feat: implement onboarding /servers and /categories endpoint

This commit is contained in:
CMK 2021-02-19 11:56:51 +08:00
parent 587d16a829
commit c919a724ab
6 changed files with 128 additions and 50 deletions

View File

@ -123,6 +123,7 @@
DB98338725C945ED00AD9700 /* Strings.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB98338525C945ED00AD9700 /* Strings.swift */; }; DB98338725C945ED00AD9700 /* Strings.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB98338525C945ED00AD9700 /* Strings.swift */; };
DB98338825C945ED00AD9700 /* Assets.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB98338625C945ED00AD9700 /* Assets.swift */; }; DB98338825C945ED00AD9700 /* Assets.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB98338625C945ED00AD9700 /* Assets.swift */; };
DB98339C25C96DE600AD9700 /* APIService+Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB98339B25C96DE600AD9700 /* APIService+Account.swift */; }; DB98339C25C96DE600AD9700 /* APIService+Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB98339B25C96DE600AD9700 /* APIService+Account.swift */; };
DBD9149025DF6D8D00903DFD /* APIService+Onboarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBD9148F25DF6D8D00903DFD /* APIService+Onboarding.swift */; };
DBE0821525CD382600FD6BBD /* MastodonRegisterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBE0821425CD382600FD6BBD /* MastodonRegisterViewController.swift */; }; DBE0821525CD382600FD6BBD /* MastodonRegisterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBE0821425CD382600FD6BBD /* MastodonRegisterViewController.swift */; };
DBE0822425CD3F1E00FD6BBD /* MastodonRegisterViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBE0822325CD3F1E00FD6BBD /* MastodonRegisterViewModel.swift */; }; DBE0822425CD3F1E00FD6BBD /* MastodonRegisterViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBE0822325CD3F1E00FD6BBD /* MastodonRegisterViewModel.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
@ -305,6 +306,7 @@
DB98338525C945ED00AD9700 /* Strings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Strings.swift; sourceTree = "<group>"; }; DB98338525C945ED00AD9700 /* Strings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Strings.swift; sourceTree = "<group>"; };
DB98338625C945ED00AD9700 /* Assets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Assets.swift; sourceTree = "<group>"; }; DB98338625C945ED00AD9700 /* Assets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Assets.swift; sourceTree = "<group>"; };
DB98339B25C96DE600AD9700 /* APIService+Account.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "APIService+Account.swift"; sourceTree = "<group>"; }; DB98339B25C96DE600AD9700 /* APIService+Account.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "APIService+Account.swift"; sourceTree = "<group>"; };
DBD9148F25DF6D8D00903DFD /* APIService+Onboarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "APIService+Onboarding.swift"; sourceTree = "<group>"; };
DBE0821425CD382600FD6BBD /* MastodonRegisterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonRegisterViewController.swift; sourceTree = "<group>"; }; DBE0821425CD382600FD6BBD /* MastodonRegisterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonRegisterViewController.swift; sourceTree = "<group>"; };
DBE0822325CD3F1E00FD6BBD /* MastodonRegisterViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonRegisterViewModel.swift; sourceTree = "<group>"; }; DBE0822325CD3F1E00FD6BBD /* MastodonRegisterViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonRegisterViewModel.swift; sourceTree = "<group>"; };
DBF53F5F25C14E88008AAC7B /* Mastodon.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; name = Mastodon.xctestplan; path = Mastodon/Mastodon.xctestplan; sourceTree = "<group>"; }; DBF53F5F25C14E88008AAC7B /* Mastodon.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; name = Mastodon.xctestplan; path = Mastodon/Mastodon.xctestplan; sourceTree = "<group>"; };
@ -677,6 +679,7 @@
DB45FB0925CA87BC005A8AC7 /* CoreData */, DB45FB0925CA87BC005A8AC7 /* CoreData */,
2D61335625C1887F00CAE157 /* Persist */, 2D61335625C1887F00CAE157 /* Persist */,
2D61335D25C1894B00CAE157 /* APIService.swift */, 2D61335D25C1894B00CAE157 /* APIService.swift */,
DBD9148F25DF6D8D00903DFD /* APIService+Onboarding.swift */,
2DF75BA625D10E1000694EC8 /* APIService+Favorite.swift */, 2DF75BA625D10E1000694EC8 /* APIService+Favorite.swift */,
DB98337E25C9452D00AD9700 /* APIService+APIError.swift */, DB98337E25C9452D00AD9700 /* APIService+APIError.swift */,
DB98336A25C9420100AD9700 /* APIService+App.swift */, DB98336A25C9420100AD9700 /* APIService+App.swift */,
@ -1227,6 +1230,7 @@
2DA7D04425CA52B200804E11 /* TimelineLoaderTableViewCell.swift in Sources */, 2DA7D04425CA52B200804E11 /* TimelineLoaderTableViewCell.swift in Sources */,
DB8AF52F25C13561002E6C99 /* DocumentStore.swift in Sources */, DB8AF52F25C13561002E6C99 /* DocumentStore.swift in Sources */,
2D38F1EB25CD477000561493 /* HomeTimelineViewModel+LoadLatestState.swift in Sources */, 2D38F1EB25CD477000561493 /* HomeTimelineViewModel+LoadLatestState.swift in Sources */,
DBD9149025DF6D8D00903DFD /* APIService+Onboarding.swift in Sources */,
DB98337F25C9452D00AD9700 /* APIService+APIError.swift in Sources */, DB98337F25C9452D00AD9700 /* APIService+APIError.swift in Sources */,
2DF123A725C3B0210020F248 /* ActiveLabel.swift in Sources */, 2DF123A725C3B0210020F248 /* ActiveLabel.swift in Sources */,
DBE0822425CD3F1E00FD6BBD /* MastodonRegisterViewModel.swift in Sources */, DBE0822425CD3F1E00FD6BBD /* MastodonRegisterViewModel.swift in Sources */,

