Skip to content

Instantly share code, notes, and snippets.

@aalemi97
Last active October 14, 2020 10:10
Show Gist options
  • Save aalemi97/7d1f137aa3c3fbd09a47ef94f6b4c983 to your computer and use it in GitHub Desktop.
Save aalemi97/7d1f137aa3c3fbd09a47ef94f6b4c983 to your computer and use it in GitHub Desktop.
import Alamofire
class NetworkManager {
static let shared: NetworkManager = {
return NetworkManager()
}()
typealias completionHandler = ((Result<Data, CustomError>) -> Void)
var request: Alamofire.Request?
let retryLimit = 3
let authorize = "https://api.petfinder.com/v2/oauth2/token"
func authorize(parameters: [String: Any]?, completion: @escaping completionHandler) {
request?.cancel()
request = AF.request(authorize, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseJSON { response in
if let data = response.data {
completion(.success(data))
} else {
completion(.failure(.unavailableServer))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment