Skip to content

Commit 6b88ce5

Browse files
Updated extensions to to use same parameters
This addresses objcio#3.
1 parent 6676e02 commit 6b88ce5

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

Sources/TinyNetworking/Endpoint.swift

+15-8
Original file line numberDiff line numberDiff line change
@@ -119,27 +119,32 @@ extension Endpoint where A == () {
119119
/// - method: the HTTP method
120120
/// - url: the endpoint's URL
121121
/// - accept: the content type for the `Accept` header
122+
/// - contentType: the content type for the `Content-Type` header
123+
/// - body: the body of the request.
122124
/// - headers: additional headers for the request
123125
/// - expectedStatusCode: the status code that's expected. If this returns false for a given status code, parsing fails.
126+
/// - timeOutInterval: the timeout interval for his request
124127
/// - query: query parameters to append to the url
125-
public init(_ method: Method, url: URL, accept: ContentType? = nil, headers: [String:String] = [:], expectedStatusCode: @escaping (Int) -> Bool = expected200to300, query: [String:String] = [:]) {
126-
self.init(method, url: url, accept: accept, headers: headers, expectedStatusCode: expectedStatusCode, query: query, parse: { _, _ in .success(()) })
128+
public init(_ method: Method, url: URL, accept: ContentType? = nil, contentType: ContentType? = nil, body: Data? = nil, headers: [String:String] = [:], expectedStatusCode: @escaping (Int) -> Bool = expected200to300, timeOutInterval: TimeInterval = 10, query: [String:String] = [:]) {
129+
self.init(method, url: url, accept: accept, contentType: contentType, body: body, headers: headers, expectedStatusCode: expectedStatusCode, timeOutInterval: timeOutInterval, query: query, parse: { _, _ in .success(()) })
127130
}
128131

129132
/// Creates a new endpoint without a parse function.
130133
///
131134
/// - Parameters:
135+
/// - method: the HTTP method
132136
/// - json: the HTTP method
133137
/// - url: the endpoint's URL
134138
/// - accept: the content type for the `Accept` header
135139
/// - body: the body of the request. This gets encoded using a default `JSONEncoder` instance.
136140
/// - headers: additional headers for the request
137141
/// - expectedStatusCode: the status code that's expected. If this returns false for a given status code, parsing fails.
142+
/// - timeOutInterval: the timeout interval for his request
138143
/// - query: query parameters to append to the url
139144
/// - encoder: the encoder that's used for encoding `A`s.
140-
public init<B: Encodable>(json method: Method, url: URL, accept: ContentType? = .json, body: B, headers: [String:String] = [:], expectedStatusCode: @escaping (Int) -> Bool = expected200to300, query: [String:String] = [:], encoder: JSONEncoder = JSONEncoder()) {
145+
public init<B: Encodable>(json method: Method, url: URL, accept: ContentType? = .json, body: B, headers: [String:String] = [:], expectedStatusCode: @escaping (Int) -> Bool = expected200to300, timeOutInterval: TimeInterval = 10, query: [String:String] = [:], encoder: JSONEncoder = JSONEncoder()) {
141146
let b = try! encoder.encode(body)
142-
self.init(method, url: url, accept: accept, contentType: .json, body: b, headers: headers, expectedStatusCode: expectedStatusCode, query: query, parse: { _, _ in .success(()) })
147+
self.init(method, url: url, accept: accept, contentType: .json, body: b, headers: headers, expectedStatusCode: expectedStatusCode, timeOutInterval: timeOutInterval, query: query, parse: { _, _ in .success(()) })
143148
}
144149
}
145150

@@ -153,10 +158,11 @@ extension Endpoint where A: Decodable {
153158
/// - accept: the content type for the `Accept` header
154159
/// - headers: additional headers for the request
155160
/// - expectedStatusCode: the status code that's expected. If this returns false for a given status code, parsing fails.
161+
/// - timeOutInterval: the timeout interval for his request
156162
/// - query: query parameters to append to the url
157163
/// - decoder: the decoder that's used for decoding `A`s.
158-
public init(json method: Method, url: URL, accept: ContentType = .json, headers: [String: String] = [:], expectedStatusCode: @escaping (Int) -> Bool = expected200to300, query: [String: String] = [:], decoder: JSONDecoder = JSONDecoder()) {
159-
self.init(method, url: url, accept: accept, body: nil, headers: headers, expectedStatusCode: expectedStatusCode, query: query) { data, _ in
164+
public init(json method: Method, url: URL, accept: ContentType = .json, headers: [String: String] = [:], expectedStatusCode: @escaping (Int) -> Bool = expected200to300, timeOutInterval: TimeInterval = 10, query: [String: String] = [:], decoder: JSONDecoder = JSONDecoder()) {
165+
self.init(method, url: url, accept: accept, body: nil, headers: headers, expectedStatusCode: expectedStatusCode, timeOutInterval: timeOutInterval, query: query) { data, _ in
160166
return Result {
161167
guard let dat = data else { throw NoDataError() }
162168
return try decoder.decode(A.self, from: dat)
@@ -173,12 +179,13 @@ extension Endpoint where A: Decodable {
173179
/// - body: the body of the request. This is encoded using a default encoder.
174180
/// - headers: additional headers for the request
175181
/// - expectedStatusCode: the status code that's expected. If this returns false for a given status code, parsing fails.
182+
/// - timeOutInterval: the timeout interval for his request
176183
/// - query: query parameters to append to the url
177184
/// - decoder: the decoder that's used for decoding `A`s.
178185
/// - encoder: the encoder that's used for encoding `A`s.
179-
public init<B: Encodable>(json method: Method, url: URL, accept: ContentType = .json, body: B? = nil, headers: [String: String] = [:], expectedStatusCode: @escaping (Int) -> Bool = expected200to300, query: [String: String] = [:], decoder: JSONDecoder = JSONDecoder(), encoder: JSONEncoder = JSONEncoder()) {
186+
public init<B: Encodable>(json method: Method, url: URL, accept: ContentType = .json, body: B? = nil, headers: [String: String] = [:], expectedStatusCode: @escaping (Int) -> Bool = expected200to300, timeOutInterval: TimeInterval = 10, query: [String: String] = [:], decoder: JSONDecoder = JSONDecoder(), encoder: JSONEncoder = JSONEncoder()) {
180187
let b = body.map { try! encoder.encode($0) }
181-
self.init(method, url: url, accept: accept, contentType: .json, body: b, headers: headers, expectedStatusCode: expectedStatusCode, query: query) { data, _ in
188+
self.init(method, url: url, accept: accept, contentType: .json, body: b, headers: headers, expectedStatusCode: expectedStatusCode, timeOutInterval: timeOutInterval, query: query) { data, _ in
182189
return Result {
183190
guard let dat = data else { throw NoDataError() }
184191
return try decoder.decode(A.self, from: dat)

0 commit comments

Comments
 (0)