feat: add rules attribute for Instance entity

This commit is contained in:
CMK 2021-02-22 12:26:44 +08:00
parent 6285cb95fa
commit 8a48eb5847
3 changed files with 66 additions and 3 deletions

View File

@ -47,6 +47,18 @@
}
]
}
},
{
"id" : "C229D9A6-6A83-4AF9-8A71-ADD1AD2AD9D8",
"name" : "mastodon.online",
"options" : {
"environmentVariableEntries" : [
{
"key" : "domain",
"value" : "mastodon.online"
}
]
}
}
],
"defaultOptions" : {
@ -54,8 +66,18 @@
},
"testTargets" : [
{
"skippedTests" : [
"MastodonSDKTests\/testCreateAnAnpplication()",
"MastodonSDKTests\/testHomeTimeline()",
"MastodonSDKTests\/testOAuthAuthorize()",
"MastodonSDKTests\/testRetrieveAccountInfo()",
"MastodonSDKTests\/testRevokeToken()",
"MastodonSDKTests\/testUpdateCredentials()",
"MastodonSDKTests\/testVerifyAppCredentials()",
"MastodonSDKTests\/testVerifyCredentials()"
],
"target" : {
"containerPath" : "container:",
"containerPath" : "container:MastodonSDK",
"identifier" : "MastodonSDKTests",
"name" : "MastodonSDKTests"
}

View File

@ -13,7 +13,7 @@ extension Mastodon.Entity {
/// - Since: 1.1.0
/// - Version: 3.3.0
/// # Last Update
/// 2021/2/5
/// 2021/2/22
/// # Reference
/// [Document](https://docs.joinmastodon.org/entities/instance/)
public struct Instance: Codable {
@ -33,6 +33,7 @@ extension Mastodon.Entity {
public let thumbnail: String?
public let contactAccount: Account?
public let rules: [Rule]?
enum CodingKeys: String, CodingKey {
case uri
@ -48,8 +49,9 @@ extension Mastodon.Entity {
case urls
case statistics
case thumbnail = "thumbnail"
case thumbnail
case contactAccount = "contact_account"
case rules
}
}
}
@ -77,3 +79,10 @@ extension Mastodon.Entity.Instance {
}
}
}
extension Mastodon.Entity.Instance {
public struct Rule: Codable {
public let id: String
public let text: String
}
}

View File

@ -37,5 +37,37 @@ extension MastodonSDKTests {
wait(for: [theExpectation], timeout: 10.0)
}
func testInstanceRules() throws {
switch domain {
case "mastodon.online": break
default: return
}
try _testInstanceRules(domain: domain)
}
func _testInstanceRules(domain: String) throws {
let theExpectation = expectation(description: "Fetch Instance Infomation")
Mastodon.API.Instance.instance(session: session, domain: domain)
.receive(on: DispatchQueue.main)
.sink { completion in
switch completion {
case .failure(let error):
XCTFail(error.localizedDescription)
case .finished:
break
}
} receiveValue: { response in
XCTAssertNotEqual(response.value.uri, "")
XCTAssert(!(response.value.rules ?? []).isEmpty)
print(response.value.rules?.sorted(by: { $0.id < $1.id }) ?? "")
theExpectation.fulfill()
}
.store(in: &disposeBag)
wait(for: [theExpectation], timeout: 10.0)
}
}