Skip to content

Commit 69ce6bb

Browse files
dabearmddub
authored andcommitted
Shareserver as url and expose list of known shareservers (#13)
* Support US, NON_US and Custom ShareServer during initialization * remove unnecessary optional and unwrapping * remove trailing whitespaces as requested * expose list of known share urls, make init take shareserver as a strign parameter
1 parent 543473a commit 69ce6bb

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

ShareClient/ShareClient.swift

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

29-
public enum ShareServer {
30-
case US
31-
case Non_US
32-
case Custom(String)
29+
30+
public enum KnownShareServers: String {
31+
case US="https://share1.dexcom.com"
32+
case NON_US="https://shareous1.dexcom.com"
33+
3334
}
3435

3536
// From the Dexcom Share iOS app, via @bewest and @shanselman:
@@ -38,8 +39,6 @@ private let dexcomUserAgent = "Dexcom Share/3.0.2.11 CFNetwork/711.2.23 Darwin/1
3839
private let dexcomApplicationId = "d89443d2-327c-4a6f-89e5-496bbb0317db"
3940
private let dexcomLoginPath = "/ShareWebServices/Services/General/LoginPublisherAccountByName"
4041
private let dexcomLatestGlucosePath = "/ShareWebServices/Services/Publisher/ReadPublisherLatestGlucoseValues"
41-
private let dexcomServerUS = "https://share1.dexcom.com"
42-
private let dexcomServerNonUS = "https://shareous1.dexcom.com"
4342
private let maxReauthAttempts = 2
4443

4544
// TODO use an HTTP library which supports JSON and futures instead of callbacks.
@@ -79,17 +78,15 @@ public class ShareClient {
7978
private let shareServer:String
8079
private var token: String?
8180

82-
public init(username: String, password: String, shareServer:ShareServer=ShareServer.US) {
81+
public init(username: String, password: String, shareServer:String=KnownShareServers.US.rawValue) {
8382
self.username = username
8483
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-
}
84+
self.shareServer = shareServer
85+
}
86+
public convenience init(username: String, password: String, shareServer:KnownShareServers=KnownShareServers.US) {
87+
88+
self.init(username: username, password: password, shareServer:shareServer.rawValue)
89+
9390
}
9491

9592
public func fetchLast(_ n: Int, callback: @escaping (ShareError?, [ShareGlucose]?) -> Void) {

0 commit comments

Comments
 (0)