Array mapping added

This commit is contained in:
Alexey Gerasimov 2017-02-14 20:09:34 +03:00
parent 3950ddeedb
commit 7b57ad8310
5 changed files with 34 additions and 6 deletions

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "LeadKit"
s.version = "0.4.2"
s.version = "0.4.3"
s.summary = "iOS framework with a bunch of tools for rapid development"
s.homepage = "https://github.com/TouchInstinct/LeadKit"
s.license = "Apache License, Version 2.0"

BIN
LeadKit/.DS_Store vendored

Binary file not shown.

View File

@ -52,6 +52,19 @@ public extension Reactive where Base: Alamofire.SessionManager {
.flatMap { $0.validate().rx.apiResponse(mappingQueue: mappingQueue) }
}
/// Method which executes request and serializes response into array of target objects
///
/// - Parameter requestParameters: api parameters to pass Alamofire
/// - Parameter mappingQueue: The dispatch queue to use for mapping
/// - Returns: Observable with HTTP URL Response and array of target objects
func responseModel<T: ImmutableMappable>(requestParameters: ApiRequestParameters,
mappingQueue: DispatchQueue = DispatchQueue.global())
-> Observable<(HTTPURLResponse, [T])> {
return apiRequest(requestParameters: requestParameters)
.flatMap { $0.rx.apiResponse(mappingQueue: mappingQueue) }
}
/// Method which executes request and serializes response into target object
///
/// - Parameter requestParameters: api parameters to pass Alamofire

View File

@ -42,6 +42,21 @@ public extension Reactive where Base: DataRequest {
}
}
/// Method which serializes response into array of target objects
///
/// - Parameter mappingQueue: The dispatch queue to use for mapping
/// - Returns: Observable with HTTP URL Response and array of target objects
func apiResponse<T: ImmutableMappable>(mappingQueue: DispatchQueue = DispatchQueue.global())
-> Observable<(HTTPURLResponse, [T])> {
return responseJSONOnQueue(mappingQueue)
.map { resp, value in
let jsonArray = try cast(value) as [[String: Any]]
return (resp, try Mapper<T>().mapArray(JSONArray: jsonArray))
}
}
/// Method which serializes response into target object
///
/// - Parameter mappingQueue: The dispatch queue to use for mapping

View File

@ -27,11 +27,11 @@ import Alamofire
*/
public struct ApiRequestParameters {
let method: HTTPMethod
let url: URLConvertible
let parameters: Parameters?
let encoding: ParameterEncoding
let headers: HTTPHeaders?
public let method: HTTPMethod
public let url: URLConvertible
public let parameters: Parameters?
public let encoding: ParameterEncoding
public let headers: HTTPHeaders?
public init(url: URLConvertible,
method: HTTPMethod = .get,