-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPIs.swift
executable file
·76 lines (62 loc) · 2.13 KB
/
APIs.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// APIs.swift
//
// Generated by swagger-codegen
// https://github.com/swagger-api/swagger-codegen
//
import Foundation
open class SwaggerClientAPI {
open static var basePath = "https://api.uber.com/v1"
open static var credential: URLCredential?
open static var customHeaders: [String:String] = [:]
static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory()
}
open class APIBase {
func toParameters(_ encodable: JSONEncodable?) -> [String: Any]? {
let encoded: Any? = encodable?.encodeToJSON()
if encoded! is [Any] {
var dictionary = [String:Any]()
for (index, item) in (encoded as! [Any]).enumerated() {
dictionary["\(index)"] = item
}
return dictionary
} else {
return encoded as? [String:Any]
}
}
}
open class RequestBuilder<T> {
var credential: URLCredential?
var headers: [String:String] = [:]
let parameters: [String:Any]?
let isBody: Bool
let method: String
let URLString: String
/// Optional block to obtain a reference to the request's progress instance when available.
public var onProgressReady: ((Progress) -> ())?
required public init(method: String, URLString: String, parameters: [String:Any]?, isBody: Bool) {
self.method = method
self.URLString = URLString
self.parameters = parameters
self.isBody = isBody
addHeaders(SwaggerClientAPI.customHeaders)
}
open func addHeaders(_ aHeaders:[String:String]) {
for (header, value) in aHeaders {
headers[header] = value
}
}
open func execute(_ completion: @escaping (_ response: Response<T>?, _ error: Error?) -> Void) { }
public func addHeader(name: String, value: String) -> Self {
if !value.isEmpty {
headers[name] = value
}
return self
}
open func addCredential() -> Self {
self.credential = SwaggerClientAPI.credential
return self
}
}
public protocol RequestBuilderFactory {
func getBuilder<T>() -> RequestBuilder<T>.Type
}