mirror of
https://github.com/mastodon/mastodon-ios.git
synced 2024-12-19 04:04:47 +01:00
feat: add stub categories
This commit is contained in:
parent
c919a724ab
commit
9e0a7bb352
@ -23,4 +23,10 @@ extension APIService {
|
|||||||
return Mastodon.API.Onboarding.categories(session: session)
|
return Mastodon.API.Onboarding.categories(session: session)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stubCategories() -> [Mastodon.Entity.Category] {
|
||||||
|
return Mastodon.Entity.Category.Kind.allCases.map { kind in
|
||||||
|
return Mastodon.Entity.Category(category: kind.rawValue, serversCount: 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,9 +44,9 @@ extension Mastodon.API.Onboarding {
|
|||||||
.eraseToAnyPublisher()
|
.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch server catagories
|
/// Fetch server categories
|
||||||
///
|
///
|
||||||
/// Using this endpoint to fetch booked catagories
|
/// Using this endpoint to fetch booked categories
|
||||||
///
|
///
|
||||||
/// - Since: 3.3.0
|
/// - Since: 3.3.0
|
||||||
/// - Version: 3.3.0
|
/// - Version: 3.3.0
|
||||||
|
@ -10,13 +10,94 @@ import Foundation
|
|||||||
extension Mastodon.Entity {
|
extension Mastodon.Entity {
|
||||||
|
|
||||||
public struct Category: Codable {
|
public struct Category: Codable {
|
||||||
public let category: String
|
public let category: Kind
|
||||||
public let serversCount: Int
|
public let serversCount: Int
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
enum CodingKeys: String, CodingKey {
|
||||||
case category
|
case category
|
||||||
case serversCount = "servers_count"
|
case serversCount = "servers_count"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public init(category: String, serversCount: Int) {
|
||||||
|
self.category = Kind(rawValue: category) ?? ._other(category)
|
||||||
|
self.serversCount = serversCount
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # Reference
|
||||||
|
/// https://joinmastodon.org/communities
|
||||||
|
public enum Kind: RawRepresentable, Codable {
|
||||||
|
|
||||||
|
case general
|
||||||
|
case regional
|
||||||
|
case art
|
||||||
|
case music
|
||||||
|
case journalism
|
||||||
|
case activism
|
||||||
|
case lgbt
|
||||||
|
case games
|
||||||
|
case tech
|
||||||
|
case academia
|
||||||
|
case furry
|
||||||
|
case food
|
||||||
|
|
||||||
|
case _other(String)
|
||||||
|
|
||||||
|
public init?(rawValue: String) {
|
||||||
|
switch rawValue {
|
||||||
|
case "general": self = .general
|
||||||
|
case "regional": self = .regional
|
||||||
|
case "art": self = .art
|
||||||
|
case "music": self = .music
|
||||||
|
case "journalism": self = .journalism
|
||||||
|
case "activism": self = .activism
|
||||||
|
case "lgbt": self = .lgbt
|
||||||
|
case "games": self = .games
|
||||||
|
case "tech": self = .tech
|
||||||
|
case "academia": self = .academia
|
||||||
|
case "furry": self = .furry
|
||||||
|
case "food": self = .food
|
||||||
|
default: self = ._other(rawValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public var rawValue: String {
|
||||||
|
switch self {
|
||||||
|
case .general: return "general"
|
||||||
|
case .regional: return "regional"
|
||||||
|
case .art: return "art"
|
||||||
|
case .music: return "music"
|
||||||
|
case .journalism: return "journalism"
|
||||||
|
case .activism: return "activism"
|
||||||
|
case .lgbt: return "lgbt"
|
||||||
|
case .games: return "games"
|
||||||
|
case .tech: return "tech"
|
||||||
|
case .academia: return "academia"
|
||||||
|
case .furry: return "furry"
|
||||||
|
case .food: return "food"
|
||||||
|
case ._other(let value): return value
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Mastodon.Entity.Category.Kind: CaseIterable {
|
||||||
|
public static var allCases: [Mastodon.Entity.Category.Kind] {
|
||||||
|
return [
|
||||||
|
.general,
|
||||||
|
.regional,
|
||||||
|
.art,
|
||||||
|
.music,
|
||||||
|
.journalism,
|
||||||
|
.activism,
|
||||||
|
.lgbt,
|
||||||
|
.games,
|
||||||
|
.tech,
|
||||||
|
.academia,
|
||||||
|
.furry,
|
||||||
|
.food,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -40,8 +40,8 @@ extension MastodonSDKTests {
|
|||||||
wait(for: [theExpectation], timeout: 10.0)
|
wait(for: [theExpectation], timeout: 10.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCatagories() throws {
|
func testCategories() throws {
|
||||||
let theExpectation = expectation(description: "Fetch Server Catagories")
|
let theExpectation = expectation(description: "Fetch Server Categories")
|
||||||
Mastodon.API.Onboarding.categories(
|
Mastodon.API.Onboarding.categories(
|
||||||
session: session
|
session: session
|
||||||
)
|
)
|
||||||
@ -62,5 +62,9 @@ extension MastodonSDKTests {
|
|||||||
wait(for: [theExpectation], timeout: 10.0)
|
wait(for: [theExpectation], timeout: 10.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCategoryKind() {
|
||||||
|
XCTAssertEqual(Mastodon.Entity.Category.Kind.allCases.count, 12)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user