2
2
mirror of https://github.com/mastodon/mastodon-ios synced 2025-04-11 22:58:02 +02:00

Add the new min_age key to V2 Instance

This commit is contained in:
shannon 2025-03-26 08:18:16 -04:00
parent a0c6b2c1ea
commit f7b72faf56
3 changed files with 40 additions and 1 deletions

View File

@ -33,6 +33,12 @@ extension APIService {
) -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.V2.Instance>, Error> {
return Mastodon.API.V2.Instance.instance(session: session, authorization: authenticationBox?.userAuthorization, domain: domain)
}
public func instanceV2(
domain: String,
authenticationBox: MastodonAuthenticationBox?
) async throws -> Mastodon.Entity.V2.Instance {
return try await Mastodon.API.V2.Instance.instance(session: session, authorization: authenticationBox?.userAuthorization, domain: domain)
}
public func extendedDescription(
domain: String,

View File

@ -48,4 +48,31 @@ extension Mastodon.API.V2.Instance {
.eraseToAnyPublisher()
}
public static func instance(
session: URLSession,
authorization: Mastodon.API.OAuth.Authorization?,
domain: String
) async throws -> Mastodon.Entity.V2.Instance {
let request = Mastodon.API.get(
url: instanceEndpointURL(domain: domain),
query: nil,
authorization: authorization
)
let (data, response) = try await session.data(for: request)
let value: Mastodon.Entity.V2.Instance
do {
value = try Mastodon.API.decode(type: Mastodon.Entity.V2.Instance.self, from: data, response: response)
} catch {
if let response = response as? HTTPURLResponse, 400 ..< 500 ~= response.statusCode {
// For example, AUTHORIZED_FETCH may result in authentication errors
value = Mastodon.Entity.V2.Instance(domain: domain)
} else {
throw error
}
}
return value
}
}

View File

@ -6,7 +6,7 @@ extension Mastodon.Entity.V2 {
/// - Since: 4.0.0
/// - Version: 4.0.3
/// # Last Update
/// 2022/12/09
/// 2025/03/24
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/instance/)
public struct Instance: Codable {
@ -92,6 +92,12 @@ extension Mastodon.Entity.V2.Instance {
extension Mastodon.Entity.V2.Instance {
public struct Registrations: Codable {
public let enabled: Bool
public let minAge: Int?
enum CodingKeys: String, CodingKey {
case enabled
case minAge = "min_age"
}
}
}