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

48 lines
978 B
Swift
Raw Normal View History

2020-09-26 08:37:30 +02:00
// Copyright © 2020 Metabolist. All rights reserved.
import Foundation
import HTTP
import Mastodon
public enum ResultsEndpoint {
case search(query: String, resolve: Bool)
}
extension ResultsEndpoint: Endpoint {
public typealias ResultType = Results
public var APIVersion: String {
switch self {
case .search:
return "v2"
}
}
public var pathComponentsInContext: [String] {
switch self {
case .search:
return ["search"]
}
}
public var method: HTTPMethod {
switch self {
case .search:
return .get
}
}
2020-10-27 04:01:12 +01:00
public var queryParameters: [URLQueryItem] {
2020-09-26 08:37:30 +02:00
switch self {
case let .search(query, resolve):
2020-10-27 04:01:12 +01:00
var params = [URLQueryItem(name: "q", value: query)]
2020-09-26 08:37:30 +02:00
if resolve {
2020-10-27 04:01:12 +01:00
params.append(.init(name: "resolve", value: "true"))
2020-09-26 08:37:30 +02:00
}
return params
}
}
}