Sha256: b752d5455a499e6cf7fd26a3b90821e72b31c8a2f779a8425ece774b6bdc65ad

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

require 'httparty'
require 'json'

class Dexby::Connection
  include ::HTTParty
  base_uri 'https://share1.dexcom.com'
  headers ({
            "User-Agent" => "Dexcom Share/3.0.2.11 CFNetwork/711.2.23 Darwin/14.0.0",
            "Content-Type" => "application/json",
            "Accept" => "application/json",
          })
  format :json

  APPLICATION_ID = "d8665ade-9673-4e27-9ff6-92db4ce13d13" # not sure where this comes from, might just be internal versioning for legit dexcom app?
  LOGIN_ENDPOINT = "/ShareWebServices/Services/General/LoginPublisherAccountByName"
  READ_ENDPOINT = "/ShareWebServices/Services/Publisher/ReadPublisherLatestGlucoseValues"

  def self.login_body(user, pass)
    {"accountName" => user, "password" => pass, "applicationId" => APPLICATION_ID}
  end

  def self.read_query(session_id, minutes, count)
    {"sessionId" => session_id, "minutes" => minutes, "maxCount" => count}
  end

  def self.login(user, pass)
    response = self.post(LOGIN_ENDPOINT, body: login_body(user, pass).to_json)
    [response.body.tr('"',''), response.code]
  end

  def self.read(session_id, minutes, count)
    response = self.post(READ_ENDPOINT, query: read_query(session_id, minutes, count))
    [response.parsed_response, response.code]
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dexby-0.1.1 lib/dexby/connection.rb
dexby-0.1.0 lib/dexby/connection.rb