mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-05-14 18:42:42 +00:00
30 lines
583 B
Swift
30 lines
583 B
Swift
import Foundation
|
|
|
|
public enum Polls: Endpoint {
|
|
case poll(id: String)
|
|
case vote(id: String, votes: [Int])
|
|
|
|
public func path() -> String {
|
|
switch self {
|
|
case let .poll(id):
|
|
return "polls/\(id)/"
|
|
case let .vote(id, _):
|
|
return "polls/\(id)/votes"
|
|
}
|
|
}
|
|
|
|
public func queryItems() -> [URLQueryItem]? {
|
|
switch self {
|
|
case let .vote(_, votes):
|
|
var params: [URLQueryItem] = []
|
|
for vote in votes {
|
|
params.append(.init(name: "choices[]", value: "\(vote)"))
|
|
}
|
|
return params
|
|
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
}
|