Download languages (#690)
This commit is contained in:
parent
a107b4d9e2
commit
5e4820739f
|
@ -28,5 +28,8 @@ extension APIService {
|
|||
return Mastodon.Entity.Category(category: kind.rawValue, serversCount: 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func languages() -> AnyPublisher<Mastodon.Response.Content<[Mastodon.Entity.Language]>, Error> {
|
||||
return Mastodon.API.Onboarding.languages(session: session)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,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")
|
||||
|
||||
/// Fetch server list
|
||||
///
|
||||
|
@ -68,7 +69,33 @@ extension Mastodon.API.Onboarding {
|
|||
}
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
|
||||
/// Fetch server languages
|
||||
///
|
||||
/// Using this endpoint to fetch booked languages
|
||||
///
|
||||
/// # Last Update
|
||||
/// 2022/12/19
|
||||
/// # Reference
|
||||
/// undocumented
|
||||
/// - Parameters:
|
||||
/// - session: `URLSession`
|
||||
/// - Returns: `AnyPublisher` contains `Language` nested in the response
|
||||
public static func languages(
|
||||
session: URLSession
|
||||
) -> AnyPublisher<Mastodon.Response.Content<[Mastodon.Entity.Language]>, Error> {
|
||||
let request = Mastodon.API.get(
|
||||
url: languagesEndpointURL,
|
||||
query: nil,
|
||||
authorization: nil
|
||||
)
|
||||
return session.dataTaskPublisher(for: request)
|
||||
.tryMap { data, response in
|
||||
let value = try Mastodon.API.decode(type: [Mastodon.Entity.Language].self, from: data, response: response)
|
||||
return Mastodon.Response.Content(value: value, response: response)
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
}
|
||||
|
||||
extension Mastodon.API.Onboarding {
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
//
|
||||
// File.swift
|
||||
//
|
||||
//
|
||||
// Created by Nathan Mattes on 19.12.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Mastodon.Entity {
|
||||
|
||||
public struct Language: Codable {
|
||||
public let locale: String
|
||||
public let serversCount: Int
|
||||
public let language: String?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case locale
|
||||
case serversCount = "servers_count"
|
||||
case language
|
||||
}
|
||||
|
||||
public init(locale: String, serversCount: Int, language: String?) {
|
||||
self.locale = locale
|
||||
self.serversCount = serversCount
|
||||
self.language = language
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue