Download default servers (IOS-171)
This commit is contained in:
parent
bd1339e9f2
commit
18895a373b
|
@ -13,6 +13,7 @@ extension Mastodon.API.Onboarding {
|
||||||
static let serversEndpointURL = Mastodon.API.joinMastodonEndpointURL.appendingPathComponent("servers")
|
static let serversEndpointURL = Mastodon.API.joinMastodonEndpointURL.appendingPathComponent("servers")
|
||||||
static let categoriesEndpointURL = Mastodon.API.joinMastodonEndpointURL.appendingPathComponent("categories")
|
static let categoriesEndpointURL = Mastodon.API.joinMastodonEndpointURL.appendingPathComponent("categories")
|
||||||
static let languagesEndpointURL = Mastodon.API.joinMastodonEndpointURL.appendingPathComponent("languages")
|
static let languagesEndpointURL = Mastodon.API.joinMastodonEndpointURL.appendingPathComponent("languages")
|
||||||
|
static let defaultServersEndpointURL = Mastodon.API.joinMastodonEndpointURL.appendingPathComponent("default-servers")
|
||||||
|
|
||||||
/// Fetch server list
|
/// Fetch server list
|
||||||
///
|
///
|
||||||
|
@ -96,6 +97,30 @@ extension Mastodon.API.Onboarding {
|
||||||
}
|
}
|
||||||
.eraseToAnyPublisher()
|
.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 {
|
extension Mastodon.API.Onboarding {
|
||||||
|
|
|
@ -134,7 +134,7 @@ extension Mastodon.API {
|
||||||
static func get(
|
static func get(
|
||||||
url: URL,
|
url: URL,
|
||||||
query: GetQuery? = nil,
|
query: GetQuery? = nil,
|
||||||
authorization: OAuth.Authorization?
|
authorization: OAuth.Authorization? = nil
|
||||||
) -> URLRequest {
|
) -> URLRequest {
|
||||||
return buildRequest(url: url, method: .GET, query: query, authorization: authorization)
|
return buildRequest(url: url, method: .GET, query: query, authorization: authorization)
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ extension Mastodon.API {
|
||||||
static func post(
|
static func post(
|
||||||
url: URL,
|
url: URL,
|
||||||
query: PostQuery?,
|
query: PostQuery?,
|
||||||
authorization: OAuth.Authorization?
|
authorization: OAuth.Authorization? = nil
|
||||||
) -> URLRequest {
|
) -> URLRequest {
|
||||||
return buildRequest(url: url, method: .POST, query: query, authorization: authorization)
|
return buildRequest(url: url, method: .POST, query: query, authorization: authorization)
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ extension Mastodon.API {
|
||||||
static func patch(
|
static func patch(
|
||||||
url: URL,
|
url: URL,
|
||||||
query: PatchQuery?,
|
query: PatchQuery?,
|
||||||
authorization: OAuth.Authorization?
|
authorization: OAuth.Authorization? = nil
|
||||||
) -> URLRequest {
|
) -> URLRequest {
|
||||||
return buildRequest(url: url, method: .PATCH, query: query, authorization: authorization)
|
return buildRequest(url: url, method: .PATCH, query: query, authorization: authorization)
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ extension Mastodon.API {
|
||||||
static func put(
|
static func put(
|
||||||
url: URL,
|
url: URL,
|
||||||
query: PutQuery? = nil,
|
query: PutQuery? = nil,
|
||||||
authorization: OAuth.Authorization?
|
authorization: OAuth.Authorization? = nil
|
||||||
) -> URLRequest {
|
) -> URLRequest {
|
||||||
return buildRequest(url: url, method: .PUT, query: query, authorization: authorization)
|
return buildRequest(url: url, method: .PUT, query: query, authorization: authorization)
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,7 @@ extension Mastodon.API {
|
||||||
static func delete(
|
static func delete(
|
||||||
url: URL,
|
url: URL,
|
||||||
query: DeleteQuery?,
|
query: DeleteQuery?,
|
||||||
authorization: OAuth.Authorization?
|
authorization: OAuth.Authorization? = nil
|
||||||
) -> URLRequest {
|
) -> URLRequest {
|
||||||
return buildRequest(url: url, method: .DELETE, query: query, authorization: authorization)
|
return buildRequest(url: url, method: .DELETE, query: query, authorization: authorization)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue