Skip to content

Commit

Permalink
Release v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Daltron committed Oct 11, 2017
1 parent f494a0e commit cbf265d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion AlamoRecord.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = 'AlamoRecord'
s.version = '1.1.0'
s.version = '1.1.1'
s.summary = 'An elegant Alamofire wrapper inspired by ActiveRecord.'
s.description = <<-DESC
AlamoRecord is a powerful yet simple framework that eliminates the often complex networking layer that exists between your networking framework and your application. AlamoRecord uses the power of AlamoFire, AlamofireObjectMapper and the concepts behind the ActiveRecord pattern to create a networking layer that makes interacting with your API easier than ever.
Expand Down
50 changes: 31 additions & 19 deletions AlamoRecord/Classes/RequestManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,49 @@ open class RequestManager<U: URLProtocol, E: AlamoRecordError>: NSObject {
}

/**
Makes a request to the given URL
- parameter method: The HTTP method
- parameter url: The URL that conforms to URLProtocol
- parameter parameters: The parameters. `nil` by default
- parameter encoding: The parameter encoding. `URLEncoding.default` by default
- parameter headers: The HTTP headers. `nil` by default
- parameter success: The block to execute if the request succeeds
- parameter failure: The block to execute if the request fails
Makes a request to the given URL
- parameter method: The HTTP method
- parameter url: The URL that conforms to URLProtocol
- parameter parameters: The parameters. `nil` by default
- parameter encoding: The parameter encoding. `URLEncoding.default` by default
- parameter headers: The HTTP headers. `nil` by default
- parameter emptyBody: Wether or not the response will have an empty body. `false` by default
- parameter success: The block to execute if the request succeeds
- parameter failure: The block to execute if the request fails
*/
@discardableResult
open func makeRequest(_ method: Alamofire.HTTPMethod,
url: U,
parameters: Parameters? = nil,
encoding: ParameterEncoding = URLEncoding.default,
headers: HTTPHeaders? = nil,
success: (() -> Void)?,
failure: ((E) -> Void)?) -> DataRequest {
url: U,
parameters: Parameters? = nil,
encoding: ParameterEncoding = URLEncoding.default,
headers: HTTPHeaders? = nil,
emptyBody: Bool = false,
success: (() -> Void)?,
failure: ((E) -> Void)?) -> DataRequest {

return makeRequest(method,
url: url,
parameters: parameters,
encoding: encoding,
headers: headers)
.responseJSON { response in

Logger.logFinishedResponse(response: response)
switch response.result {
case .success:

guard emptyBody else {
switch response.result {
case .success:
self.onSuccess(success: success, response: response)
case .failure(let error):
self.onFailure(error: error, response: response, failure: failure)
}
return
}

if response.response!.statusCode >= 200 && response.response!.statusCode <= 299 {
self.onSuccess(success: success, response: response)
case .failure(let error):
self.onFailure(error: error, response: response, failure: failure)
} else {
self.onFailure(error: response.error!, response: response, failure: failure)
}
}

Expand Down

0 comments on commit cbf265d

Please sign in to comment.