Last active
May 22, 2020 15:14
-
-
Save catalinaturlea/bc7d8e4b05f5a438e237 to your computer and use it in GitHub Desktop.
Request wrapper
This file contains hidden or 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
| public class AlamofireWrapper: NSObject { | |
| // MARK: - Request Methods | |
| /** | |
| Creates a request using the shared manager instance for the specified method, URL string, parameters, and | |
| parameter encoding. | |
| - parameter method: The HTTP method. | |
| - parameter URLString: The URL string. | |
| - parameter parameters: The parameters. | |
| - parameter encoding: The parameter encoding. `.URL` by default. | |
| - parameter headers: The HTTP headers. | |
| - parameter success: The block to be executed in case the request succeeds. | |
| - parameter failure: The block to be executed in case the request fails. | |
| */ | |
| public class func performJSONRequest( | |
| method: RequestMethod, | |
| URLString: String, | |
| parameters: [String: NSObject]?, | |
| encoding: RequestParameterEncoding = .URL, | |
| headers: [String: String]?, | |
| success: (request: NSURLRequest?, response: NSHTTPURLResponse?, json: [NSObject: AnyObject]?) -> (), | |
| failure: (request: NSURLRequest?, response: NSHTTPURLResponse?, error: NSError?) -> ()) { | |
| let method = translateMethod(method) | |
| let encoding = translateEncoding(encoding) | |
| let request = Alamofire.request(method, URLString, parameters: parameters, encoding: encoding, headers: headers) | |
| request.responseJSON { (response) -> Void in | |
| parseResponse(response, success: success, failure: failure) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment