-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathPermissionsRequest.swift
More file actions
66 lines (51 loc) · 1.88 KB
/
Copy pathPermissionsRequest.swift
File metadata and controls
66 lines (51 loc) · 1.88 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
58
59
60
61
62
63
64
65
66
//
// PermissionsRequest.swift
// NativeAppTemplate
//
import Foundation
struct PermissionsResponse: Sendable {
var iosAppVersion: Int
var shouldUpdatePrivacy: Bool
var shouldUpdateTerms: Bool
var maximumNameLength: Int
var shopLimitCount: Int
}
struct PermissionsRequest: Request {
typealias Response = PermissionsResponse
// MARK: - Properties
var method: HTTPMethod {
.GET
}
var path: String {
"/shopkeeper/permissions"
}
var additionalHeaders: [String: String] = [:]
var body: Data? {
nil
}
// MARK: - Internal
func handle(response: Data) throws -> Response {
let json = try JSONSerialization.jsonObject(with: response)
let doc = JSONAPIDocument(json)
guard let iosAppVersion = doc.meta["ios_app_version"] as? Int else {
throw NativeAppTemplateAPIError.responseMissingRequiredMeta(field: "ios_app_version")
}
guard let shouldUpdatePrivacy = doc.meta["should_update_privacy"] as? Bool else {
throw NativeAppTemplateAPIError.responseMissingRequiredMeta(field: "should_update_privacy")
}
guard let shouldUpdateTerms = doc.meta["should_update_terms"] as? Bool else {
throw NativeAppTemplateAPIError.responseMissingRequiredMeta(field: "should_update_terms")
}
let maximumNameLength = doc.meta["maximum_name_length"] as? Int ?? 100
guard let shopLimitCount = doc.meta["shop_limit_count"] as? Int else {
throw NativeAppTemplateAPIError.responseMissingRequiredMeta(field: "shop_limit_count")
}
return PermissionsResponse(
iosAppVersion: iosAppVersion,
shouldUpdatePrivacy: shouldUpdatePrivacy,
shouldUpdateTerms: shouldUpdateTerms,
maximumNameLength: maximumNameLength,
shopLimitCount: shopLimitCount
)
}
}