NetworkManager.swift
1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// NetworkManager.swift
// InterQR-Internship
//
// Created by Дмитрий Тимофеев on 25.06.2022.
//
import Foundation
import Alamofire
struct RequestModel: Codable {
var deviceUUID: String
var manufacturer: String
var model: String
var platform: String
var osVersion: String
var appVersion: String
}
class NetworkManager {
typealias WebServiceResponse = (RequestModel) -> Void
typealias FailedHandler = (Error) -> Void
func authorizationRequest(_ url: URL, model: RequestModel, completion: @escaping WebServiceResponse, fail: @escaping FailedHandler) {
let params = ["device_uuid": model.deviceUUID,
"manufacturer": model.manufacturer,
"model": model.model,
"platform": model.platform,
"os_version": model.osVersion,
"app_version": model.appVersion] as [String: Any]
AF.request(url, method: .post, parameters: params, encoding: JSONEncoding.default).responseDecodable(of: RequestModel.self ) { response in
if let error = response.error {
fail(error)
} else {
if let res = response.value {
completion(res)
}
}
}
// AF.request(url).response { response in
// guard let data = response.data else { return }
// do {
// let decoder = JSONDecoder()
// let json = try decoder.decode(Initialize.self, from: data)
//
// DispatchQueue.main.async {
// completion(json)
// }
// }
// catch {
// print("❌\(error)❌")
// }
// }
}
}