-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathConfigManager.swift
More file actions
131 lines (102 loc) · 3.65 KB
/
ConfigManager.swift
File metadata and controls
131 lines (102 loc) · 3.65 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// ConfigManager.swift
// safesafe
//
// Created by Lukasz szyszkowski on 24/04/2020.
// Copyright © 2020 Lukasz szyszkowski. All rights reserved.
//
import Foundation
final class ConfigManager {
#if DEV
static private let configPlistName = "Config-dev"
#elseif STAGE || STAGE_SCREENCAST || STAGE_DEBUG
static private let configPlistName = "Config-stage"
#elseif LIVE
static private let configPlistName = "Config-live"
#elseif LIVE_ADHOC
static private let configPlistName = "Config-live"
#elseif LIVE_DEBUG
static private let configPlistName = "Config-live"
#endif
static let `default` = ConfigManager(plistName: configPlistName)
private enum Key {
// PWA Settings
static let pwa = "PWA" // Dictionary
static let host = "HOST" // String
static let scheme = "SCHEME" // String
// Exposure Notification
static let exposureNotification = "EXPOSURE_NOTIFICATION" // Dictionary
static let enGatBaseURL = "EN_GAT_BASE_URL" // String
static let enUdkBaseURL = "EN_UDK_BASE_URL" // String
static let enStorageURL = "EN_STORAGE_URL" // String
// Base Url
static let baseURL = "BASE_URL"
// Free COVID Test
static let freeTest = "FREE_TEST"
static let freetTestBaseURL = "BASE_URL"
}
private let settings: [String: Any]
init(plistName: String) {
guard
let path = Bundle.main.path(forResource: plistName, ofType: "plist"),
let plist = NSDictionary(contentsOfFile: path) as? [String: Any]
else {
Fatal.execute("Can't find \(plistName).plist")
}
settings = plist
}
private func value<T>(for key: String, dictionary: [String: Any]) -> T {
guard let dictValue = dictionary[key] as? T else {
Fatal.execute("Can't read value [\(T.self)] for \(key)")
}
return dictValue
}
}
// PWA
extension ConfigManager {
private var pwaSettings: [String: Any] {
guard let dictionary = settings[Key.pwa] as? [String: Any] else {
Fatal.execute("Can't read \(Key.pwa) from plist")
}
return dictionary
}
var pwaHost: String {
return value(for: Key.host, dictionary: pwaSettings)
}
var pwaScheme: String {
return value(for: Key.scheme, dictionary: pwaSettings)
}
}
extension ConfigManager {
// Exposure Notification
private var enSettings: [String: Any] {
guard let dictionary = settings[Key.exposureNotification] as? [String: Any] else {
Fatal.execute("Can't read \(Key.exposureNotification) from plist")
}
return dictionary
}
private var freeTestSettings: [String: Any] {
guard let dictionary = settings[Key.freeTest] as? [String: Any] else {
Fatal.execute("Can't read \(Key.freeTest) from plist")
}
return dictionary
}
var enGatBaseURL: String {
return value(for: Key.enGatBaseURL, dictionary: enSettings)
}
var enUdkBaseURL: String {
return value(for: Key.enUdkBaseURL, dictionary: enSettings)
}
var enStorageURL: String {
return value(for: Key.enStorageURL, dictionary: enSettings)
}
var baseURL: String {
guard let baseURL = settings[Key.baseURL] as? String else {
Fatal.execute("Can't read \(Key.baseURL) from plist")
}
return baseURL
}
var freeTestBaseURL: String {
return value(for: Key.freetTestBaseURL, dictionary: freeTestSettings)
}
}