mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-26 10:10:58 +00:00
36 lines
817 B
Swift
36 lines
817 B
Swift
|
// Copyright © 2020 Metabolist. All rights reserved.
|
||
|
|
||
|
import Foundation
|
||
|
|
||
|
struct MastodonTarget<E: MastodonEndpoint> {
|
||
|
let baseURL: URL
|
||
|
let endpoint: E
|
||
|
let accessToken: String?
|
||
|
}
|
||
|
|
||
|
extension MastodonTarget: DecodableTarget {
|
||
|
typealias ResultType = E.ResultType
|
||
|
|
||
|
var pathComponents: [String] { endpoint.pathComponents }
|
||
|
|
||
|
var method: HTTPMethod { endpoint.method }
|
||
|
|
||
|
var encoding: ParameterEncoding { endpoint.encoding }
|
||
|
|
||
|
var parameters: [String: Any]? { endpoint.parameters }
|
||
|
|
||
|
var headers: HTTPHeaders? {
|
||
|
var headers = endpoint.headers
|
||
|
|
||
|
if let accessToken = accessToken {
|
||
|
if headers == nil {
|
||
|
headers = HTTPHeaders()
|
||
|
}
|
||
|
|
||
|
headers?.add(.authorization(bearerToken: accessToken))
|
||
|
}
|
||
|
|
||
|
return headers
|
||
|
}
|
||
|
}
|