metatext/MastodonAPI/Sources/MastodonAPI/Endpoints/EmptyEndpoint.swift

68 lines
2.2 KiB
Swift
Raw Normal View History

// Copyright © 2020 Metabolist. All rights reserved.
import Foundation
2020-08-31 01:40:58 +00:00
import HTTP
import Mastodon
2020-12-03 05:18:47 +00:00
public enum EmptyEndpoint {
2020-10-05 22:50:05 +00:00
case oauthRevoke(token: String, clientId: String, clientSecret: String)
2021-03-03 00:50:22 +00:00
case addAccountsToList(id: List.Id, accountIds: Set<Account.Id>)
case removeAccountsFromList(id: List.Id, accountIds: Set<Account.Id>)
2020-12-03 05:18:47 +00:00
case deleteList(id: List.Id)
case deleteFilter(id: Filter.Id)
2020-12-04 03:13:18 +00:00
case blockDomain(String)
case unblockDomain(String)
}
2020-12-03 05:18:47 +00:00
extension EmptyEndpoint: Endpoint {
2020-08-30 23:33:11 +00:00
public typealias ResultType = [String: String]
2020-08-30 23:33:11 +00:00
public var context: [String] {
switch self {
case .oauthRevoke:
2020-08-29 03:50:58 +00:00
return ["oauth"]
2021-03-03 00:50:22 +00:00
case .addAccountsToList, .removeAccountsFromList, .deleteList:
2020-08-29 03:50:58 +00:00
return defaultContext + ["lists"]
2020-12-03 05:18:47 +00:00
case .deleteFilter:
2020-08-29 10:26:26 +00:00
return defaultContext + ["filters"]
2020-12-04 03:13:18 +00:00
case .blockDomain, .unblockDomain:
return defaultContext + ["domain_blocks"]
}
}
2020-08-30 23:33:11 +00:00
public var pathComponentsInContext: [String] {
switch self {
case .oauthRevoke:
2020-08-29 03:50:58 +00:00
return ["revoke"]
2021-03-03 00:50:22 +00:00
case let .addAccountsToList(id, _), let .removeAccountsFromList(id, _):
return [id, "accounts"]
2020-12-03 05:18:47 +00:00
case let .deleteList(id), let .deleteFilter(id):
2020-08-29 03:50:58 +00:00
return [id]
2020-12-04 03:13:18 +00:00
case .blockDomain, .unblockDomain:
return []
}
}
2020-08-30 23:33:11 +00:00
public var method: HTTPMethod {
switch self {
2021-03-03 00:50:22 +00:00
case .addAccountsToList, .oauthRevoke, .blockDomain:
return .post
2021-03-03 00:50:22 +00:00
case .removeAccountsFromList, .deleteList, .deleteFilter, .unblockDomain:
2020-08-29 03:50:58 +00:00
return .delete
}
}
2020-09-23 07:04:37 +00:00
public var jsonBody: [String: Any]? {
switch self {
2020-10-05 22:50:05 +00:00
case let .oauthRevoke(token, clientId, clientSecret):
return ["token": token, "client_id": clientId, "client_secret": clientSecret]
2021-03-03 00:50:22 +00:00
case let .addAccountsToList(_, accountIds), let .removeAccountsFromList(_, accountIds):
return ["account_ids": Array(accountIds)]
2020-12-04 03:13:18 +00:00
case let .blockDomain(domain), let .unblockDomain(domain):
return ["domain": domain]
2020-12-03 05:18:47 +00:00
case .deleteList, .deleteFilter:
2020-08-29 03:50:58 +00:00
return nil
}
}
}