Last active
October 14, 2020 10:10
-
-
Save aalemi97/7d1f137aa3c3fbd09a47ef94f6b4c983 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 | |
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