@@ -28,7 +28,8 @@ public struct HttpClient {
2828
2929 /// Send a request - Async - with params
3030 /// This method can be used for **GET** requests to external APIs
31- /// - Parameter params: GET request parameters
31+ /// - Parameter params: GET request parameters **CAUTION** for api with `.valueOnly` or `.keyValuePair`, the route api could be unexpected sorted.,
32+ /// i.e., ["route1": "one", "route2": "two"] may result in /route2/two/route1/one, depends on the internal NSDictionary key arrangement structure.
3233 /// - Parameter responseType: expected response type
3334 /// - Parameter completion: Closure as the completion handler
3435 /// - Parameter response: mapped model ready to use
@@ -46,23 +47,20 @@ public struct HttpClient {
4647 break
4748 case . get:
4849 if api. paramFormat == . valueOnly {
49- for (_, value) in params {
50- parameteredURL. append ( " / \( value) " )
51- }
50+ let path : [ String ] = params. map { " / " + " \( $0. value) " . stringByEncodingURL }
51+ parameteredURL. append ( path. joined ( ) )
5252 } else if api. paramFormat == . keyValuePair {
53- for (key, value) in params {
54- parameteredURL. append ( " / \( key) / \( value) " )
53+ let path : [ String ] = params. map {
54+ " / " + $0. key. stringByEncodingURL +
55+ " / " + " \( $0. value) " . stringByEncodingURL
5556 }
57+ parameteredURL. append ( path. joined ( ) )
5658 } else if api. paramFormat == . urlEncoding {
57- parameteredURL. append ( " ? " )
58- var index = 0
59- for (key, value) in params {
60- parameteredURL. append ( " \( key) = \( value) " )
61- index += 1
62- if index < params. count {
63- parameteredURL. append ( " & " )
64- }
59+ let path : [ String ] = params. map {
60+ $0. key. stringByEncodingURL +
61+ " = " + " \( $0. value) " . stringByEncodingURL
6562 }
63+ parameteredURL. append ( " ? " + path. joined ( separator: " & " ) )
6664 }
6765 default :
6866 break
0 commit comments