Download default servers (IOS-171)

This commit is contained in:
Nathan Mattes 2023-07-02 12:39:27 +02:00
parent bd1339e9f2
commit 18895a373b
3 changed files with 40 additions and 5 deletions

View File

@ -13,6 +13,7 @@ extension Mastodon.API.Onboarding {
static let serversEndpointURL = Mastodon.API.joinMastodonEndpointURL.appendingPathComponent("servers")
static let categoriesEndpointURL = Mastodon.API.joinMastodonEndpointURL.appendingPathComponent("categories")
static let languagesEndpointURL = Mastodon.API.joinMastodonEndpointURL.appendingPathComponent("languages")
static let defaultServersEndpointURL = Mastodon.API.joinMastodonEndpointURL.appendingPathComponent("default-servers")
/// Fetch server list
///
@ -96,6 +97,30 @@ extension Mastodon.API.Onboarding {
}
.eraseToAnyPublisher()
}
/// Fetch default servers
///
/// Using this endpoint to fetch default servers
///
/// # Last Update
/// 2023/07/02
/// # Reference
/// undocumented
/// - Parameters:
/// - session: `URLSession`
/// - Returns: `AnyPublisher` contains `Language` nested in the response
public static func defaultServers(
session: URLSession
) -> AnyPublisher<Mastodon.Response.Content<[Mastodon.Entity.DefaultServer]>, Error> {
let request = Mastodon.API.get(url: defaultServersEndpointURL)
return session.dataTaskPublisher(for: request)
.tryMap { data, response in
let value = try Mastodon.API.decode(type: [Mastodon.Entity.DefaultServer].self, from: data, response: response)
return Mastodon.Response.Content(value: value, response: response)
}
.eraseToAnyPublisher()
}
}
extension Mastodon.API.Onboarding {

View File

@ -134,7 +134,7 @@ extension Mastodon.API {
static func get(
url: URL,
query: GetQuery? = nil,
authorization: OAuth.Authorization?
authorization: OAuth.Authorization? = nil
) -> URLRequest {
return buildRequest(url: url, method: .GET, query: query, authorization: authorization)
}
@ -142,7 +142,7 @@ extension Mastodon.API {
static func post(
url: URL,
query: PostQuery?,
authorization: OAuth.Authorization?
authorization: OAuth.Authorization? = nil
) -> URLRequest {
return buildRequest(url: url, method: .POST, query: query, authorization: authorization)
}
@ -150,7 +150,7 @@ extension Mastodon.API {
static func patch(
url: URL,
query: PatchQuery?,
authorization: OAuth.Authorization?
authorization: OAuth.Authorization? = nil
) -> URLRequest {
return buildRequest(url: url, method: .PATCH, query: query, authorization: authorization)
}
@ -158,7 +158,7 @@ extension Mastodon.API {
static func put(
url: URL,
query: PutQuery? = nil,
authorization: OAuth.Authorization?
authorization: OAuth.Authorization? = nil
) -> URLRequest {
return buildRequest(url: url, method: .PUT, query: query, authorization: authorization)
}
@ -166,7 +166,7 @@ extension Mastodon.API {
static func delete(
url: URL,
query: DeleteQuery?,
authorization: OAuth.Authorization?
authorization: OAuth.Authorization? = nil
) -> URLRequest {
return buildRequest(url: url, method: .DELETE, query: query, authorization: authorization)
}

View File

@ -0,0 +1,10 @@
// Copyright © 2023 Mastodon gGmbH. All rights reserved.
import Foundation
extension Mastodon.Entity {
public struct DefaultServer: Codable {
let domain: String
let weight: Int
}
}