metatext/MastodonAPI/Sources/MastodonAPI/Endpoints/DeletionEndpoint.swift

54 lines
1.3 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-08-30 23:33:11 +00:00
public enum DeletionEndpoint {
case oauthRevoke(token: String, clientID: String, clientSecret: String)
2020-08-29 03:50:58 +00:00
case list(id: String)
2020-08-29 10:26:26 +00:00
case filter(id: String)
}
2020-08-30 23:59:49 +00:00
extension DeletionEndpoint: 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"]
case .list:
return defaultContext + ["lists"]
2020-08-29 10:26:26 +00:00
case .filter:
return defaultContext + ["filters"]
}
}
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"]
2020-08-29 10:26:26 +00:00
case let .list(id), let .filter(id):
2020-08-29 03:50:58 +00:00
return [id]
}
}
2020-08-30 23:33:11 +00:00
public var method: HTTPMethod {
switch self {
case .oauthRevoke:
return .post
2020-08-29 10:26:26 +00:00
case .list, .filter:
2020-08-29 03:50:58 +00:00
return .delete
}
}
2020-08-30 23:33:11 +00:00
public var parameters: [String: Any]? {
switch self {
case let .oauthRevoke(token, clientID, clientSecret):
return ["token": token, "client_id": clientID, "client_secret": clientSecret]
2020-08-29 10:26:26 +00:00
case .list, .filter:
2020-08-29 03:50:58 +00:00
return nil
}
}
}