Impressia/Vernissage/EnvironmentObjects/Client.swift

55 lines
2.0 KiB
Swift
Raw Normal View History

2023-02-03 15:16:30 +01:00
//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
2023-03-28 10:35:38 +02:00
// Licensed under the Apache License 2.0.
2023-02-03 15:16:30 +01:00
//
import Foundation
2023-02-19 10:32:38 +01:00
import PixelfedKit
2023-02-03 15:16:30 +01:00
public class Client: ObservableObject {
public static let shared = Client()
private init() { }
2023-02-19 10:43:37 +01:00
private var pixelfedClient: PixelfedClientAuthenticated?
2023-02-03 15:16:30 +01:00
func setAccount(account: AccountModel) {
guard let accessToken = account.accessToken else {
return
}
2023-02-19 10:43:37 +01:00
self.pixelfedClient = PixelfedClient(baseURL: account.serverUrl).getAuthenticated(token: accessToken)
2023-02-03 15:16:30 +01:00
}
2023-02-23 08:09:02 +01:00
func clearAccount() {
self.pixelfedClient = nil
}
2023-02-03 15:16:30 +01:00
}
extension Client {
2023-02-19 10:43:37 +01:00
public var trends: Trends? { return Trends(pixelfedClient: self.pixelfedClient) }
public var publicTimeline: PublicTimeline? { return PublicTimeline(pixelfedClient: self.pixelfedClient) }
public var tags: Tags? { return Tags(pixelfedClient: self.pixelfedClient) }
public var notifications: Notifications? { return Notifications(pixelfedClient: self.pixelfedClient) }
public var statuses: Statuses? { return Statuses(pixelfedClient: self.pixelfedClient) }
public var media: Media? { return Media(pixelfedClient: self.pixelfedClient) }
public var accounts: Accounts? { return Accounts(pixelfedClient: self.pixelfedClient) }
public var search: Search? { return Search(pixelfedClient: self.pixelfedClient) }
public var places: Places? { return Places(pixelfedClient: self.pixelfedClient) }
2023-03-27 14:52:53 +02:00
public var blocks: Blocks? { return Blocks(pixelfedClient: self.pixelfedClient) }
public var mutes: Mutes? { return Mutes(pixelfedClient: self.pixelfedClient) }
2023-02-03 15:16:30 +01:00
public var instances: Instances { return Instances() }
}
public class BaseClient {
2023-02-19 10:43:37 +01:00
public var pixelfedClient: PixelfedClientAuthenticated
2023-02-03 15:16:30 +01:00
2023-02-19 10:43:37 +01:00
init?(pixelfedClient: PixelfedClientAuthenticated?) {
guard let pixelfedClient else {
2023-02-03 15:16:30 +01:00
return nil
}
2023-02-19 10:43:37 +01:00
self.pixelfedClient = pixelfedClient
2023-02-03 15:16:30 +01:00
}
}