mirror of
https://github.com/block/goose.git
synced 2026-07-17 12:56:20 +02:00
69 lines
2.2 KiB
Swift
69 lines
2.2 KiB
Swift
// APIs.swift
|
|
//
|
|
// Generated by openapi-generator
|
|
// https://openapi-generator.tech
|
|
//
|
|
|
|
import Foundation
|
|
#if canImport(FoundationNetworking)
|
|
import FoundationNetworking
|
|
#endif
|
|
open class GooseAPIAPI {
|
|
public static var basePath = "http://localhost"
|
|
public static var customHeaders: [String: String] = [:]
|
|
public static var credential: URLCredential?
|
|
public static var requestBuilderFactory: RequestBuilderFactory = URLSessionRequestBuilderFactory()
|
|
public static var apiResponseQueue: DispatchQueue = .main
|
|
}
|
|
|
|
open class RequestBuilder<T> {
|
|
var credential: URLCredential?
|
|
var headers: [String: String]
|
|
public let parameters: [String: Any]?
|
|
public let method: String
|
|
public let URLString: String
|
|
public let requestTask: RequestTask = RequestTask()
|
|
public let requiresAuthentication: Bool
|
|
|
|
/// Optional block to obtain a reference to the request's progress instance when available.
|
|
public var onProgressReady: ((Progress) -> Void)?
|
|
|
|
required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool) {
|
|
self.method = method
|
|
self.URLString = URLString
|
|
self.parameters = parameters
|
|
self.headers = headers
|
|
self.requiresAuthentication = requiresAuthentication
|
|
|
|
addHeaders(GooseAPIAPI.customHeaders)
|
|
addCredential()
|
|
}
|
|
|
|
open func addHeaders(_ aHeaders: [String: String]) {
|
|
for (header, value) in aHeaders {
|
|
headers[header] = value
|
|
}
|
|
}
|
|
|
|
@discardableResult
|
|
open func execute(_ apiResponseQueue: DispatchQueue = GooseAPIAPI.apiResponseQueue, _ completion: @escaping (_ result: Swift.Result<Response<T>, ErrorResponse>) -> Void) -> RequestTask {
|
|
return requestTask
|
|
}
|
|
|
|
public func addHeader(name: String, value: String) -> Self {
|
|
if !value.isEmpty {
|
|
headers[name] = value
|
|
}
|
|
return self
|
|
}
|
|
|
|
open func addCredential() {
|
|
credential = GooseAPIAPI.credential
|
|
}
|
|
}
|
|
|
|
public protocol RequestBuilderFactory {
|
|
func getNonDecodableBuilder<T>() -> RequestBuilder<T>.Type
|
|
func getBuilder<T: Decodable>() -> RequestBuilder<T>.Type
|
|
}
|