Tusker/Packages/Pachyderm/Sources/Pachyderm/Model/List.swift

64 lines
2.0 KiB
Swift
Raw Normal View History

2018-09-11 14:52:21 +00:00
//
// List.swift
// Pachyderm
//
// Created by Shadowfacts on 9/9/18.
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import Foundation
public struct List: ListProtocol, Decodable, Equatable, Hashable, Sendable {
2018-09-11 14:52:21 +00:00
public let id: String
public let title: String
2018-09-11 14:52:21 +00:00
2019-12-17 23:48:29 +00:00
public var timeline: Timeline {
return .list(id: id)
}
public init(id: String, title: String) {
self.id = id
self.title = title
}
2020-06-24 20:40:45 +00:00
public static func ==(lhs: List, rhs: List) -> Bool {
2022-11-19 19:08:39 +00:00
return lhs.id == rhs.id && lhs.title == rhs.title
2020-06-24 20:40:45 +00:00
}
public func hash(into hasher: inout Hasher) {
hasher.combine(id)
2022-11-19 19:08:39 +00:00
hasher.combine(title)
2020-06-24 20:40:45 +00:00
}
public static func getAccounts(_ listID: String, range: RequestRange = .default) -> Request<[Account]> {
var request = Request<[Account]>(method: .get, path: "/api/v1/lists/\(listID)/accounts")
2018-09-11 14:52:21 +00:00
request.range = range
return request
2018-09-11 14:52:21 +00:00
}
public static func update(_ listID: String, title: String) -> Request<List> {
return Request<List>(method: .put, path: "/api/v1/lists/\(listID)", body: ParametersBody(["title" => title]))
2018-09-11 14:52:21 +00:00
}
public static func delete(_ listID: String) -> Request<Empty> {
return Request<Empty>(method: .delete, path: "/api/v1/lists/\(listID)")
2018-09-11 14:52:21 +00:00
}
public static func add(_ listID: String, accounts accountIDs: [String]) -> Request<Empty> {
return Request<Empty>(method: .post, path: "/api/v1/lists/\(listID)/accounts", body: ParametersBody(
2019-12-18 03:56:53 +00:00
"account_ids" => accountIDs
2018-09-11 14:52:21 +00:00
))
}
public static func remove(_ listID: String, accounts accountIDs: [String]) -> Request<Empty> {
return Request<Empty>(method: .delete, path: "/api/v1/lists/\(listID)/accounts", body: ParametersBody(
2019-12-18 03:56:53 +00:00
"account_ids" => accountIDs
2018-09-11 14:52:21 +00:00
))
}
private enum CodingKeys: String, CodingKey {
case id
case title
}
}