diff --git a/Package.resolved b/Package.resolved index 91041ddf..53290d83 100644 --- a/Package.resolved +++ b/Package.resolved @@ -23,8 +23,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio.git", "state" : { - "revision" : "2d8e6ca36fe3e8ed74b0883f593757a45463c34d", - "version" : "2.53.0" + "revision" : "6213ba7a06febe8fef60563a4a7d26a4085783cf", + "version" : "2.54.0" } }, { diff --git a/Sources/TootSDK/Models/ProfileDirectoryParams.swift b/Sources/TootSDK/Models/ProfileDirectoryParams.swift new file mode 100644 index 00000000..ddadb0ec --- /dev/null +++ b/Sources/TootSDK/Models/ProfileDirectoryParams.swift @@ -0,0 +1,36 @@ +// +// ProfileDirectoryParams.swift +// +// +// Created by Philip Chu on 5/29/23. +// + +import Foundation + +public struct ProfileDirectoryParams: Codable { + + /// Use active to sort by most recently posted statuses (default) or new to sort by most recently created profiles. + public var order: Order? + /// If true, returns only local accounts. + public var local: Bool? + + public init(order: Order? = nil, + local: Bool? = nil) { + self.order = order + self.local = local + } + + public enum Order: String, Codable, Hashable, CaseIterable { + case active + case new + } +} + +extension ProfileDirectoryParams { + var queryItems: [URLQueryItem] { + [ + URLQueryItem(name: "order", value: order?.rawValue), + URLQueryItem(name: "local", value: local?.description) + ].filter { $0.value != nil } + } +} diff --git a/Sources/TootSDK/TootClient/TootClient+Notifications.swift b/Sources/TootSDK/TootClient/TootClient+Notifications.swift index ffcaa99b..16d1914f 100644 --- a/Sources/TootSDK/TootClient/TootClient+Notifications.swift +++ b/Sources/TootSDK/TootClient/TootClient+Notifications.swift @@ -10,6 +10,8 @@ import Foundation public extension TootClient { /// Get all notifications concerning the user + /// - Parameters: + /// - limit: Maximum number of results to return. Defaults to 15 notifications. Max 30 notifications. func getNotifications(params: TootNotificationParams = .init(), _ pageInfo: PagedInfo? = nil, limit: Int? = nil) async throws -> PagedResult<[TootNotification]> { let req = HTTPRequestBuilder { $0.url = getURL(["api", "v1", "notifications"]) diff --git a/Sources/TootSDK/TootClient/TootClient+ProfileDirectory.swift b/Sources/TootSDK/TootClient/TootClient+ProfileDirectory.swift new file mode 100644 index 00000000..a3ccf463 --- /dev/null +++ b/Sources/TootSDK/TootClient/TootClient+ProfileDirectory.swift @@ -0,0 +1,28 @@ +// +// TootClient+Directory.swift +// +// +// Created by Philip Chu on 5/29/23. +// + +import Foundation + +public extension TootClient { + + /// List accounts visible in the directory. + /// + /// - Parameters: + /// - offset. Skip the first n results. + /// - limit: How many accounts to load. Defaults to 40 accounts. Max 80 accounts. + /// - params: Includes order and local parameters. + /// - Returns: Array of ``Account``. + func getProfileDirectory(params: ProfileDirectoryParams, offset: Int? = nil, limit: Int? = nil) async throws -> [Account] { + let req = HTTPRequestBuilder { + $0.url = getURL(["api", "v1", "directory"]) + $0.method = .get + $0.query = getQueryParams(limit: limit, offset: offset) + params.queryItems + } + + return try await fetch([Account].self, req) + } +} diff --git a/Sources/TootSDK/TootClient/TootClient+ScheduledPost.swift b/Sources/TootSDK/TootClient/TootClient+ScheduledPost.swift index 4251edff..46989c35 100644 --- a/Sources/TootSDK/TootClient/TootClient+ScheduledPost.swift +++ b/Sources/TootSDK/TootClient/TootClient+ScheduledPost.swift @@ -51,6 +51,18 @@ public extension TootClient { return try await fetch([ScheduledPost].self, req) } + + /// Gets scheduled posts + /// - Returns: the scheduled posts requested, or an error if unable to retrieve + func getScheduledPosts(_ pageInfo: PagedInfo? = nil, limit: Int? = nil) async throws -> PagedResult<[ScheduledPost]> { + let req = HTTPRequestBuilder { + $0.url = getURL(["api", "v1", "scheduled_statuses"]) + $0.method = .get + $0.query = getQueryParams(pageInfo, limit: limit) + } + + return try await fetchPagedResult(req) + } /// Gets a single Scheduled post by id ///