2022-11-29 11:18:06 +00:00
|
|
|
import Foundation
|
2023-01-10 07:24:05 +00:00
|
|
|
import Models
|
2022-11-29 11:18:06 +00:00
|
|
|
|
2022-12-01 08:05:26 +00:00
|
|
|
public enum Accounts: Endpoint {
|
2022-11-29 11:18:06 +00:00
|
|
|
case accounts(id: String)
|
2023-12-08 07:04:35 +00:00
|
|
|
case lookup(name: String)
|
2023-01-24 05:35:43 +00:00
|
|
|
case favorites(sinceId: String?)
|
2023-01-09 18:26:56 +00:00
|
|
|
case bookmarks(sinceId: String?)
|
2022-12-21 08:42:05 +00:00
|
|
|
case followedTags
|
2022-12-21 19:26:38 +00:00
|
|
|
case featuredTags(id: String)
|
2022-12-01 08:05:26 +00:00
|
|
|
case verifyCredentials
|
2024-01-02 20:16:27 +00:00
|
|
|
case updateCredentialsMedia
|
2023-02-24 06:55:24 +00:00
|
|
|
case updateCredentials(json: UpdateCredentialsData)
|
2023-01-03 17:22:08 +00:00
|
|
|
case statuses(id: String,
|
|
|
|
sinceId: String?,
|
|
|
|
tag: String?,
|
|
|
|
onlyMedia: Bool?,
|
|
|
|
excludeReplies: Bool?,
|
|
|
|
pinned: Bool?)
|
2022-12-23 14:28:22 +00:00
|
|
|
case relationships(ids: [String])
|
2023-01-23 17:50:59 +00:00
|
|
|
case follow(id: String, notify: Bool, reblogs: Bool)
|
2022-12-20 16:11:12 +00:00
|
|
|
case unfollow(id: String)
|
2022-12-22 11:26:11 +00:00
|
|
|
case familiarFollowers(withAccount: String)
|
2022-12-23 14:28:22 +00:00
|
|
|
case suggestions
|
2022-12-24 12:41:25 +00:00
|
|
|
case followers(id: String, maxId: String?)
|
|
|
|
case following(id: String, maxId: String?)
|
2023-01-02 18:23:44 +00:00
|
|
|
case lists(id: String)
|
2023-01-09 18:47:54 +00:00
|
|
|
case preferences
|
2023-01-19 17:22:31 +00:00
|
|
|
case block(id: String)
|
|
|
|
case unblock(id: String)
|
2023-02-06 11:25:51 +00:00
|
|
|
case mute(id: String, json: MuteData)
|
2023-01-19 17:22:31 +00:00
|
|
|
case unmute(id: String)
|
2023-02-18 17:28:16 +00:00
|
|
|
case relationshipNote(id: String, json: RelationshipNoteData)
|
2023-02-12 15:29:41 +00:00
|
|
|
|
2022-11-29 11:18:06 +00:00
|
|
|
public func path() -> String {
|
|
|
|
switch self {
|
2023-01-17 10:36:01 +00:00
|
|
|
case let .accounts(id):
|
2023-09-16 12:15:03 +00:00
|
|
|
"accounts/\(id)"
|
2023-12-08 07:04:35 +00:00
|
|
|
case .lookup:
|
|
|
|
"accounts/lookup"
|
2023-01-24 05:35:43 +00:00
|
|
|
case .favorites:
|
2023-09-16 12:15:03 +00:00
|
|
|
"favourites"
|
2023-01-09 18:26:56 +00:00
|
|
|
case .bookmarks:
|
2023-09-16 12:15:03 +00:00
|
|
|
"bookmarks"
|
2022-12-21 08:42:05 +00:00
|
|
|
case .followedTags:
|
2023-09-16 12:15:03 +00:00
|
|
|
"followed_tags"
|
2023-01-17 10:36:01 +00:00
|
|
|
case let .featuredTags(id):
|
2023-09-16 12:15:03 +00:00
|
|
|
"accounts/\(id)/featured_tags"
|
2022-12-01 08:05:26 +00:00
|
|
|
case .verifyCredentials:
|
2023-09-16 12:15:03 +00:00
|
|
|
"accounts/verify_credentials"
|
2024-01-02 20:16:27 +00:00
|
|
|
case .updateCredentials, .updateCredentialsMedia:
|
2023-09-16 12:15:03 +00:00
|
|
|
"accounts/update_credentials"
|
2023-01-17 10:36:01 +00:00
|
|
|
case let .statuses(id, _, _, _, _, _):
|
2023-09-16 12:15:03 +00:00
|
|
|
"accounts/\(id)/statuses"
|
2022-12-20 16:11:12 +00:00
|
|
|
case .relationships:
|
2023-09-16 12:15:03 +00:00
|
|
|
"accounts/relationships"
|
2023-01-23 17:50:59 +00:00
|
|
|
case let .follow(id, _, _):
|
2023-09-16 12:15:03 +00:00
|
|
|
"accounts/\(id)/follow"
|
2023-01-17 10:36:01 +00:00
|
|
|
case let .unfollow(id):
|
2023-09-16 12:15:03 +00:00
|
|
|
"accounts/\(id)/unfollow"
|
2022-12-22 11:26:11 +00:00
|
|
|
case .familiarFollowers:
|
2023-09-16 12:15:03 +00:00
|
|
|
"accounts/familiar_followers"
|
2022-12-23 14:28:22 +00:00
|
|
|
case .suggestions:
|
2023-09-16 12:15:03 +00:00
|
|
|
"suggestions"
|
2023-01-17 10:36:01 +00:00
|
|
|
case let .following(id, _):
|
2023-09-16 12:15:03 +00:00
|
|
|
"accounts/\(id)/following"
|
2023-01-17 10:36:01 +00:00
|
|
|
case let .followers(id, _):
|
2023-09-16 12:15:03 +00:00
|
|
|
"accounts/\(id)/followers"
|
2023-01-17 10:36:01 +00:00
|
|
|
case let .lists(id):
|
2023-09-16 12:15:03 +00:00
|
|
|
"accounts/\(id)/lists"
|
2023-01-09 18:47:54 +00:00
|
|
|
case .preferences:
|
2023-09-16 12:15:03 +00:00
|
|
|
"preferences"
|
2023-01-19 17:22:31 +00:00
|
|
|
case let .block(id):
|
2023-09-16 12:15:03 +00:00
|
|
|
"accounts/\(id)/block"
|
2023-01-19 17:22:31 +00:00
|
|
|
case let .unblock(id):
|
2023-09-16 12:15:03 +00:00
|
|
|
"accounts/\(id)/unblock"
|
2023-02-06 11:25:51 +00:00
|
|
|
case let .mute(id, _):
|
2023-09-16 12:15:03 +00:00
|
|
|
"accounts/\(id)/mute"
|
2023-01-19 17:22:31 +00:00
|
|
|
case let .unmute(id):
|
2023-09-16 12:15:03 +00:00
|
|
|
"accounts/\(id)/unmute"
|
2023-02-18 17:28:16 +00:00
|
|
|
case let .relationshipNote(id, _):
|
2023-09-16 12:15:03 +00:00
|
|
|
"accounts/\(id)/note"
|
2022-11-29 11:18:06 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-12 15:29:41 +00:00
|
|
|
|
2022-11-29 11:18:06 +00:00
|
|
|
public func queryItems() -> [URLQueryItem]? {
|
2022-12-18 19:30:19 +00:00
|
|
|
switch self {
|
2023-12-08 07:04:35 +00:00
|
|
|
case let .lookup(name):
|
|
|
|
return [
|
|
|
|
.init(name: "acct", value: name),
|
|
|
|
]
|
2023-01-17 10:36:01 +00:00
|
|
|
case let .statuses(_, sinceId, tag, onlyMedia, excludeReplies, pinned):
|
2022-12-21 19:26:38 +00:00
|
|
|
var params: [URLQueryItem] = []
|
|
|
|
if let tag {
|
|
|
|
params.append(.init(name: "tagged", value: tag))
|
|
|
|
}
|
|
|
|
if let sinceId {
|
|
|
|
params.append(.init(name: "max_id", value: sinceId))
|
|
|
|
}
|
2023-01-01 07:22:39 +00:00
|
|
|
if let onlyMedia {
|
|
|
|
params.append(.init(name: "only_media", value: onlyMedia ? "true" : "false"))
|
|
|
|
}
|
|
|
|
if let excludeReplies {
|
2023-01-28 18:29:16 +00:00
|
|
|
params.append(.init(name: "exclude_replies", value: excludeReplies ? "true" : "false"))
|
2023-01-01 07:22:39 +00:00
|
|
|
}
|
2023-01-03 17:22:08 +00:00
|
|
|
if let pinned {
|
|
|
|
params.append(.init(name: "pinned", value: pinned ? "true" : "false"))
|
|
|
|
}
|
2022-12-21 19:26:38 +00:00
|
|
|
return params
|
2022-12-23 14:28:22 +00:00
|
|
|
case let .relationships(ids):
|
|
|
|
return ids.map {
|
|
|
|
URLQueryItem(name: "id[]", value: $0)
|
|
|
|
}
|
2023-01-23 17:50:59 +00:00
|
|
|
case let .follow(_, notify, reblogs):
|
|
|
|
return [
|
|
|
|
.init(name: "notify", value: notify ? "true" : "false"),
|
2023-01-25 12:02:28 +00:00
|
|
|
.init(name: "reblogs", value: reblogs ? "true" : "false"),
|
2023-01-23 17:50:59 +00:00
|
|
|
]
|
2022-12-22 11:26:11 +00:00
|
|
|
case let .familiarFollowers(withAccount):
|
|
|
|
return [.init(name: "id[]", value: withAccount)]
|
2022-12-24 12:41:25 +00:00
|
|
|
case let .followers(_, maxId):
|
2022-12-28 18:10:13 +00:00
|
|
|
return makePaginationParam(sinceId: nil, maxId: maxId, mindId: nil)
|
2022-12-24 12:41:25 +00:00
|
|
|
case let .following(_, maxId):
|
2022-12-28 18:10:13 +00:00
|
|
|
return makePaginationParam(sinceId: nil, maxId: maxId, mindId: nil)
|
2023-01-24 05:35:43 +00:00
|
|
|
case let .favorites(sinceId):
|
2022-12-24 08:21:04 +00:00
|
|
|
guard let sinceId else { return nil }
|
|
|
|
return [.init(name: "max_id", value: sinceId)]
|
2023-01-09 18:26:56 +00:00
|
|
|
case let .bookmarks(sinceId):
|
|
|
|
guard let sinceId else { return nil }
|
|
|
|
return [.init(name: "max_id", value: sinceId)]
|
2022-12-18 19:30:19 +00:00
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
2022-11-29 11:18:06 +00:00
|
|
|
}
|
2023-02-12 15:29:41 +00:00
|
|
|
|
2023-02-06 11:25:51 +00:00
|
|
|
public var jsonValue: Encodable? {
|
|
|
|
switch self {
|
|
|
|
case let .mute(_, json):
|
2023-09-16 12:15:03 +00:00
|
|
|
json
|
2023-02-18 17:28:16 +00:00
|
|
|
case let .relationshipNote(_, json):
|
2023-09-16 12:15:03 +00:00
|
|
|
json
|
2023-02-24 06:55:24 +00:00
|
|
|
case let .updateCredentials(json):
|
2023-09-16 12:15:03 +00:00
|
|
|
json
|
2023-02-06 11:25:51 +00:00
|
|
|
default:
|
2023-09-16 12:15:03 +00:00
|
|
|
nil
|
2023-02-06 11:25:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-18 21:51:44 +00:00
|
|
|
public struct MuteData: Encodable, Sendable {
|
2023-02-06 11:25:51 +00:00
|
|
|
public let duration: Int
|
2023-02-12 15:29:41 +00:00
|
|
|
|
2023-02-06 11:25:51 +00:00
|
|
|
public init(duration: Int) {
|
|
|
|
self.duration = duration
|
|
|
|
}
|
2022-11-29 11:18:06 +00:00
|
|
|
}
|
2023-02-18 17:28:16 +00:00
|
|
|
|
2023-02-18 21:51:44 +00:00
|
|
|
public struct RelationshipNoteData: Encodable, Sendable {
|
2023-02-18 17:28:16 +00:00
|
|
|
public let comment: String
|
2023-02-21 06:23:42 +00:00
|
|
|
|
2023-02-18 17:28:16 +00:00
|
|
|
public init(note comment: String) {
|
|
|
|
self.comment = comment
|
|
|
|
}
|
|
|
|
}
|
2023-02-24 06:55:24 +00:00
|
|
|
|
|
|
|
public struct UpdateCredentialsData: Encodable, Sendable {
|
|
|
|
public struct SourceData: Encodable, Sendable {
|
|
|
|
public let privacy: Visibility
|
|
|
|
public let sensitive: Bool
|
2023-02-26 05:45:57 +00:00
|
|
|
|
2023-02-24 06:55:24 +00:00
|
|
|
public init(privacy: Visibility, sensitive: Bool) {
|
|
|
|
self.privacy = privacy
|
|
|
|
self.sensitive = sensitive
|
|
|
|
}
|
|
|
|
}
|
2023-02-26 05:45:57 +00:00
|
|
|
|
2023-02-24 06:55:24 +00:00
|
|
|
public struct FieldData: Encodable, Sendable {
|
|
|
|
public let name: String
|
|
|
|
public let value: String
|
2023-02-26 05:45:57 +00:00
|
|
|
|
2023-02-24 06:55:24 +00:00
|
|
|
public init(name: String, value: String) {
|
|
|
|
self.name = name
|
|
|
|
self.value = value
|
|
|
|
}
|
|
|
|
}
|
2023-02-26 05:45:57 +00:00
|
|
|
|
2023-02-24 06:55:24 +00:00
|
|
|
public let displayName: String
|
|
|
|
public let note: String
|
|
|
|
public let source: SourceData
|
|
|
|
public let bot: Bool
|
|
|
|
public let locked: Bool
|
|
|
|
public let discoverable: Bool
|
|
|
|
public let fieldsAttributes: [String: FieldData]
|
2023-02-26 05:45:57 +00:00
|
|
|
|
2023-02-24 06:55:24 +00:00
|
|
|
public init(displayName: String,
|
|
|
|
note: String,
|
|
|
|
source: UpdateCredentialsData.SourceData,
|
|
|
|
bot: Bool,
|
|
|
|
locked: Bool,
|
|
|
|
discoverable: Bool,
|
2023-02-26 05:45:57 +00:00
|
|
|
fieldsAttributes: [FieldData])
|
|
|
|
{
|
2023-02-24 06:55:24 +00:00
|
|
|
self.displayName = displayName
|
|
|
|
self.note = note
|
|
|
|
self.source = source
|
|
|
|
self.bot = bot
|
|
|
|
self.locked = locked
|
|
|
|
self.discoverable = discoverable
|
2023-02-26 05:45:57 +00:00
|
|
|
|
2023-02-24 06:55:24 +00:00
|
|
|
var fieldAttributes: [String: FieldData] = [:]
|
2023-02-24 08:23:16 +00:00
|
|
|
for (index, field) in fieldsAttributes.enumerated() {
|
|
|
|
fieldAttributes[String(index)] = field
|
2023-02-24 06:55:24 +00:00
|
|
|
}
|
|
|
|
self.fieldsAttributes = fieldAttributes
|
|
|
|
}
|
|
|
|
}
|