use Convertible mapper
This commit is contained in:
parent
be3f5abf79
commit
7b01f94649
4
Cartfile
4
Cartfile
|
|
@ -1,5 +1,5 @@
|
|||
github "CocoaLumberjack/CocoaLumberjack" ~> 3.0.0
|
||||
github "ReactiveX/RxSwift" "3.0.0-beta.1"
|
||||
github "lyft/mapper" "5.0.0-beta.2"
|
||||
github "Alamofire/Alamofire" ~> 4.0.0
|
||||
github "RxSwiftCommunity/RxAlamofire" "3.0.0-beta.1"
|
||||
github "RxSwiftCommunity/RxAlamofire" "3.0.0-beta.1"
|
||||
github "petropavel13/Convertible" "1.1.0"
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
github "Alamofire/Alamofire" "4.0.1"
|
||||
github "CocoaLumberjack/CocoaLumberjack" "3.0.0"
|
||||
github "petropavel13/Reflection" "0.15.0"
|
||||
github "ReactiveX/RxSwift" "3.0.0-beta.1"
|
||||
github "lyft/mapper" "5.0.0-beta.2"
|
||||
github "petropavel13/Convertible" "1.1.0"
|
||||
github "RxSwiftCommunity/RxAlamofire" "3.0.0-beta.1"
|
||||
|
|
|
|||
|
|
@ -13,8 +13,10 @@
|
|||
780D23461DA416F80084620D /* CGContext+Initializers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 780D23451DA416F80084620D /* CGContext+Initializers.swift */; };
|
||||
7837F60F1CBCF5C0000D74C1 /* EstimatedViewHeightProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7837F60E1CBCF5C0000D74C1 /* EstimatedViewHeightProtocol.swift */; };
|
||||
786D78E81D53C378006B2CEA /* AlamofireRequest+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 786D78E71D53C378006B2CEA /* AlamofireRequest+Extensions.swift */; };
|
||||
786D78EA1D53C43E006B2CEA /* ApiError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 786D78E91D53C43E006B2CEA /* ApiError.swift */; };
|
||||
786D78EA1D53C43E006B2CEA /* RequestError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 786D78E91D53C43E006B2CEA /* RequestError.swift */; };
|
||||
786D78EC1D53C46E006B2CEA /* AlamofireManager+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 786D78EB1D53C46E006B2CEA /* AlamofireManager+Extensions.swift */; };
|
||||
786FFEB71DA7F604008F28A7 /* Convertible.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 786FFEB51DA7F604008F28A7 /* Convertible.framework */; };
|
||||
786FFEB81DA7F604008F28A7 /* Reflection.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 786FFEB61DA7F604008F28A7 /* Reflection.framework */; };
|
||||
787682FA1CAD40C300532AB3 /* StaticEstimatedViewHeightProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 787682F91CAD40C200532AB3 /* StaticEstimatedViewHeightProtocol.swift */; };
|
||||
787783631CA03CA0001CDC9B /* IndexPath+ImmutableIndexPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 787783621CA03CA0001CDC9B /* IndexPath+ImmutableIndexPath.swift */; };
|
||||
787783671CA04D4A001CDC9B /* String+SizeCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 787783661CA04D4A001CDC9B /* String+SizeCalculation.swift */; };
|
||||
|
|
@ -28,7 +30,6 @@
|
|||
78B0364B1DA61EDE0021D5CC /* CGImage+Crop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B0364A1DA61EDE0021D5CC /* CGImage+Crop.swift */; };
|
||||
78B0365E1DA624C10021D5CC /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78B036581DA624C10021D5CC /* Alamofire.framework */; };
|
||||
78B0365F1DA624C10021D5CC /* CocoaLumberjack.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78B036591DA624C10021D5CC /* CocoaLumberjack.framework */; };
|
||||
78B036601DA624C10021D5CC /* Mapper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78B0365A1DA624C10021D5CC /* Mapper.framework */; };
|
||||
78B036611DA624C10021D5CC /* RxAlamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78B0365B1DA624C10021D5CC /* RxAlamofire.framework */; };
|
||||
78B036621DA624C10021D5CC /* RxCocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78B0365C1DA624C10021D5CC /* RxCocoa.framework */; };
|
||||
78B036631DA624C10021D5CC /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78B0365D1DA624C10021D5CC /* RxSwift.framework */; };
|
||||
|
|
@ -72,8 +73,10 @@
|
|||
780D23451DA416F80084620D /* CGContext+Initializers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CGContext+Initializers.swift"; sourceTree = "<group>"; };
|
||||
7837F60E1CBCF5C0000D74C1 /* EstimatedViewHeightProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EstimatedViewHeightProtocol.swift; sourceTree = "<group>"; };
|
||||
786D78E71D53C378006B2CEA /* AlamofireRequest+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AlamofireRequest+Extensions.swift"; sourceTree = "<group>"; };
|
||||
786D78E91D53C43E006B2CEA /* ApiError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApiError.swift; sourceTree = "<group>"; };
|
||||
786D78E91D53C43E006B2CEA /* RequestError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestError.swift; sourceTree = "<group>"; };
|
||||
786D78EB1D53C46E006B2CEA /* AlamofireManager+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AlamofireManager+Extensions.swift"; sourceTree = "<group>"; };
|
||||
786FFEB51DA7F604008F28A7 /* Convertible.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Convertible.framework; path = ../../../Carthage/Build/iOS/Convertible.framework; sourceTree = "<group>"; };
|
||||
786FFEB61DA7F604008F28A7 /* Reflection.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Reflection.framework; path = ../../../Carthage/Build/iOS/Reflection.framework; sourceTree = "<group>"; };
|
||||
787682F91CAD40C200532AB3 /* StaticEstimatedViewHeightProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StaticEstimatedViewHeightProtocol.swift; sourceTree = "<group>"; };
|
||||
787783621CA03CA0001CDC9B /* IndexPath+ImmutableIndexPath.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "IndexPath+ImmutableIndexPath.swift"; sourceTree = "<group>"; };
|
||||
787783661CA04D4A001CDC9B /* String+SizeCalculation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+SizeCalculation.swift"; sourceTree = "<group>"; };
|
||||
|
|
@ -87,7 +90,6 @@
|
|||
78B0364A1DA61EDE0021D5CC /* CGImage+Crop.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CGImage+Crop.swift"; sourceTree = "<group>"; };
|
||||
78B036581DA624C10021D5CC /* Alamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Alamofire.framework; path = ../../../Carthage/Build/iOS/Alamofire.framework; sourceTree = "<group>"; };
|
||||
78B036591DA624C10021D5CC /* CocoaLumberjack.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CocoaLumberjack.framework; path = ../../../Carthage/Build/iOS/CocoaLumberjack.framework; sourceTree = "<group>"; };
|
||||
78B0365A1DA624C10021D5CC /* Mapper.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Mapper.framework; path = ../../../Carthage/Build/iOS/Mapper.framework; sourceTree = "<group>"; };
|
||||
78B0365B1DA624C10021D5CC /* RxAlamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxAlamofire.framework; path = ../../../Carthage/Build/iOS/RxAlamofire.framework; sourceTree = "<group>"; };
|
||||
78B0365C1DA624C10021D5CC /* RxCocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxCocoa.framework; path = ../../../Carthage/Build/iOS/RxCocoa.framework; sourceTree = "<group>"; };
|
||||
78B0365D1DA624C10021D5CC /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxSwift.framework; path = ../../../Carthage/Build/iOS/RxSwift.framework; sourceTree = "<group>"; };
|
||||
|
|
@ -122,11 +124,12 @@
|
|||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
78B036601DA624C10021D5CC /* Mapper.framework in Frameworks */,
|
||||
78B0365F1DA624C10021D5CC /* CocoaLumberjack.framework in Frameworks */,
|
||||
78B036631DA624C10021D5CC /* RxSwift.framework in Frameworks */,
|
||||
78B0365E1DA624C10021D5CC /* Alamofire.framework in Frameworks */,
|
||||
786FFEB81DA7F604008F28A7 /* Reflection.framework in Frameworks */,
|
||||
78B036621DA624C10021D5CC /* RxCocoa.framework in Frameworks */,
|
||||
786FFEB71DA7F604008F28A7 /* Convertible.framework in Frameworks */,
|
||||
78B036611DA624C10021D5CC /* RxAlamofire.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
@ -147,10 +150,11 @@
|
|||
children = (
|
||||
78B036581DA624C10021D5CC /* Alamofire.framework */,
|
||||
78B036591DA624C10021D5CC /* CocoaLumberjack.framework */,
|
||||
78B0365A1DA624C10021D5CC /* Mapper.framework */,
|
||||
78B0365B1DA624C10021D5CC /* RxAlamofire.framework */,
|
||||
78B0365C1DA624C10021D5CC /* RxCocoa.framework */,
|
||||
78B0365D1DA624C10021D5CC /* RxSwift.framework */,
|
||||
786FFEB51DA7F604008F28A7 /* Convertible.framework */,
|
||||
786FFEB61DA7F604008F28A7 /* Reflection.framework */,
|
||||
);
|
||||
path = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -158,7 +162,7 @@
|
|||
78011A651D47AF3000EA16A2 /* Enums */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
786D78E91D53C43E006B2CEA /* ApiError.swift */,
|
||||
786D78E91D53C43E006B2CEA /* RequestError.swift */,
|
||||
);
|
||||
path = Enums;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -536,8 +540,9 @@
|
|||
"$(SRCROOT)/../Carthage/Build/iOS/RxSwift.framework",
|
||||
"$(SRCROOT)/../Carthage/Build/iOS/RxCocoa.framework",
|
||||
"$(SRCROOT)/../Carthage/Build/iOS/Alamofire.framework",
|
||||
"$(SRCROOT)/../Carthage/Build/iOS/Mapper.framework",
|
||||
"$(SRCROOT)/../Carthage/Build/iOS/RxAlamofire.framework",
|
||||
"$(SRCROOT)/../Carthage/Build/iOS/Reflection.framework",
|
||||
"$(SRCROOT)/../Carthage/Build/iOS/Convertible.framework",
|
||||
);
|
||||
name = "Carthage copy-frameworks";
|
||||
outputPaths = (
|
||||
|
|
@ -568,7 +573,7 @@
|
|||
786D78EC1D53C46E006B2CEA /* AlamofireManager+Extensions.swift in Sources */,
|
||||
78B0FC811C6B2CD500358B64 /* App.swift in Sources */,
|
||||
78B036491DA562C30021D5CC /* CGImage+Template.swift in Sources */,
|
||||
786D78EA1D53C43E006B2CEA /* ApiError.swift in Sources */,
|
||||
786D78EA1D53C43E006B2CEA /* RequestError.swift in Sources */,
|
||||
780D23461DA416F80084620D /* CGContext+Initializers.swift in Sources */,
|
||||
95B39A861D9D51250057BD54 /* String+Localization.swift in Sources */,
|
||||
78C36F7E1D801E3E00E7EBEA /* Double+Rounding.swift in Sources */,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// ApiError.swift
|
||||
// RequestError.swift
|
||||
// LeadKit
|
||||
//
|
||||
// Created by Ivan Smolin on 04/08/16.
|
||||
|
|
@ -17,6 +17,6 @@ public enum RequestError: Error {
|
|||
|
||||
case network(error: Error)
|
||||
case jsonSerialization(error: Error)
|
||||
case mapping(reason: String)
|
||||
|
||||
case mapping(error: Error)
|
||||
|
||||
}
|
||||
|
|
@ -8,9 +8,9 @@
|
|||
|
||||
import Alamofire
|
||||
import RxSwift
|
||||
import Mapper
|
||||
import RxAlamofire
|
||||
import struct RxCocoa.Reactive
|
||||
import Convertible
|
||||
|
||||
public extension Reactive where Base: DataRequest {
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ public extension Reactive where Base: DataRequest {
|
|||
|
||||
- returns: Observable with HTTP URL Response and target object
|
||||
*/
|
||||
func apiResponse<T: Mappable>() -> Observable<(HTTPURLResponse, T)> {
|
||||
func apiResponse<T: Convertible>(convertibleOptions: [ConvertibleOption] = []) -> Observable<(HTTPURLResponse, T)> {
|
||||
let mapperSerializer = DataResponseSerializer<T> { request, response, data, error in
|
||||
if let err = error {
|
||||
return .failure(RequestError.network(error: err))
|
||||
|
|
@ -30,12 +30,10 @@ public extension Reactive where Base: DataRequest {
|
|||
|
||||
switch result {
|
||||
case .success(let value):
|
||||
if let responseObject = value as? NSDictionary, let mappedObject = T.from(responseObject) {
|
||||
return .success(mappedObject)
|
||||
} else {
|
||||
let failureReason = "JSON could not be mapped into response object. JSON: \(value)"
|
||||
|
||||
return .failure(RequestError.mapping(reason: failureReason))
|
||||
do {
|
||||
return .success(try T.initializeWithJson(JsonValue(object: value), options: convertibleOptions))
|
||||
} catch let err {
|
||||
return .failure(RequestError.mapping(error: err))
|
||||
}
|
||||
case .failure(let error):
|
||||
return .failure(RequestError.jsonSerialization(error: error))
|
||||
|
|
|
|||
Loading…
Reference in New Issue