Skip to content

Commit

Permalink
Merge pull request #169 from technicat/main
Browse files Browse the repository at this point in the history
added getProfileDirectory, getScheduledPosts
  • Loading branch information
kkostov committed Jun 9, 2023
2 parents 9f8ceef + 142fc94 commit 1b4ce1d
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down
36 changes: 36 additions & 0 deletions Sources/TootSDK/Models/ProfileDirectoryParams.swift
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 }
}
}
2 changes: 2 additions & 0 deletions Sources/TootSDK/TootClient/TootClient+Notifications.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
28 changes: 28 additions & 0 deletions Sources/TootSDK/TootClient/TootClient+ProfileDirectory.swift
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)
}
}
12 changes: 12 additions & 0 deletions Sources/TootSDK/TootClient/TootClient+ScheduledPost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down

0 comments on commit 1b4ce1d

Please sign in to comment.