Created
March 18, 2015 13:17
-
-
Save jpibarra1130/f163e0e07a3417983059 to your computer and use it in GitHub Desktop.
Sample request model that can be converted to a MutableURLRequest
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
class Request { | |
var url: String | |
var requestType: RequestType | |
var body: NSData? | |
var headers: Dictionary<String, String>? | |
init(url: String, requestType: RequestType, body: NSData?, headers: Dictionary<String, String>?) { | |
self.url = url | |
self.requestType = requestType | |
if body != nil { | |
self.body = body! | |
} | |
if headers != nil { | |
self.headers = headers! | |
} | |
} | |
func toMutableURLRequest() -> NSMutableURLRequest { | |
println("Setting up URL: \(url)") | |
var request = NSMutableURLRequest(URL: NSURL(string: url)!) | |
println("Setting up request type: \(requestType.rawValue)") | |
request.HTTPMethod = requestType.rawValue | |
request.HTTPBody = body | |
if let newHeaders = headers { | |
for (key, value) in newHeaders { | |
request.addValue(value, forHTTPHeaderField: key) | |
} | |
} | |
return request | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment