Skip to content

Instantly share code, notes, and snippets.

@jpibarra1130
Created March 18, 2015 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpibarra1130/f163e0e07a3417983059 to your computer and use it in GitHub Desktop.
Save jpibarra1130/f163e0e07a3417983059 to your computer and use it in GitHub Desktop.
Sample request model that can be converted to a MutableURLRequest
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