fitbit_client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FitbitClient
4
+ module Resources
5
+ # The Fitbit's Subscriptions API allows third-party applications
6
+ # to be notified when Fitbit user data changes.
7
+ #
8
+ # This allows apps to have a user's latest data without having to implement
9
+ # a polling or scheduling system to retrieve user's data.
10
+ module Subscription
11
+ # You must add a subscription in your application so that users will
12
+ # get notifications and return a response in the format requested.
13
+ #
14
+ # The <em>activity_type</em> must be one of activities, body, foods, sleep
15
+ # if nil value is passed the activity, nutrition, profile, settings,
16
+ # sleep, weight scopes are required.
17
+ #
18
+ # The <em>subscription_id</em> value provides a way to associate an update
19
+ # with a particular user stream in your application, you must generate
20
+ # this value.
21
+ def add_subscription(activity_type, subscription_id)
22
+ post_json(path_user_version("#{subscription_path(activity_type)}/#{subscription_id}"))
23
+ end
24
+
25
+ # Deletes a subscription for a user.
26
+ # A successful request will return a 204 status code and empty response body.
27
+ #
28
+ # returns true when succesfully deleted
29
+ def delete_subscription(activity_type, subscription_id)
30
+ path = path_user_version("#{subscription_path(activity_type)}/#{subscription_id}")
31
+ successful_delete?(delete(path))
32
+ end
33
+
34
+ # Get a list of a user's subscriptions for your application in the format
35
+ # requested.
36
+ #
37
+ # You can either fetch subscriptions for a specific collection or the
38
+ # entire list of subscriptions for the user.
39
+ #
40
+ # For best practice, make sure that your application maintains this
41
+ # list on your side and use this endpoint only to periodically ensure
42
+ # data consistency.
43
+ def list_of_subscriptions(activity_type)
44
+ get_json(path_user_version(subscription_path(activity_type)))
45
+ end
46
+
47
+ private
48
+
49
+ def subscription_path(activity_type)
50
+ activity_type ? "/#{subscription_type_whitelist(activity_type)}/apiSubscriptions" : '/apiSubscriptions'
51
+ end
52
+
53
+ def subscription_type_whitelist(activity_type)
54
+ return activity_type if FitbitClient::VALID_SUBSCRIPTIONS.include?(activity_type.to_sym)
55
+ raise "Invalid activity type requested for subscription, must be one of #{FitbitClient::VALID_SUBSCRIPTIONS}"
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FitbitClient
4
+ module Util
5
+ def empty_str?(obj)
6
+ obj.nil? || obj.empty?
7
+ end
8
+
9
+ def path_user_version(path, options = {})
10
+ version = options.fetch(:version, '1')
11
+ return "/#{version}#{path}.json" if options[:skip_user]
12
+
13
+ # Add user id
14
+ user_id = options.fetch(:user_id, '-')
15
+ "/#{version}/user/#{user_id}#{path}.json"
16
+ end
17
+
18
+ # Convert a Date object to a iso8601 format String (yyyy-MM-dd)
19
+ def iso_date(date)
20
+ date.iso8601
21
+ end
22
+
23
+ def iso_time(time)
24
+ time.strftime('%H:%M')
25
+ end
26
+
27
+ def iso_time_with_seconds(time)
28
+ time.strftime('%H:%M:%S')
29
+ end
30
+
31
+ module_function :empty_str?, :iso_date, :iso_time, :iso_time_with_seconds, :path_user_version
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FitbitClient
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fitbit_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michel Ocon
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: codeclimate-test-reporter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 1.0.0
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '1.0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.0.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: minitest
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '5.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '5.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: simplecov
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.13.0
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.13.0
103
+ - !ruby/object:Gem::Dependency
104
+ name: vcr
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '3.0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '3.0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: webmock
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '2.3'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '2.3'
131
+ - !ruby/object:Gem::Dependency
132
+ name: oauth2
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '1.4'
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: 1.4.0
141
+ type: :runtime
142
+ prerelease: false
143
+ version_requirements: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - "~>"
146
+ - !ruby/object:Gem::Version
147
+ version: '1.4'
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: 1.4.0
151
+ description: Client library which connects to the Fibit API using OAuth2 protocol.
152
+ email:
153
+ - soun.xrt@gmail.com
154
+ executables: []
155
+ extensions: []
156
+ extra_rdoc_files: []
157
+ files:
158
+ - ".gitignore"
159
+ - ".rubocop.yml"
160
+ - ".rubocop_todo.yml"
161
+ - ".travis.yml"
162
+ - CODE_OF_CONDUCT.md
163
+ - Gemfile
164
+ - LICENSE
165
+ - README.md
166
+ - Rakefile
167
+ - bin/console
168
+ - bin/setup
169
+ - fitbit_client.gemspec
170
+ - lib/fitbit_client.rb
171
+ - lib/fitbit_client/authorization_grant_flow.rb
172
+ - lib/fitbit_client/client.rb
173
+ - lib/fitbit_client/error.rb
174
+ - lib/fitbit_client/network/request.rb
175
+ - lib/fitbit_client/resources.rb
176
+ - lib/fitbit_client/resources/activity.rb
177
+ - lib/fitbit_client/resources/body_and_weight.rb
178
+ - lib/fitbit_client/resources/common.rb
179
+ - lib/fitbit_client/resources/devices.rb
180
+ - lib/fitbit_client/resources/sleep.rb
181
+ - lib/fitbit_client/resources/subscription.rb
182
+ - lib/fitbit_client/util.rb
183
+ - lib/fitbit_client/version.rb
184
+ homepage: https://github.com/sounxrt/fitbit_client
185
+ licenses:
186
+ - MIT
187
+ metadata: {}
188
+ post_install_message:
189
+ rdoc_options: []
190
+ require_paths:
191
+ - lib
192
+ required_ruby_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - "~>"
195
+ - !ruby/object:Gem::Version
196
+ version: '2.3'
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ requirements: []
203
+ rubyforge_project:
204
+ rubygems_version: 2.6.12
205
+ signing_key:
206
+ specification_version: 4
207
+ summary: Connects to Fibit API using OAuth2
208
+ test_files: []