2023-02-03 15:16:30 +01:00
|
|
|
//
|
|
|
|
// https://mczachurski.dev
|
|
|
|
// Copyright © 2023 Marcin Czachurski and the repository contributors.
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
//
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-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
|
|
|
}
|
|
|
|
}
|