mirror of
https://github.com/AU-COVIDSafe/mobile-ios.git
synced 2025-06-07 21:15:18 +00:00
COVIDSafe code from version 1.14 (#27)
This commit is contained in:
parent
3ea83834f5
commit
cf93ea43c0
29 changed files with 370 additions and 141 deletions
|
@ -7,25 +7,20 @@
|
|||
|
||||
import Foundation
|
||||
import Alamofire
|
||||
import KeychainSwift
|
||||
|
||||
class GetTempIdAPI {
|
||||
class GetTempIdAPI: CovidSafeAuthenticatedAPI {
|
||||
|
||||
private static let apiVersion = 2
|
||||
|
||||
static func getTempId(completion: @escaping (String?, Int?, Swift.Error?) -> Void) {
|
||||
let keychain = KeychainSwift()
|
||||
static func getTempId(completion: @escaping (String?, Int?, Swift.Error?, CovidSafeAPIError?) -> Void) {
|
||||
guard let apiHost = PlistHelper.getvalueFromInfoPlist(withKey: "API_Host", plistName: "CovidSafe-config") else {
|
||||
return
|
||||
}
|
||||
|
||||
guard let token = keychain.get("JWT_TOKEN") else {
|
||||
completion(nil, nil, nil)
|
||||
guard let headers = try? authenticatedHeaders() else {
|
||||
completion(nil, nil, nil, .TokenExpiredError)
|
||||
return
|
||||
}
|
||||
let headers: HTTPHeaders = [
|
||||
"Authorization": "Bearer \(token)"
|
||||
]
|
||||
let params = [
|
||||
"version" : apiVersion
|
||||
]
|
||||
|
@ -37,9 +32,17 @@ class GetTempIdAPI {
|
|||
switch response.result {
|
||||
case .success:
|
||||
guard let tempIdResponse = response.value else { return }
|
||||
completion(tempIdResponse.tempId, tempIdResponse.expiryTime, nil)
|
||||
completion(tempIdResponse.tempId, tempIdResponse.expiryTime, nil, nil)
|
||||
case let .failure(error):
|
||||
completion(nil, nil, error)
|
||||
guard let statusCode = response.response?.statusCode else {
|
||||
completion(nil, nil, error, .UnknownError)
|
||||
return
|
||||
}
|
||||
if statusCode == 401, let respData = response.data {
|
||||
completion(nil, nil, error, processUnauthorizedError(respData))
|
||||
return
|
||||
}
|
||||
completion(nil, nil, error, .ServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue