Class: DexcomShareApi::HttpApi

Inherits:
Object
  • Object
show all
Defined in:
lib/dexcom_share_api/http_api.rb

Constant Summary collapse

InvalidServerError =
Class.new(ArgumentError)
ApiError =
Class.new(StandardError)
VALID_SERVERS =

This server needs to be either “us” or “eu. If you’re in the US, the server should be ”us“. Any other country outside of the US (eg. Canada) is classified as ”eu“ by Dexcom.

["us", "outside-us"]
APPLICATION_ID =

This seems to be a blessed ID the Dexcom Share app uses. This is in no way special to this library, is it used in several (nightscout, dexcomedy, etc).

"d8665ade-9673-4e27-9ff6-92db4ce13d13"

Instance Method Summary collapse

Constructor Details

#initialize(username:, password:, server:) ⇒ HttpApi

Returns a new instance of HttpApi.



22
23
24
25
26
27
28
# File 'lib/dexcom_share_api/http_api.rb', line 22

def initialize(username:, password:, server:)
  validate_server!(server)

  @username = username
  @password = password
  @server = server
end

Instance Method Details

#fetch_account_id!Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/dexcom_share_api/http_api.rb', line 64

def 
  uri = URI::HTTPS.build(
    host: base_host,
    path: "/ShareWebServices/Services/General/AuthenticatePublisherAccount",
  )

  data = {
    applicationId: APPLICATION_ID,
    accountName: @username,
    password: @password,
  }

  dexcom_request!(uri, data)
end

#fetch_estimated_glucose!(last:, minutes: 24 * 60) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dexcom_share_api/http_api.rb', line 30

def fetch_estimated_glucose!(last:, minutes: 24 * 60)
  session_id = fetch_session_id!

  uri = URI::HTTPS.build(
    host: base_host,
    path: "/ShareWebServices/Services/Publisher/ReadPublisherLatestGlucoseValues",
  )

  data = {
    maxCount: last,
    sessionId: session_id,
    minutes: minutes,
  }

  dexcom_request!(uri, data)
end

#fetch_session_id!Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dexcom_share_api/http_api.rb', line 47

def fetch_session_id!
   = 

  uri = URI::HTTPS.build(
    host: base_host,
    path: "/ShareWebServices/Services/General/LoginPublisherAccountById",
  )

  data = {
    applicationId: APPLICATION_ID,
    accountId: ,
    password: @password,
  }

  dexcom_request!(uri, data)
end