Skip to content

Commit

Permalink
Updated for latest version of Moya
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine van der Lee committed Jan 4, 2017
1 parent 7855511 commit 54ddaed
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 40 deletions.
5 changes: 5 additions & 0 deletions Example/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 2.2.0
- Updated for Moya 8.0.0
- Updated for ReactiveSwift 1.0.0
- Support for iOS 8 re-added

# 2.1
- Updated for Moya beta 6 & ReactiveSwift 4

Expand Down
8 changes: 6 additions & 2 deletions Example/Moya-SwiftyJSONMapper/ExampleAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ extension ExampleAPI: JSONMappableTargetType {
var task: Task {
return Task.request
}
var parameterEncoding: ParameterEncoding {
return URLEncoding.default
}

}

// Then add an additional request method
Expand All @@ -74,12 +78,12 @@ func requestType<T:ALSwiftyJSONAble>(target: ExampleAPI) -> SignalProducer<T, Mo
let jsonObject = try response.mapJSON()

guard let mappedObject = T(jsonData: JSON(jsonObject)) else {
throw Error.jsonMapping(response)
throw MoyaError.jsonMapping(response)
}

return SignalProducer(value: mappedObject)
} catch let error {
return SignalProducer(error: Moya.Error.underlying(error as NSError))
return SignalProducer(error: MoyaError.underlying(error as NSError))
}
})
}
Expand Down
52 changes: 26 additions & 26 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
PODS:
- Alamofire (4.2.0)
- Moya (8.0.0-beta.6):
- Moya/Core (= 8.0.0-beta.6)
- Moya-SwiftyJSONMapper (2.0):
- Moya-SwiftyJSONMapper/Core (= 2.0)
- Moya-SwiftyJSONMapper/Core (2.0):
- Moya (= 8.0.0-beta.6)
- Moya (8.0.0):
- Moya/Core (= 8.0.0)
- Moya-SwiftyJSONMapper (2.2.0):
- Moya-SwiftyJSONMapper/Core (= 2.2.0)
- Moya-SwiftyJSONMapper/Core (2.2.0):
- Moya (~> 8.0.0)
- SwiftyJSON
- Moya-SwiftyJSONMapper/ReactiveCocoa (2.0):
- Moya-SwiftyJSONMapper/ReactiveCocoa (2.2.0):
- Moya-SwiftyJSONMapper/Core
- Moya/ReactiveCocoa (= 8.0.0-beta.6)
- ReactiveSwift (= 1.0.0-alpha.4)
- Moya-SwiftyJSONMapper/RxSwift (2.0):
- Moya/ReactiveCocoa
- ReactiveSwift
- Moya-SwiftyJSONMapper/RxSwift (2.2.0):
- Moya-SwiftyJSONMapper/Core
- Moya/RxSwift (= 8.0.0-beta.6)
- Moya/Core (8.0.0-beta.6):
- Alamofire (~> 4.0)
- Result (~> 3.0)
- Moya/ReactiveCocoa (8.0.0-beta.6):
- Moya/RxSwift
- Moya/Core (8.0.0):
- Alamofire (~> 4.2.0)
- Result (~> 3.1.0)
- Moya/ReactiveCocoa (8.0.0):
- Moya/ReactiveSwift
- Moya/ReactiveSwift (8.0.0-beta.6):
- Moya/ReactiveSwift (8.0.0):
- Moya/Core
- ReactiveSwift (= 1.0.0-alpha.4)
- Moya/RxSwift (8.0.0-beta.6):
- ReactiveSwift (= 1.0.0)
- Moya/RxSwift (8.0.0):
- Moya/Core
- RxSwift (~> 3.0)
- ReactiveSwift (1.0.0-alpha.4):
- Result (~> 3.0)
- RxSwift (~> 3.1.0)
- ReactiveSwift (1.0.0):
- Result (~> 3.1)
- Result (3.1.0)
- RxSwift (3.0.1)
- RxSwift (3.1.0)
- SwiftyJSON (3.1.3)

DEPENDENCIES:
Expand All @@ -42,11 +42,11 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Alamofire: aa2e09d871c9160ac53c90e83c68064a94e3dfbe
Moya: a29e2503a0c5067d462ba2f07cc6b6b1f3fc172d
Moya-SwiftyJSONMapper: fadd6dde9ee764cc3cb57bd65c6c4ad1216064e2
ReactiveSwift: 3fa49d2db97609ea700cd2b8f1bfbdd162024f97
Moya: 850a166ab8241bd1c1cea6dbe012e3a2ad62944a
Moya-SwiftyJSONMapper: b1d46deb65198c495b50fe2603475503349a1d95
ReactiveSwift: f391724ee318a2cfd3e37dfb041cd49ecf4e7869
Result: 4e3ed5995ed94d0cd6a09be9a431fce3f3624bbf
RxSwift: af5680055c4ad04480189c52d28385b1029493a6
RxSwift: 83ff553e7593fdfdcb2562933a64c0284dffdadc
SwiftyJSON: 38a8ea2006779c0fc4c310cb2ee8195327740faf

PODFILE CHECKSUM: bdad710955f55fa2cf7ec1dd14ded585db6b0dc3
Expand Down
12 changes: 6 additions & 6 deletions Moya-SwiftyJSONMapper.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "Moya-SwiftyJSONMapper"
s.version = "2.1"
s.version = "2.2.0"
s.summary = "Map objects through SwiftyJSON in combination with Moya"
s.description = <<-EOS
[SwiftyJSON](https://github.com/SwiftyJSON/SwiftyJSON) bindings for
Expand All @@ -23,7 +23,7 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/AvdLee/Moya-SwiftyJSONMapper.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/twannl'

s.ios.deployment_target = '9.0'
s.ios.deployment_target = '8.0'
s.tvos.deployment_target = '9.0'
s.watchos.deployment_target = '3.0'
s.requires_arc = true
Expand All @@ -32,21 +32,21 @@ Pod::Spec.new do |s|

s.subspec "Core" do |ss|
ss.source_files = "Source/*.swift"
ss.dependency "Moya", "8.0.0-beta.6"
ss.dependency "Moya", "~> 8.0.0"
ss.dependency "SwiftyJSON"
ss.framework = "Foundation"
end

s.subspec "RxSwift" do |ss|
ss.source_files = "Source/RxSwift/*.swift"
ss.dependency "Moya/RxSwift", "8.0.0-beta.6"
ss.dependency "Moya/RxSwift"
ss.dependency "Moya-SwiftyJSONMapper/Core"
end

s.subspec "ReactiveCocoa" do |ss|
ss.source_files = "Source/ReactiveCocoa/*.swift"
ss.dependency "Moya/ReactiveCocoa", "8.0.0-beta.6"
ss.dependency "Moya/ReactiveCocoa"
ss.dependency "Moya-SwiftyJSONMapper/Core"
ss.dependency "ReactiveSwift", "1.0.0-alpha.4"
ss.dependency "ReactiveSwift"
end
end
10 changes: 5 additions & 5 deletions Source/ReactiveCocoa/SignalProducer+SwiftyJSONMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ import Moya
import SwiftyJSON

/// Extension for processing Responses into Mappable objects through ObjectMapper
extension SignalProducerProtocol where Value == Moya.Response, Error == Moya.Error {
extension SignalProducerProtocol where Value == Moya.Response, Error == MoyaError {

/// Maps data received from the signal into an object which implements the ALSwiftyJSONAble protocol.
/// If the conversion fails, the signal errors.
public func map<T: ALSwiftyJSONAble>(to type: T.Type) -> SignalProducer<T, Moya.Error> {
public func map<T: ALSwiftyJSONAble>(to type: T.Type) -> SignalProducer<T, MoyaError> {
return producer.flatMap(.latest) { response -> SignalProducer<T, Moya.Error> in
return unwrapThrowable { try response.map(to: type) }
}
}

/// Maps data received from the signal into an array of objects which implement the ALSwiftyJSONAble protocol.
/// If the conversion fails, the signal errors.
public func map<T: ALSwiftyJSONAble>(to type: [T.Type]) -> SignalProducer<[T], Moya.Error> {
public func map<T: ALSwiftyJSONAble>(to type: [T.Type]) -> SignalProducer<[T], MoyaError> {
return producer.flatMap(.latest) { response -> SignalProducer<[T], Moya.Error> in
return unwrapThrowable { try response.map(to: type) }
}
}
}

/// Maps throwable to SignalProducer
private func unwrapThrowable<T>(throwable: () throws -> T) -> SignalProducer<T, Moya.Error> {
private func unwrapThrowable<T>(throwable: () throws -> T) -> SignalProducer<T, MoyaError> {
do {
return SignalProducer(value: try throwable())
} catch {
return SignalProducer(error: error as! Moya.Error)
return SignalProducer(error: error as! MoyaError)
}
}
2 changes: 1 addition & 1 deletion Source/Response+SwiftyJSONMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public extension Response {
let jsonObject = try mapJSON()

guard let mappedObject = T(jsonData: JSON(jsonObject)) else {
throw Error.jsonMapping(self)
throw MoyaError.jsonMapping(self)
}

return mappedObject
Expand Down

0 comments on commit 54ddaed

Please sign in to comment.