Last active
August 13, 2016 10:57
-
-
Save feighter09/2c9394fbc146ffc923ebcaf5292cbf5f to your computer and use it in GitHub Desktop.
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
import Alamofire | |
protocol FetchUserType: NetworkRequest { | |
associatedtype ResponseType = User | |
func perform(username: String, callback: (User?, ErrorType?) -> Void) | |
} | |
final class FetchUser: FetchUserType { | |
typealias ResponseType = User | |
var endpoint: String { return "post" } | |
var method: Alamofire.Method { return .POST } | |
var params: [String : AnyObject] { return ["param": username] } | |
private var username = "" | |
func perform(username: String, callback: (User?, ErrorType?) -> Void) | |
{ | |
self.username = username | |
let parsedCallback = { (data: NSData?, error: ErrorType?) in | |
callback(data.flatMap(self.responseHandler), error) | |
} | |
networkClient.makeRequest(self, callback: parsedCallback) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment