dexcom 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d92f8ee13e26400f77410fae6493272443160c5b0127a3707803441bdc9ac3ca
4
- data.tar.gz: fc1ab6d1dcf9ef7830621422fa6e24900a3274745ea6844e7b3e8901ec7920b1
3
+ metadata.gz: a9fd13bc624d95fe72f20fb528eade9fc3240282f052450a18a81070d6b2c18f
4
+ data.tar.gz: 0fad9ab7130a00684ffc57bf4daebf6ef2bf50892437bb93590f755a20111575
5
5
  SHA512:
6
- metadata.gz: aa6c3c86b3cf48bd6fae4d68c2eed1c7b44999d6e0f69282ce3742bbe7379d46c2e5f3b1696b92a2729a3fa7febedc0b072a1d93945ef186bc8b19f273589b4d
7
- data.tar.gz: 807626594715076c8ad214156e3117a97eea810afa1b5feb4b182e6b7bb43c176ae8cc6f0a1e8d9d140e92dd12c49cd0ebeb7a18596fc83e25dc7d0bd7b1e9da
6
+ metadata.gz: 68ae42721d0b56cf18fb3d1b202f244702f5aa38e8da23c6747ed5ebe5b058093fb56197e35bbd975bfc2061d8ac2c2d223a4bb10f36e038812b4fa6693200d4
7
+ data.tar.gz: f6155dad0b5fb77910260612f6a386481e38885210dccf87291c56c602b2b8a837494a674daf4e9563fdcada49d3ea71098cb2cb0204bdde66e957f3647211b2
@@ -0,0 +1,50 @@
1
+ version: 2.1
2
+ orbs:
3
+ ruby: circleci/ruby@0.1.2
4
+
5
+ common: &common
6
+ steps:
7
+ - checkout
8
+ - run:
9
+ name: Configure Bundler
10
+ command: |
11
+ echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV
12
+ source $BASH_ENV
13
+ gem install bundler
14
+ - restore_cache:
15
+ keys:
16
+ - v1-dep-bundle-{{ checksum "Gemfile.lock" }}-{{ .Environment.CIRCLE_JOB }}
17
+ - run:
18
+ name: Install dependencies
19
+ command: |
20
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
21
+ - save_cache:
22
+ key: v1-dep-bundle-{{ checksum "Gemfile.lock" }}-{{ .Environment.CIRCLE_JOB }}
23
+ paths:
24
+ - vendor/bundle
25
+ - run:
26
+ name: Run tests
27
+ command: |
28
+ bundle exec rspec --color --format documentation --format progress spec
29
+
30
+
31
+ jobs:
32
+ "ruby-26":
33
+ <<: *common
34
+ docker:
35
+ - image: circleci/ruby:2.6
36
+ "ruby-27":
37
+ <<: *common
38
+ docker:
39
+ - image: ruby:2.7
40
+ "ruby-30":
41
+ <<: *common
42
+ docker:
43
+ - image: ruby:3.0
44
+ workflows:
45
+ version: 2.1
46
+ build:
47
+ jobs:
48
+ - "ruby-26"
49
+ - "ruby-27"
50
+ - "ruby-30"
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
data/Gemfile.lock CHANGED
@@ -1,64 +1,67 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dexcom (0.1.0)
4
+ dexcom (0.3.1)
5
+ activesupport
5
6
  httparty
6
7
 
7
8
  GEM
8
- remote: http://rubygems.org/
9
+ remote: https://rubygems.org/
9
10
  specs:
10
- activesupport (5.2.3)
11
+ activesupport (6.1.4)
11
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
12
- i18n (>= 0.7, < 2)
13
- minitest (~> 5.1)
14
- tzinfo (~> 1.1)
15
- addressable (2.7.0)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
17
+ addressable (2.8.0)
16
18
  public_suffix (>= 2.0.2, < 5.0)
17
- climate_control (0.2.0)
19
+ climate_control (1.0.1)
18
20
  coderay (1.1.3)
19
- concurrent-ruby (1.1.5)
20
- crack (0.4.3)
21
- safe_yaml (~> 1.0.0)
22
- diff-lcs (1.3)
23
- factory_bot (5.0.2)
24
- activesupport (>= 4.2.0)
21
+ concurrent-ruby (1.1.9)
22
+ crack (0.4.5)
23
+ rexml
24
+ diff-lcs (1.4.4)
25
+ factory_bot (6.2.0)
26
+ activesupport (>= 5.0.0)
25
27
  hashdiff (1.0.1)
26
- httparty (0.18.0)
28
+ httparty (0.18.1)
27
29
  mime-types (~> 3.0)
28
30
  multi_xml (>= 0.5.2)
29
- i18n (1.6.0)
31
+ i18n (1.8.10)
30
32
  concurrent-ruby (~> 1.0)
31
33
  method_source (1.0.0)
32
34
  mime-types (3.3.1)
33
35
  mime-types-data (~> 3.2015)
34
- mime-types-data (3.2020.0512)
35
- minitest (5.11.3)
36
+ mime-types-data (3.2021.0704)
37
+ minitest (5.14.4)
36
38
  multi_xml (0.6.0)
37
39
  pry (0.13.1)
38
40
  coderay (~> 1.1)
39
41
  method_source (~> 1.0)
40
- public_suffix (4.0.5)
41
- rspec (3.9.0)
42
- rspec-core (~> 3.9.0)
43
- rspec-expectations (~> 3.9.0)
44
- rspec-mocks (~> 3.9.0)
45
- rspec-core (3.9.2)
46
- rspec-support (~> 3.9.3)
47
- rspec-expectations (3.9.2)
42
+ public_suffix (4.0.6)
43
+ rexml (3.2.5)
44
+ rspec (3.10.0)
45
+ rspec-core (~> 3.10.0)
46
+ rspec-expectations (~> 3.10.0)
47
+ rspec-mocks (~> 3.10.0)
48
+ rspec-core (3.10.1)
49
+ rspec-support (~> 3.10.0)
50
+ rspec-expectations (3.10.1)
48
51
  diff-lcs (>= 1.2.0, < 2.0)
49
- rspec-support (~> 3.9.0)
50
- rspec-mocks (3.9.1)
52
+ rspec-support (~> 3.10.0)
53
+ rspec-mocks (3.10.2)
51
54
  diff-lcs (>= 1.2.0, < 2.0)
52
- rspec-support (~> 3.9.0)
53
- rspec-support (3.9.3)
54
- safe_yaml (1.0.5)
55
- thread_safe (0.3.6)
56
- tzinfo (1.2.5)
57
- thread_safe (~> 0.1)
58
- webmock (3.8.3)
55
+ rspec-support (~> 3.10.0)
56
+ rspec-support (3.10.2)
57
+ timecop (0.9.1)
58
+ tzinfo (2.0.4)
59
+ concurrent-ruby (~> 1.0)
60
+ webmock (3.13.0)
59
61
  addressable (>= 2.3.6)
60
62
  crack (>= 0.3.2)
61
63
  hashdiff (>= 0.4.0, < 2.0.0)
64
+ zeitwerk (2.4.2)
62
65
 
63
66
  PLATFORMS
64
67
  ruby
@@ -70,7 +73,8 @@ DEPENDENCIES
70
73
  factory_bot
71
74
  pry
72
75
  rspec
76
+ timecop
73
77
  webmock
74
78
 
75
79
  BUNDLED WITH
76
- 2.0.2
80
+ 2.2.21
data/README.md CHANGED
@@ -1,2 +1,108 @@
1
1
  # dexcom-ruby
