Skip to content

Commit 21d8657

Browse files
slowbrewedmacchiatoセオウ
andauthored
Add support for Dexcom Japan and APAC (#42)
- Add URL for Dexcom APAC Share API server (covers Japan, Phillipines, Singapore, etc...) - Add Dexcom Application Id for the new URL as it is different from that of the US and Global. - Update UI to allow the user to select the APAC Share API server. Co-authored-by: セオウ <[email protected]>
1 parent 0f93513 commit 21d8657

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

ShareClient/ShareClient.swift

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,26 @@ public enum ShareError: Error {
2727
}
2828

2929

30-
public enum KnownShareServers: String {
30+
public enum KnownShareServers: String, CaseIterable {
3131
case US="https://share2.dexcom.com"
32-
case NON_US="https://shareous1.dexcom.com"
33-
32+
case APAC="https://share.dexcom.jp"
33+
case Worldwide="https://shareous1.dexcom.com"
34+
35+
// Application IDs obtained from Dexcom Share iOS app,
36+
// including the one covering Japan/APAC region.
37+
var dexcomApplicationId: String {
38+
switch self {
39+
case .US, .Worldwide:
40+
"d89443d2-327c-4a6f-89e5-496bbb0317db"
41+
case .APAC:
42+
"d8665ade-9673-4e27-9ff6-92db4ce13d13"
43+
}
44+
}
3445
}
3546

3647
// From the Dexcom Share iOS app, via @bewest and @shanselman:
3748
// https://github.com/bewest/share2nightscout-bridge
3849
private let dexcomUserAgent = "Dexcom Share/3.0.2.11 CFNetwork/711.2.23 Darwin/14.0.0"
39-
private let dexcomApplicationId = "d89443d2-327c-4a6f-89e5-496bbb0317db"
4050
private let dexcomAuthenticatePath = "/ShareWebServices/Services/General/AuthenticatePublisherAccount"
4151
private let dexcomLoginByIdPath = "/ShareWebServices/Services/General/LoginPublisherAccountById"
4252
private let dexcomLatestGlucosePath = "/ShareWebServices/Services/Publisher/ReadPublisherLatestGlucoseValues"
@@ -117,10 +127,14 @@ public class ShareClient {
117127
}
118128

119129
private func fetchAccountID(_ callback: @escaping (Result<String, ShareError>) -> Void) {
130+
guard let applicationId = KnownShareServers(rawValue: shareServer)?.dexcomApplicationId else {
131+
return callback(.failure(.fetchError))
132+
}
133+
120134
let data = [
121135
"accountName": username,
122136
"password": password,
123-
"applicationId": dexcomApplicationId
137+
"applicationId": applicationId
124138
]
125139

126140
guard let url = URL(string: shareServer + dexcomAuthenticatePath) else {
@@ -151,10 +165,14 @@ public class ShareClient {
151165
}
152166

153167
private func fetchTokenByAccountId(_ accountId: String, callback: @escaping (ShareError?, String?) -> Void) {
168+
guard let applicationId = KnownShareServers(rawValue: shareServer)?.dexcomApplicationId else {
169+
return callback(ShareError.fetchError, nil)
170+
}
171+
154172
let data = [
155173
"accountId": accountId,
156174
"password": password,
157-
"applicationId": dexcomApplicationId
175+
"applicationId": applicationId
158176
]
159177

160178
guard let url = URL(string: shareServer + dexcomLoginByIdPath) else {

ShareClientUI/ShareService+UI.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ extension ShareService: ServiceAuthenticationUI {
3232
options: [
3333
(title: LocalizedString("US", comment: "U.S. share server option title"),
3434
value: KnownShareServers.US.rawValue),
35-
(title: LocalizedString("Outside US", comment: "Outside US share server option title"),
36-
value: KnownShareServers.NON_US.rawValue)
35+
(title: LocalizedString("APAC", comment: "Japan, Phillipines, Singapore share server option title"), value: KnownShareServers.APAC.rawValue),
36+
(title: LocalizedString("Worldwide", comment: "Outside US and APAC share server option title"),
37+
value: KnownShareServers.Worldwide.rawValue)
3738

3839
]
3940
)

0 commit comments

Comments
 (0)