Skip to content

Commit 500c620

Browse files
authored
Merge pull request #27 from hamtiko/master
Improvements with parameters encoding
2 parents 8e15346 + eb1d159 commit 500c620

3 files changed

Lines changed: 12 additions & 35 deletions

File tree

Example/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PODS:
1818
- RxSwift (~> 5)
1919
- RxRelay (5.0.0):
2020
- RxSwift (~> 5)
21-
- RxRestClient (1.2.1):
21+
- RxRestClient (1.3.0):
2222
- Alamofire (~> 4)
2323
- RxAlamofire (~> 5)
2424
- RxCocoa (~> 5)
@@ -65,7 +65,7 @@ SPEC CHECKSUMS:
6565
RxCocoa: fcf32050ac00d801f34a7f71d5e8e7f23026dcd8
6666
RxOptional: 9904e2219d59260c3c171273d475b2126de187e8
6767
RxRelay: 4f7409406a51a55cd88483f21ed898c234d60f18
68-
RxRestClient: 4bf25b1d2355c6f6815d0d71f2f6e32e3d34f0d9
68+
RxRestClient: 63e5a2cf7ceeeed169eb40925fb9a6c31a806fe0
6969
RxSwift: 8b0671caa829a763bbce7271095859121cbd895f
7070
SDWebImage: 3f3f0c02f09798048c47a5ed0a13f17b063572d8
7171

RxRestClient.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'RxRestClient'
3-
s.version = '1.2.1'
3+
s.version = '1.3.0'
44
s.summary = 'Simple REST Client based on RxSwift and Alamofire.'
55
s.swift_version = '5.0'
66

RxRestClient/Classes/RxRestClient.swift

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public struct RxRestClientOptions {
2020
public var headers = ["Content-Type": "application/json"]
2121
public var maxConcurrentOperationCount = 2
2222
public var logger: RxRestClientLogger?
23-
public var urlEncoding: ParameterEncoding = URLEncoding.default
24-
public var jsonEncoding: ParameterEncoding = JSONEncoding.default
23+
public var queryEncoding: ParameterEncoding = URLEncoding.default
24+
public var bodyEncoding: ParameterEncoding = JSONEncoding.default
2525
public var jsonDecoder: JSONDecoder = JSONDecoder()
2626
public var jsonEncoder: JSONEncoder = JSONEncoder()
2727
public var sessionManager: SessionManager?
@@ -99,7 +99,7 @@ open class RxRestClient {
9999
/// - object: dictinary representing body of request
100100
/// - Returns: An observable of a the response state
101101
public func post<T: ResponseState>(url: URL, object: [String: Any]) -> Observable<T> {
102-
return run(request(.post, url, object: object))
102+
return run(request(.post, url, object: object, encoding: options.bodyEncoding))
103103
}
104104

105105
/// Do POST Request
@@ -159,7 +159,7 @@ open class RxRestClient {
159159
/// - object: dictinary representing body of request
160160
/// - Returns: An observable of a the response state
161161
public func put<T: ResponseState>(url: URL, object: [String: Any]) -> Observable<T> {
162-
return run(request(.put, url, object: object))
162+
return run(request(.put, url, object: object, encoding: options.bodyEncoding))
163163
}
164164

165165
/// Do PUT Request
@@ -219,7 +219,7 @@ open class RxRestClient {
219219
/// - object: dictinary representing body of request
220220
/// - Returns: An observable of a the response state
221221
public func patch<T: ResponseState>(url: URL, object: [String: Any]) -> Observable<T> {
222-
return run(request(.patch, url, object: object))
222+
return run(request(.patch, url, object: object, encoding: options.bodyEncoding))
223223
}
224224

225225
/// Do PATCH Request
@@ -256,30 +256,7 @@ open class RxRestClient {
256256
/// - object: dictinary representing body of request, default value is empty
257257
/// - Returns: An observable of a the response state
258258
public func delete<T: ResponseState>(url: URL, object: [String: Any] = [:]) -> Observable<T> {
259-
return run(request(.delete, url, object: object))
260-
}
261-
262-
/// Do DELETE Request
263-
///
264-
/// - Parameters:
265-
/// - endpoint: Relative path of endpoint which will be appended to baseUrl
266-
/// - array: array representing body of request, default value is empty
267-
/// - Returns: An observable of a the response state
268-
public func delete<T: ResponseState>(_ endpoint: String, array: [Any]) -> Observable<T> {
269-
guard let url = buildURL(endpoint) else {
270-
return Observable.error(RxRestClientError.urlBuildFailed)
271-
}
272-
return delete(url: url, array: array)
273-
}
274-
275-
/// Do DELETE Request
276-
///
277-
/// - Parameters:
278-
/// - url: absalute url
279-
/// - array: array representing body of request, default value is empty
280-
/// - Returns: An observable of a the response state
281-
public func delete<T: ResponseState>(url: URL, array: [Any]) -> Observable<T> {
282-
return run(request(.delete, url, array: array))
259+
return run(request(.delete, url, object: object, encoding: options.queryEncoding))
283260
}
284261

285262
/// Do DELETE Request
@@ -316,7 +293,7 @@ open class RxRestClient {
316293
/// - query: dictinary representing query of request, default value is empty
317294
/// - Returns: An observable of a the response state
318295
public func get<T: ResponseState>(url: URL, query: [String: Any] = [:]) -> Observable<T> {
319-
return run(request(.get, url, object: query, encoding: options.urlEncoding))
296+
return run(request(.get, url, object: query, encoding: options.queryEncoding))
320297
}
321298

322299
/// Do GET Request
@@ -432,12 +409,12 @@ open class RxRestClient {
432409
/// - object: A dictionary containing all necessary options
433410
/// - encoding: The kind of encoding used to process parameters
434411
/// - Returns: An observable of a the created DataRequest
435-
public func request(_ method: HTTPMethod, _ url: URLConvertible, object: [String: Any], encoding: ParameterEncoding? = nil) -> Observable<DataRequest> {
412+
public func request(_ method: HTTPMethod, _ url: URLConvertible, object: [String: Any], encoding: ParameterEncoding) -> Observable<DataRequest> {
436413
return getSessionManager().rx.request(
437414
method,
438415
url,
439416
parameters: object,
440-
encoding: encoding ?? options.jsonEncoding,
417+
encoding: encoding,
441418
headers: options.headers
442419
)
443420
}

0 commit comments

Comments
 (0)