2
- Gem to interact with Dexcom Share API, enabling real-time retrieval of glucose data
2
+ [Imgur](https://i.imgur.com/HZdC1fH.png?1)
3
+ [![Gem Version](https://badge.fury.io/rb/dexcom.svg)](https://rubygems.org/gems/dexcom) [![AlexGascon](https://circleci.com/gh/AlexGascon/dexcom-ruby.svg?style=svg)](https://app.circleci.com/pipelines/github/AlexGascon/dexcom-ruby)
4
+
5
+ ## Introduction
6
+ `dexcom-ruby` allows you to easily interact with Dexcom Share APIs, enabling real-time retrieval of glucose data on your application
7
+
8
+ ## Install
9
+ You can install the gem via Rubygems:
10
+
11
+ ```
12
+ gem install dexcom
13
+ ```
14
+
15
+ ## Configuration
16
+ The gem can be easily configured via the `configure` method:
17
+
18
+ ```ruby
19
+ Dexcom.configure do |config|
20
+ config.username = 'my_username'
21
+ config.password = 'my_password'
22
+ config.outside_usa = true
23
+ end
24
+ ```
25
+
26
+ There are three available parameters to configure:
27
+ * `username`: The username of your Dexcom account
28
+ * `password`: The password of your Dexcom account
29
+ * `outside_usa`: Boolean indicating if the account that you want to access is not an American one
30
+
31
+ ## Usage
32
+ You can retrieve the last blood glucose reading from Dexcom using the method `Dexcom::BloodGlucose.last`
33
+
34
+ ```
35
+ bg = Dexcom::BloodGlucose.last
36
+ => #<Dexcom::BloodGlucose:0x0000555c19959000
37
+ @timestamp=Sun, 21 Jun 2020 11:23:05 +0000,
38
+ @trend=4,
39
+ @value=147>
40
+ ```
41
+
42
+ It will return a `Dexcom::BloodGlucose` object, which has the following fields:
43
+
44
+ * `value`: The blood glucose value in mg/dL
45
+ * `timestamp`: The instant when this reading was registered
46
+ * `trend`: Number representing the type of progression of the latest readings. You can get a human-readable version using `trend_description` and its symbol using `trend_symbol`.
47
+ * `mg_dl`: Alias to `value`
48
+ * `mmol`: Blood glucose value in mmol/L
49
+
50
+ ```
51
+ bg.timestamp
52
+ => Sun, 21 Jun 2020 11:23:05 +0000
53
+
54
+ bg.trend_description
55
+ => "Steady"
56
+
57
+ bg.trend_symbol
58
+ => "→"
59
+
60
+ bg.mg_dl
61
+ => 147
62
+
63
+ bg.mmol
64
+ => 8.2
65
+ ```
66
+
67
+ Additionally, if you prefer to retrieve a range of values instead of only the last one, you can use the `.get_last` method. You can specify either the number of values that you want or how many minutes in the past you want to search for
68
+
69
+ ```
70
+ Dexcom::BloodGlucose.get_last(max_count: 5)
71
+ => [#<Dexcom::BloodGlucose:0x0000555c19d7b7c8
72
+ @timestamp=Sun, 21 Jun 2020 11:23:05 +0000,
73
+ @trend=4,
74
+ @value=147>,
75
+ #<Dexcom::BloodGlucose:0x0000555c19d7b660
76
+ @timestamp=Sun, 21 Jun 2020 11:18:06 +0000,
77
+ @trend=4,
78
+ @value=148>,
79
+ #<Dexcom::BloodGlucose:0x0000555c19d7b4d0
80
+ @timestamp=Sun, 21 Jun 2020 11:13:06 +0000,
81
+ @trend=4,
82
+ @value=147>,
83
+ #<Dexcom::BloodGlucose:0x0000555c19d7b390
84
+ @timestamp=Sun, 21 Jun 2020 11:08:06 +0000,
85
+ @trend=4,
86
+ @value=148>,
87
+ #<Dexcom::BloodGlucose:0x0000555c19d7b138
88
+ @timestamp=Sun, 21 Jun 2020 11:03:06 +0000,
89
+ @trend=4,
90
+ @value=149>]
91
+
92
+
93
+ Dexcom::BloodGluocse.get_last(minutes: 15)
94
+ => [#<Dexcom::BloodGlucose:0x0000555c19d7b7c8
95
+ @timestamp=Sun, 21 Jun 2020 11:23:05 +0000,
96
+ @trend=4,
97
+ @value=147>,
98
+ #<Dexcom::BloodGlucose:0x0000555c19d7b660
99
+ @timestamp=Sun, 21 Jun 2020 11:18:06 +0000,
100
+ @trend=4,
101
+ @value=148>,
102
+ #<Dexcom::BloodGlucose:0x0000555c19d7b4d0
103
+ @timestamp=Sun, 21 Jun 2020 11:13:06 +0000,
104
+ @trend=4,
105
+ @value=147>]
106
+ ```
107
+
108
+ **NOTE:** You can retrieve data up to 1440 minutes (24 hours) in the past. Even if `minutes` is greater than 1440, or if you specify a `max_count` greater than the number of blood glucose values registered in the last 24 hours, you will only get data for that period
data/dexcom.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ['lib']
23
23
 
24
+ spec.add_dependency 'activesupport'
24
25
  spec.add_dependency 'httparty'
25
26
 
26
27
  spec.add_development_dependency 'bundler'
@@ -28,5 +29,6 @@ Gem::Specification.new do |spec|
28
29
  spec.add_development_dependency 'factory_bot'
29
30
  spec.add_development_dependency 'pry'
30
31
  spec.add_development_dependency 'rspec'
32
+ spec.add_development_dependency 'timecop'
31
33
  spec.add_development_dependency 'webmock'
32
34
  end
data/lib/dexcom.rb CHANGED
@@ -6,14 +6,4 @@ require 'dexcom/configuration'
6
6
  require 'dexcom/constants'
7
7
  require 'dexcom/version'
8
8
 
9
- module Dexcom
10
- class << self
11
- def configuration
12
- @configuration ||= Configuration.new
13
- end
14
-
15
- def configure
16
- yield configuration
17
- end
18
- end
19
- end
9
+ module Dexcom; end
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'httparty'
3
+ require 'utils/httparty_configured'
4
4
 
5
5
  module Dexcom
6
6
  class Authentication
7
+ include ::Utils::HTTPartyConfigured
8
+
7
9
  class << self
8
10
  def access_token
9
11
  refresh_access_token if @access_token.nil?
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'utils/httparty_configured'
4
+
3
5
  module Dexcom
4
6
  module BloodGlucoseUtils
5
7
  module ApiHandler
8
+ include ::Utils::HTTPartyConfigured
9
+
6
10
  MAX_MINUTES = 1440
7
11
 
8
12
  def make_api_request(number_of_values)
@@ -42,7 +46,8 @@ module Dexcom
42
46
  def query(max_count)
43
47
  {
44
48
  maxCount: max_count,
45
- minutes: MAX_MINUTES
49
+ minutes: MAX_MINUTES,
50
+ sessionId: Dexcom::Authentication.session_id
46
51
  }
47
52
  end
48
53
 
@@ -50,9 +55,8 @@ module Dexcom
50
55
  timestamp_info = blood_glucose_response_item['WT']
51
56
  timestamp_regex = /(\d+)000/
52
57
  timestamp = timestamp_info[timestamp_regex, 1]
53
- utc = '+00:00'
54
58
 
55
- DateTime.parse(Time.at(timestamp.to_i, in: utc).to_s)
59
+ DateTime.strptime(timestamp, '%s')
56
60
  end
57
61
 
58
62
  def config
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal
2
2
 
3
+ require 'active_support'
4
+ require 'active_support/core_ext'
5
+
3
6
  module Dexcom
4
7
  module BloodGlucoseUtils
5
8
  module ClassMethods
@@ -7,26 +10,30 @@ module Dexcom
7
10
  MINUTES_PER_DATAPOINT = 5
8
11
 
9
12
  def last
10
- get_last(max_count: 1)
13
+ get_last(max_count: 1).first
11
14
  end
12
15
 
13
16
  def get_last(max_count: nil, minutes: nil)
14
17
  number_of_values = calculate_number_of_values(max_count, minutes)
15
18
 
16
19
  response = make_api_request(number_of_values)
17
- process_api_response(response)
20
+ blood_glucose_values = process_api_response(response)
21
+
22
+ if minutes.present?
23
+ blood_glucose_values.select! { |bg| bg.timestamp >= minutes.minutes.ago }
24
+ end
25
+
26
+ blood_glucose_values
18
27
  end
19
28
 
20
29
  private
21
30
 
22
31
  def calculate_number_of_values(max_count, minutes)
23
- if minutes.nil?
24
- max_count || DEFAULT_NUMBER_OF_VALUES
25
- elsif max_count.nil?
26
- minutes / MINUTES_PER_DATAPOINT
27
- else
28
- [max_count, minutes / MINUTES_PER_DATAPOINT].min
29
- end
32
+ return DEFAULT_NUMBER_OF_VALUES if (minutes.nil? && max_count.nil?)
33
+ return max_count if minutes.nil?
34
+ return (minutes / MINUTES_PER_DATAPOINT) if max_count.nil?
35
+
36
+ [max_count, minutes / MINUTES_PER_DATAPOINT].min
30
37
  end
31
38
  end
32
39
  end
@@ -2,16 +2,37 @@
2
2
 
3
3
  module Dexcom
4
4
  class Configuration
5
- attr_accessor :username, :password, :outside_usa
5
+ attr_accessor :username, :password, :outside_usa, :logger, :log_level
6
+
7
+ DEFAULT_LOGGER = nil
8
+ DEFAULT_LOGGER_LEVEL = :info
6
9
 
7
10
  def initialize
8
11
  @username = nil
9
12
  @password = nil
10
13
  @outside_usa = nil
14
+ @logger = DEFAULT_LOGGER
15
+ @log_level = DEFAULT_LOGGER_LEVEL
11
16
  end
12
17
 
13
18
  def base_url
14
19
  outside_usa ? URL_BASE_OUTSIDE_USA : URL_BASE
15
20
  end
16
21
  end
22
+
23
+ class << self
24
+ def configuration
25
+ @configuration ||= Configuration.new
26
+ end
27
+
28
+ def configuration=(config)
29
+ raise StandardError('Invalid configuration provided') unless config.is_a? Dexcom::Configuration
30
+
31
+ @configuration = config
32
+ end
33
+
34
+ def configure
35
+ yield configuration
36
+ end
37
+ end
17
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dexcom
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.1'
5
5
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+
5
+ require 'dexcom/configuration'
6
+
7
+ module Utils
8
+ module HTTPartyConfigured
9
+ include HTTParty
10
+
11
+ config = Dexcom.configuration
12
+
13
+ unless config.logger.nil?
14
+ logger config.logger, config.log_level, :apache
15
+ debug_output config.logger if config.log_level == :debug
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dexcom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Gascon
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-13 00:00:00.000000000 Z
11
+ date: 2021-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: httparty
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +108,20 @@ dependencies:
94
108
  - - ">="
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: timecop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: webmock
99
127
  requirement: !ruby/object:Gem::Requirement
@@ -108,12 +136,13 @@ dependencies:
108
136
  - - ">="
109
137
  - !ruby/object:Gem::Version
110
138
  version: '0'
111
- description:
139
+ description:
112
140
  email: alexgascon.93@gmail.com
113
141
  executables: []
114
142
  extensions: []
115
143
  extra_rdoc_files: []
116
144
  files:
145
+ - ".circleci/config.yml"
117
146
  - ".gitignore"
118
147
  - ".rspec"
119
148
  - Gemfile
@@ -129,11 +158,12 @@ files:
129
158
  - lib/dexcom/configuration.rb
130
159
  - lib/dexcom/constants.rb
131
160
  - lib/dexcom/version.rb
132
- homepage:
161
+ - lib/utils/httparty_configured.rb
162
+ homepage:
133
163
  licenses:
134
164
  - MIT
135
165
  metadata: {}
136
- post_install_message:
166
+ post_install_message:
137
167
  rdoc_options: []
138
168
  require_paths:
139
169
  - lib
@@ -148,8 +178,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
178
  - !ruby/object:Gem::Version
149
179
  version: '0'
150
180
  requirements: []
151
- rubygems_version: 3.0.3
152
- signing_key:
181
+ rubygems_version: 3.2.15
182
+ signing_key:
153
183
  specification_version: 4
154
184
  summary: Gem to interact with Dexcom Share API
155
185
  test_files: []