metatext-app-ios-iphone-ipad/MastodonAPI/Sources/MastodonAPI/Endpoints/AccountsEndpoint.swift

66 lines
1.7 KiB
Swift
Raw Normal View History

2020-09-25 07:39:06 +02:00
// Copyright © 2020 Metabolist. All rights reserved.
import Foundation
import HTTP
import Mastodon
public enum AccountsEndpoint {
2020-10-06 00:50:05 +02:00
case rebloggedBy(id: Status.Id)
case favouritedBy(id: Status.Id)
2020-12-02 00:23:47 +01:00
case mutes
case blocks
2020-12-03 02:06:46 +01:00
case accountsFollowers(id: Account.Id)
case accountsFollowing(id: Account.Id)
2021-01-26 07:57:44 +01:00
case followRequests
case directory(local: Bool)
2020-09-25 07:39:06 +02:00
}
extension AccountsEndpoint: Endpoint {
public typealias ResultType = [Account]
public var context: [String] {
switch self {
2020-10-06 00:50:05 +02:00
case .rebloggedBy, .favouritedBy:
2020-09-25 07:39:06 +02:00
return defaultContext + ["statuses"]
case .mutes, .blocks, .followRequests, .directory:
2020-12-02 00:23:47 +01:00
return defaultContext
2020-12-03 02:06:46 +01:00
case .accountsFollowers, .accountsFollowing:
return defaultContext + ["accounts"]
2020-09-25 07:39:06 +02:00
}
}
public var pathComponentsInContext: [String] {
switch self {
2020-10-06 00:50:05 +02:00
case let .rebloggedBy(id):
2020-09-29 01:23:41 +02:00
return [id, "reblogged_by"]
2020-10-06 00:50:05 +02:00
case let .favouritedBy(id):
2020-09-25 07:39:06 +02:00
return [id, "favourited_by"]
2020-12-02 00:23:47 +01:00
case .mutes:
return ["mutes"]
case .blocks:
return ["blocks"]
2020-12-03 02:06:46 +01:00
case let .accountsFollowers(id):
return [id, "followers"]
case let .accountsFollowing(id):
return [id, "following"]
2021-01-26 07:57:44 +01:00
case .followRequests:
return ["follow_requests"]
case .directory:
return ["directory"]
}
}
public var queryParameters: [URLQueryItem] {
switch self {
case let .directory(local):
return [.init(name: "local", value: String(local))]
default:
return []
2020-09-25 07:39:06 +02:00
}
}
public var method: HTTPMethod {
2020-12-02 00:23:47 +01:00
.get
2020-09-25 07:39:06 +02:00
}
}