Skip to content

Commit 965eca4

Browse files
dabearps2
authored andcommitted
Support US, NON_US and Custom ShareServer during init (#10)
* Support US, NON_US and Custom ShareServer during initialization * remove unnecessary optional and unwrapping * remove trailing whitespaces as requested
1 parent 7c23abc commit 965eca4

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

ShareClient/ShareClient.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public enum ShareError: Error {
2626
case dateError
2727
}
2828

29+
public enum ShareServer {
30+
case US
31+
case Non_US
32+
case Custom(String)
33+
}
34+
2935
// From the Dexcom Share iOS app, via @bewest and @shanselman:
3036
// https://github.com/bewest/share2nightscout-bridge
3137
private let dexcomUserAgent = "Dexcom Share/3.0.2.11 CFNetwork/711.2.23 Darwin/14.0.0"
@@ -70,11 +76,20 @@ public class ShareClient {
7076
public let username: String
7177
public let password: String
7278

79+
private let shareServer:String
7380
private var token: String?
7481

75-
public init(username: String, password: String) {
82+
public init(username: String, password: String, shareServer:ShareServer=ShareServer.US) {
7683
self.username = username
7784
self.password = password
85+
switch shareServer {
86+
case .US:
87+
self.shareServer=dexcomServerUS
88+
case .Non_US:
89+
self.shareServer=dexcomServerNonUS
90+
case .Custom(let url):
91+
self.shareServer=url
92+
}
7893
}
7994

8095
public func fetchLast(_ n: Int, callback: @escaping (ShareError?, [ShareGlucose]?) -> Void) {
@@ -103,7 +118,7 @@ public class ShareClient {
103118
"applicationId": dexcomApplicationId
104119
]
105120

106-
guard let url = URL(string: dexcomServerUS + dexcomLoginPath) else {
121+
guard let url = URL(string: shareServer + dexcomLoginPath) else {
107122
return callback(ShareError.fetchError, nil)
108123
}
109124

@@ -136,7 +151,7 @@ public class ShareClient {
136151
return callback(error, nil)
137152
}
138153

139-
guard var components = URLComponents(string: dexcomServerUS + dexcomLatestGlucosePath) else {
154+
guard var components = URLComponents(string: self.shareServer + dexcomLatestGlucosePath) else {
140155
return callback(.fetchError, nil)
141156
}
142157

0 commit comments

Comments
 (0)