mirror of
https://github.com/AU-COVIDSafe/mobile-ios.git
synced 2025-04-19 13:05:21 +00:00
COVIDSafe code from version 2.2 (#42)
This commit is contained in:
parent
9e6e4604ef
commit
f14aa60482
67 changed files with 3645 additions and 464 deletions
58
CovidSafe/API/ChangePostcodeAPI.swift
Normal file
58
CovidSafe/API/ChangePostcodeAPI.swift
Normal file
|
@ -0,0 +1,58 @@
|
|||
//
|
||||
// ChangePostcodeAPI.swift
|
||||
// CovidSafe
|
||||
//
|
||||
// Copyright © 2020 Australian Government. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Alamofire
|
||||
|
||||
class ChangePostcodeAPI: CovidSafeAuthenticatedAPI {
|
||||
|
||||
static func changePostcode(newPostcode: String,
|
||||
completion: @escaping (CovidSafeAPIError?) -> Void) {
|
||||
|
||||
guard let apiHost = PlistHelper.getvalueFromInfoPlist(withKey: "API_Host", plistName: "CovidSafe-config") else {
|
||||
return
|
||||
}
|
||||
|
||||
guard let headers = try? authenticatedHeaders() else {
|
||||
completion(.TokenExpiredError)
|
||||
return
|
||||
}
|
||||
|
||||
let params = [
|
||||
"postcode": newPostcode,
|
||||
]
|
||||
CovidNetworking.shared.session.request("\(apiHost)/device",
|
||||
method: .post,
|
||||
parameters: params,
|
||||
encoding: JSONEncoding.default,
|
||||
headers: headers,
|
||||
interceptor: CovidRequestRetrier(retries:3)).validate().responseDecodable(of: DeviceResponse.self) { (response) in
|
||||
switch response.result {
|
||||
case .success:
|
||||
completion(nil)
|
||||
case .failure(_):
|
||||
guard let statusCode = response.response?.statusCode else {
|
||||
completion(.UnknownError)
|
||||
return
|
||||
}
|
||||
if (statusCode >= 400 && statusCode < 500) {
|
||||
completion(.RequestError)
|
||||
return
|
||||
}
|
||||
completion(.ServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct DeviceResponse: Decodable {
|
||||
let message: String?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case message
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue