fitbit_api 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +3 -1
- data/CHANGELOG.md +4 -0
- data/README.md +28 -14
- data/lib/fitbit_api/activities.rb +11 -4
- data/lib/fitbit_api/client.rb +2 -2
- data/lib/fitbit_api/helpers/utils.rb +1 -1
- data/lib/fitbit_api/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a3e997f500cb5e13f629c70ee4a960e449204dd4c0568721277b3adeb397277f
|
4
|
+
data.tar.gz: 6b5168a42468309c215a56d988166ff4fb32398df29790c52c28b04c8c6a9423
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b864be3c323e0c912b26e4d45af8a5c7827e0d1d5431a68712ccc169a63e3c063b6fc0040e6d76fa2675a1ea4a10b7ac2b577683d670d21f0aee8f65de6ecc0
|
7
|
+
data.tar.gz: 7f35266d3f1454f61e3f207b2f709400643b2adcb31a29a8b783b2fbbf72805feb05948df48bebedc1c3ec4e3d6746da72ee7f3c78389184c5ed071c72c402b2
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -17,45 +17,59 @@ To include in a Rails project, add it to the Gemfile:
|
|
17
17
|
gem 'fitbit_api'
|
18
18
|
```
|
19
19
|
|
20
|
-
##
|
20
|
+
## Getting Started
|
21
21
|
|
22
|
-
To use the Fitbit API, you must register your application at [dev.fitbit.com](https://dev.fitbit.com/apps). After registering, you should have access to **CLIENT ID
|
22
|
+
To use the Fitbit API, you must register your application at [dev.fitbit.com](https://dev.fitbit.com/apps). After registering, you should have access to the **CLIENT ID** and **CLIENT SECRET** values for use in instantiating a *FitbitAPI::Client* object.
|
23
23
|
|
24
24
|
### Rails
|
25
25
|
|
26
|
-
|
26
|
+
You can reference the [fitbit_api_rails](https://github.com/zokioki/fitbit_api_rails) repo as a simple example of how to use this gem within a Rails project.
|
27
27
|
|
28
|
-
###
|
28
|
+
### Quickstart
|
29
29
|
|
30
|
-
|
30
|
+
If you already have access to a user's stored refresh token, you can instantiate a client instance like so:
|
31
31
|
|
32
32
|
```ruby
|
33
33
|
client = FitbitAPI::Client.new(client_id: 'XXXXXX',
|
34
|
-
|
35
|
-
|
34
|
+
client_secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
35
|
+
refresh_token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
|
36
36
|
```
|
37
37
|
|
38
|
-
|
38
|
+
### OAuth 2.0 Authorization Flow
|
39
|
+
|
40
|
+
- Create a client instance (ensure that `redirect_uri` is passed in):
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
client = FitbitAPI::Client.new(client_id: 'XXXXXX',
|
44
|
+
client_secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
45
|
+
redirect_uri: 'http://example.com/handle/callback')
|
46
|
+
```
|
47
|
+
|
48
|
+
- Generate a link for your app's Fitbit authorization page:
|
39
49
|
|
40
50
|
```ruby
|
41
51
|
client.auth_url
|
42
52
|
# => https://fitbit.com/oauth2/authorize?client_id=123XYZ&redirect_uri=...
|
43
53
|
```
|
44
54
|
|
45
|
-
- Follow the generated link to Fitbit's authorization page. After
|
55
|
+
- Follow the generated link to Fitbit's authorization page. After granting permission for your app, you're sent to the `redirect_uri`, with an appended authorization `code` param, which you'll exchange for an access token:
|
46
56
|
|
47
57
|
```ruby
|
48
58
|
client.get_token(auth_code)
|
49
59
|
```
|
50
60
|
|
51
|
-
You're now
|
61
|
+
You're now authorized and can make calls to Fitbit's API.
|
62
|
+
|
63
|
+
### Interacting with the API
|
64
|
+
|
65
|
+
Once a valid token has been generated, you're able to make API calls from the client object, like so:
|
52
66
|
|
53
67
|
```ruby
|
54
68
|
client.food_logs Date.today
|
55
69
|
# => { "foods" => [{ "isFavorite" => true, "logDate" => "2015-06-26", "logId" => 1820, "loggedFood" => { "accessLevel" => "PUBLIC", "amount" => 132.57, "brand" => "", "calories" => 752, ...}] }
|
56
70
|
```
|
57
71
|
|
58
|
-
To make
|
72
|
+
To make responses more easily suited for attribute-assignment, they can be parsed to return a hash whose keys are in snake_case format. This can be done by setting the client's `snake_case_keys` option to `true`, like so:
|
59
73
|
|
60
74
|
```ruby
|
61
75
|
client.snake_case_keys = true
|
@@ -66,10 +80,11 @@ client.food_logs Date.today
|
|
66
80
|
Similarly, all arguments passed in through a POST request are automatically converted to camelCase before they hit Fitbit's API, making it easy to keep your codebase stylistically consistent. For example, all of the following would result in valid API calls:
|
67
81
|
|
68
82
|
```ruby
|
83
|
+
# options with snake_cased keys
|
69
84
|
client.log_activity activity_id: 12345, duration_millis: '50000'
|
85
|
+
# options with camelCased keys
|
70
86
|
client.log_activity activityId: 54321, durationMillis: '44100'
|
71
|
-
#
|
72
|
-
# FitbitAPI would make sure the result is a validly formatted request
|
87
|
+
# options with mixed snake and camel cased keys
|
73
88
|
client.log_activity activity_id: 12345, durationMillis: '683300'
|
74
89
|
```
|
75
90
|
|
@@ -89,7 +104,6 @@ When initializing a `FitbitAPI::Client` instance, you're given access to a handf
|
|
89
104
|
|
90
105
|
- `:symbolize_keys` - Transform returned object's keys to symbols (default: false)
|
91
106
|
|
92
|
-
|
93
107
|
## License
|
94
108
|
|
95
109
|
This gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -48,15 +48,22 @@ module FitbitAPI
|
|
48
48
|
# Retrieves a list of a user's activity log entries before or after a given day with
|
49
49
|
# offset and limit using units in the unit system which corresponds to the Accept-Language header provided.
|
50
50
|
|
51
|
-
# ==== Parameters
|
51
|
+
# ==== URL Parameters
|
52
52
|
# * +:beforeDate+ - the date; formatted in yyyy-MM-ddTHH:mm:ss
|
53
53
|
# * +:afterDate+ - the date; formatted in yyyy-MM-ddTHH:mm:ss
|
54
54
|
# * +:sort+ - the sort order of entries by date (asc or desc)
|
55
|
-
# * +:offset+ - the offset number of entries
|
56
|
-
# * +:limit+ - the max of the number of entries returned (max:
|
55
|
+
# * +:offset+ - the offset number of entries. Must always be 0
|
56
|
+
# * +:limit+ - the max of the number of entries returned (max: 20)
|
57
57
|
|
58
58
|
def activity_logs_list(opts={})
|
59
|
-
|
59
|
+
params = {}
|
60
|
+
param_defaults = { before_date: Date.today, after_date: nil, sort: 'desc', limit: 20, offset: 0 }
|
61
|
+
|
62
|
+
# merge defaults without overwriting specified values, then split params from options
|
63
|
+
opts.merge!(param_defaults) { |_key, val, _default| val }
|
64
|
+
param_defaults.keys.each { |i| params[i] = opts.delete(i) }
|
65
|
+
|
66
|
+
get("user/#{user_id}/activities/list.json", opts, params: params)
|
60
67
|
end
|
61
68
|
|
62
69
|
# Returns the details of a specific activity in the Fitbit activities database in the format requested.
|
data/lib/fitbit_api/client.rb
CHANGED
@@ -67,8 +67,8 @@ module FitbitAPI
|
|
67
67
|
}
|
68
68
|
end
|
69
69
|
|
70
|
-
def get(path, opts={})
|
71
|
-
response = token.get(("#{@api_version}/" + path), headers: request_headers).response
|
70
|
+
def get(path, opts={}, params: {})
|
71
|
+
response = token.get(("#{@api_version}/" + path), params: deep_keys_to_camel_case!(params), headers: request_headers).response
|
72
72
|
object = MultiJson.load(response.body) unless response.status == 204
|
73
73
|
process_keys!(object, opts)
|
74
74
|
end
|
data/lib/fitbit_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fitbit_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zoran
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
121
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.
|
122
|
+
rubygems_version: 2.7.3
|
123
123
|
signing_key:
|
124
124
|
specification_version: 4
|
125
125
|
summary: A Ruby interface to the Fitbit Web API.
|