-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from technicat/main
added getProfileDirectory, getScheduledPosts
- Loading branch information
Showing
5 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
Sources/TootSDK/TootClient/TootClient+ProfileDirectory.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters