This repository has been archived by the owner on Nov 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Otbivnoe/update-alamofire-v5
Update the project according to Alamofire 5
- Loading branch information
Showing
12 changed files
with
128 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
github "Alamofire/Alamofire" | ||
github "Alamofire/Alamofire" "5.0.0-rc.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
github "Alamofire/Alamofire" "4.8.1" | ||
github "Alamofire/Alamofire" "5.0.0-rc.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,23 +9,23 @@ | |
Pod::Spec.new do |s| | ||
|
||
s.name = "CodableAlamofire" | ||
s.version = "1.1.2" | ||
s.version = "1.2.0" | ||
s.summary = "An extension for Alamofire that converts JSON data into Decodable Objects." | ||
s.homepage = "https://github.com/Otbivnoe/CodableAlamofire" | ||
s.license = { :type => "MIT", :file => "LICENSE" } | ||
s.author = { "Nikita Ermolenko" => "[email protected]" } | ||
s.social_media_url = "https://twitter.com/iOtbivnoe" | ||
|
||
s.ios.deployment_target = '8.0' | ||
s.osx.deployment_target = '10.10' | ||
s.watchos.deployment_target = '2.0' | ||
s.tvos.deployment_target = '9.0' | ||
s.ios.deployment_target = '10.0' | ||
s.osx.deployment_target = '10.12' | ||
s.watchos.deployment_target = '3.0' | ||
s.tvos.deployment_target = '10.0' | ||
|
||
s.source = { :git => "https://github.com/Otbivnoe/CodableAlamofire.git", :tag => "#{s.version}" } | ||
s.source_files = "Sources/**/*.{h,swift}" | ||
s.swift_versions = ['4.0', '5.0', '5.1'] | ||
|
||
s.requires_arc = true | ||
s.dependency 'Alamofire', '~> 4.0' | ||
s.dependency 'Alamofire', '~> 5.0.0-rc.3' | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// DataKeyPathSerializer.swift | ||
// CodableAlamofire | ||
// | ||
// Created by Nikita Ermolenko on 03/12/2019. | ||
// | ||
|
||
import Foundation | ||
import Alamofire | ||
|
||
internal final class DataKeyPathSerializer<SerializedObject: Decodable>: DataResponseSerializerProtocol { | ||
|
||
private let keyPath: String? | ||
private let decoder: JSONDecoder | ||
|
||
init(keyPath: String?, decoder: JSONDecoder = JSONDecoder()) { | ||
self.keyPath = keyPath | ||
self.decoder = decoder | ||
} | ||
|
||
func serialize(request: URLRequest?, response: HTTPURLResponse?, data: Data?, error: Error?) throws -> SerializedObject { | ||
if let error = error { | ||
throw error | ||
} | ||
|
||
if let keyPath = self.keyPath { | ||
if keyPath.isEmpty { | ||
throw AFError.responseSerializationFailed(reason: .decodingFailed(error: AlamofireDecodableError.emptyKeyPath)) | ||
} | ||
|
||
let json = try JSONResponseSerializer().serialize(request: nil, response: response, data: data, error: nil) | ||
if let nestedJson = (json as AnyObject).value(forKeyPath: keyPath) { | ||
guard JSONSerialization.isValidJSONObject(nestedJson) else { | ||
throw AFError.responseSerializationFailed(reason: .decodingFailed(error: AlamofireDecodableError.invalidJSON)) | ||
} | ||
let data = try JSONSerialization.data(withJSONObject: nestedJson) | ||
let object = try decoder.decode(SerializedObject.self, from: data) | ||
return object | ||
} | ||
else { | ||
throw AFError.responseSerializationFailed(reason: .decodingFailed(error: AlamofireDecodableError.invalidKeyPath)) | ||
} | ||
} else { | ||
let data = try DataResponseSerializer().serialize(request: nil, response: response, data: data, error: nil) | ||
let object = try self.decoder.decode(SerializedObject.self, from: data) | ||
return object | ||
} | ||
} | ||
} |
Oops, something went wrong.