View File

@ -0,0 +1,26 @@
//
// APIService+Onboarding.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-2-19.
//
import Foundation
import Combine
import MastodonSDK
extension APIService {
func servers(
language: String?,
category: String?
) -> AnyPublisher<Mastodon.Response.Content<[Mastodon.Entity.Server]>, Error> {
let query = Mastodon.API.Onboarding.ServersQuery(language: language, category: category)
return Mastodon.API.Onboarding.servers(session: session, query: query)
}
func categories() -> AnyPublisher<Mastodon.Response.Content<[Mastodon.Entity.Category]>, Error> {
return Mastodon.API.Onboarding.categories(session: session)
}
}

View File

@ -1,5 +1,5 @@
// //
// Mastodon+API+Server.swift // Mastodon+API+Onboarding.swift
// //
// //
// Created by MainasuK Cirno on 2021-2-18. // Created by MainasuK Cirno on 2021-2-18.
@ -8,11 +8,25 @@
import Foundation import Foundation
import Combine import Combine
extension Mastodon.API.Server { 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")
/// Fetch server list
///
/// Using this endpoint to fetch booked servers
///
/// - Since: 3.3.0
/// - Version: 3.3.0
/// # Last Update
/// 2021/2/19
/// # Reference
/// undocumented
/// - Parameters:
/// - session: `URLSession`
/// - query: `ServerQuery`
/// - Returns: `AnyPublisher` contains `Server` nested in the response
public static func servers( public static func servers(
session: URLSession, session: URLSession,
query: ServersQuery query: ServersQuery
@ -30,6 +44,19 @@ extension Mastodon.API.Server {
.eraseToAnyPublisher() .eraseToAnyPublisher()
} }
/// Fetch server catagories
///
/// Using this endpoint to fetch booked catagories
///
/// - Since: 3.3.0
/// - Version: 3.3.0
/// # Last Update
/// 2021/2/19
/// # Reference
/// undocumented
/// - Parameters:
/// - session: `URLSession`
/// - Returns: `AnyPublisher` contains `Category` nested in the response
public static func categories( public static func categories(
session: URLSession session: URLSession
) -> AnyPublisher<Mastodon.Response.Content<[Mastodon.Entity.Category]>, Error> { ) -> AnyPublisher<Mastodon.Response.Content<[Mastodon.Entity.Category]>, Error> {
@ -48,9 +75,9 @@ extension Mastodon.API.Server {
} }
extension Mastodon.API.Server { extension Mastodon.API.Onboarding {
public struct ServersQuery: Codable, GetQuery { public struct ServersQuery: GetQuery {
public let language: String? public let language: String?
public let category: String? public let category: String?

View File

@ -88,8 +88,8 @@ extension Mastodon.API {
public enum App { } public enum App { }
public enum Instance { } public enum Instance { }
public enum OAuth { } public enum OAuth { }
public enum Onboarding { }
public enum Timeline { } public enum Timeline { }
public enum Server { }
public enum Favorites { } public enum Favorites { }
} }

View File

@ -0,0 +1,66 @@
//
// MastodonSDK+API+OnboardingTests.swift
//
//
// Created by MainasuK Cirno on 2021-2-18.
//
import os.log
import XCTest
import Combine
@testable import MastodonSDK
extension MastodonSDKTests {
func testServers() throws {
try _testServers(query: Mastodon.API.Onboarding.ServersQuery(language: nil, category: nil))
try _testServers(query: Mastodon.API.Onboarding.ServersQuery(language: "en", category: "tech"))
}
func _testServers(query: Mastodon.API.Onboarding.ServersQuery) throws {
let theExpectation = expectation(description: "Fetch Server List")
Mastodon.API.Onboarding.servers(
session: session,
query: query
)
.receive(on: DispatchQueue.main)
.sink { completion in
switch completion {
case .failure(let error):
XCTFail(error.localizedDescription)
case .finished:
break
}
} receiveValue: { response in
XCTAssert(!response.value.isEmpty)
theExpectation.fulfill()
}
.store(in: &disposeBag)
wait(for: [theExpectation], timeout: 10.0)
}
func testCatagories() throws {
let theExpectation = expectation(description: "Fetch Server Catagories")
Mastodon.API.Onboarding.categories(
session: session
)
.receive(on: DispatchQueue.main)
.sink { completion in
switch completion {
case .failure(let error):
XCTFail(error.localizedDescription)
case .finished:
break
}
} receiveValue: { response in
XCTAssert(!response.value.isEmpty)
theExpectation.fulfill()
}
.store(in: &disposeBag)
wait(for: [theExpectation], timeout: 10.0)
}
}

View File

@ -1,45 +0,0 @@
//
// MastodonSDK+API+ServerTests.swift
//
//
// Created by MainasuK Cirno on 2021-2-18.
//
import os.log
import XCTest
import Combine
@testable import MastodonSDK
extension MastodonSDKTests {
func testServers() throws {
try _testServers(query: Mastodon.API.Server.ServersQuery(language: nil, category: nil))
try _testServers(query: Mastodon.API.Server.ServersQuery(language: "en", category: "tech"))
}
func _testServers(query: Mastodon.API.Server.ServersQuery) throws {
let theExpectation = expectation(description: "Fetch Server List")
Mastodon.API.Server.servers(
session: session,
query: query
)
.receive(on: DispatchQueue.main)
.sink { completion in
switch completion {
case .failure(let error):
XCTFail(error.localizedDescription)
case .finished:
break
}
} receiveValue: { response in
XCTAssert(!response.value.isEmpty)
theExpectation.fulfill()
}
.store(in: &disposeBag)
wait(for: [theExpectation], timeout: 10.0)
}
}