-
Notifications
You must be signed in to change notification settings - Fork 3
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 #47 from futuredapp/feature/adapter-removal-rewrite
Adapter removal rewrite
- Loading branch information
Showing
38 changed files
with
934 additions
and
1,078 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,29 @@ | ||
Pod::Spec.new do |s| | ||
s.name = "FTAPIKit" | ||
s.version = "0.6.0" | ||
s.summary = "Declarative, generic REST API framework using URLSession and Codable" | ||
s.description = <<-DESC | ||
Protocol-oriented REST API library for communication with REST API. | ||
APIEndpoint protocols allow description of the API access points | ||
and the requests/responses codable types. APIAdapter handles execution | ||
of calls to this endpoints. | ||
s.name = "FTAPIKit" | ||
s.version = "1.0.0" | ||
s.summary = "Declarative, generic and protocol-orented REST API framework using URLSession and Codable" | ||
s.description = <<-DESC | ||
Protocol-oriented framework for communication with REST APIs. | ||
Endpoint protocols describe the API resource access points | ||
and the requests/responses codable types. Server protocol describes web services | ||
and enables the user to call endoints in a type-safe manner. | ||
DESC | ||
s.homepage = "https://github.com/futuredapp/FTAPIKit" | ||
s.license = { :type => "MIT", :file => "LICENSE" } | ||
s.author = { "Matěj Kašpar Jirásek" => "[email protected]" } | ||
s.social_media_url = "https://twitter.com/Futuredapps" | ||
s.default_subspec = 'Core' | ||
s.swift_version = "5.0" | ||
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.source = { :git => "https://github.com/futuredapp/FTAPIKit.git", :tag => s.version.to_s } | ||
s.homepage = "https://github.com/futuredapp/FTAPIKit" | ||
s.license = { type: "MIT", file: "LICENSE" } | ||
s.author = { "Matěj Kašpar Jirásek": "[email protected]" } | ||
s.social_media_url = "https://twitter.com/Futuredapps" | ||
|
||
s.subspec 'Core' do |ss| | ||
ss.source_files = "Sources/FTAPIKit/*" | ||
ss.framework = "Foundation" | ||
ss.ios.framework = "MobileCoreServices" | ||
ss.tvos.framework = "MobileCoreServices" | ||
ss.watchos.framework = "MobileCoreServices" | ||
end | ||
s.source = { git: "https://github.com/futuredapp/FTAPIKit.git", tag: s.version.to_s } | ||
s.source_files = "Sources/FTAPIKit/*" | ||
|
||
s.subspec 'PromiseKit' do |ss| | ||
ss.source_files = Dir['Sources/FTAPIKitPromiseKit/*'] | ||
ss.dependency 'PromiseKit', '~> 6.0' | ||
ss.dependency 'FTAPIKit/Core' | ||
end | ||
s.framework = "Foundation" | ||
s.ios.framework = "MobileCoreServices" | ||
s.tvos.framework = "MobileCoreServices" | ||
s.watchos.framework = "MobileCoreServices" | ||
|
||
s.swift_version = "5.0" | ||
s.ios.deployment_target = "8.0" | ||
s.osx.deployment_target = "10.10" | ||
s.watchos.deployment_target = "2.0" | ||
s.tvos.deployment_target = "9.0" | ||
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,39 @@ | ||
import Foundation | ||
|
||
/// Standard API error returned in `APIResult` when no custom error | ||
/// was parsed in the `APIAdapter` first and the response from server | ||
/// was invalid. | ||
public enum APIErrorStandard: APIError { | ||
/// Error raised by URLSession. | ||
case connection(URLError) | ||
case encoding(EncodingError) | ||
case decoding(DecodingError) | ||
/// Status code error when the response status code | ||
/// is larger or equal to 500 and less than 600. | ||
case server(Int, URLResponse, Data?) | ||
/// Status code error when the response status code | ||
/// is larger or equal to 400 and less than 500. | ||
case client(Int, URLResponse, Data?) | ||
case unhandled(data: Data?, response: URLResponse?, error: Error?) | ||
|
||
public init?(data: Data?, response: URLResponse?, error: Error?, decoding: Decoding) { | ||
switch (data, response as? HTTPURLResponse, error) { | ||
case let (_, _, error as URLError): | ||
self = .connection(error) | ||
case let (_, _, error as EncodingError): | ||
self = .encoding(error) | ||
case let (_, _, error as DecodingError): | ||
self = .decoding(error) | ||
case let (data, response?, nil) where 400..<500 ~= response.statusCode: | ||
self = .client(response.statusCode, response, data) | ||
case let (data, response?, nil) where 500..<600 ~= response.statusCode: | ||
self = .server(response.statusCode, response, data) | ||
case (_, .some, nil), (.some, nil, nil): | ||
return nil | ||
default: | ||
self = .unhandled(data: data, response: response, error: error) | ||
} | ||
} | ||
|
||
public static var unhandled: Standard = .unhandled(data: nil, response: nil, error: nil) | ||
} |
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,42 +1,9 @@ | ||
import Foundation | ||
|
||
public protocol APIError: Error { | ||
init?(data: Data?, response: URLResponse?, error: Error?, decoder: JSONDecoder) | ||
} | ||
typealias Standard = APIErrorStandard | ||
|
||
/// Standard API error returned in `APIResult` when no custom error | ||
/// was parsed in the `APIAdapter` first and the response from server | ||
/// was invalid. | ||
public enum StandardAPIError: APIError { | ||
/// Error raised by NSURLSession corresponding to NSURLErrorCancelled at | ||
/// domain NSURLErrorDomain. | ||
case cancelled | ||
/// Connection error when no response and data was received. | ||
case connection(Error) | ||
/// Status code error when the response status code | ||
/// is larger or equal to 500 and less than 600. | ||
case server(Int, Data?) | ||
/// Status code error when the response status code | ||
/// is larger or equal to 400 and less than 500. | ||
case client(Int, Data?) | ||
/// Multipart body part error, when the stream for the part | ||
/// or the temporary request body stream cannot be opened. | ||
case multipartStreamCannotBeOpened | ||
init?(data: Data?, response: URLResponse?, error: Error?, decoding: Decoding) | ||
|
||
public init?(data: Data?, response: URLResponse?, error: Error?, decoder: JSONDecoder) { | ||
switch (data, response as? HTTPURLResponse, error) { | ||
case let (_, _, error as NSError) where error.domain == NSURLErrorDomain && error.code == NSURLErrorCancelled: | ||
self = .cancelled | ||
case let (_, _, error?): | ||
self = .connection(error) | ||
case let (data, response?, nil) where 400..<500 ~= response.statusCode: | ||
self = .client(response.statusCode, data) | ||
case let (data, response?, nil) where 500..<600 ~= response.statusCode: | ||
self = .server(response.statusCode, data) | ||
case (_, .some, nil), (.some, nil, nil): | ||
return nil | ||
case (nil, nil, nil): | ||
fatalError("No response, data or error was returned from URLSession") | ||
} | ||
} | ||
static var unhandled: Self { get } | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
Oops, something went wrong.