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