Skip to content

Instantly share code, notes, and snippets.

@poksi592
Last active May 15, 2018 13:04
Show Gist options
  • Save poksi592/dcd5cf880e99f8700f4ccdf6d7eb0eae to your computer and use it in GitHub Desktop.
Save poksi592/dcd5cf880e99f8700f4ccdf6d7eb0eae to your computer and use it in GitHub Desktop.
let nonCompliantModule = NonConformingModule()
nonCompliantModule.login(username: "myUsername",
password: "myPassword",
completion: { (bearerToken, error) in
print(String(describing: bearerToken))
})
class NonConformingModule {
func login(username: String,
password: String,
completion: ((String?, Error?) -> Void)?) {
let service = NetworkService()
service.post(scheme: "tandem",
host: "login",
path: "/login",
parameters: ["username": "myUsername",
"password": "myPassword"]) { (response, urlResponse, error) in
// We are not going to check errors and URL response status codes, just a shortest path.
var networkError: ResponseError? = nil
if let error = error {
networkError = ResponseError(error: error, response: urlResponse)
}
let token = response?["bearerToken"] as? String
completion?(token, networkError)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment