@@ -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
3849private 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 "
4050private let dexcomAuthenticatePath = " /ShareWebServices/Services/General/AuthenticatePublisherAccount "
4151private let dexcomLoginByIdPath = " /ShareWebServices/Services/General/LoginPublisherAccountById "
4252private 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 {
0 commit comments