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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c0f7cfa7bd01601218b28a91cfc320c5d2e116b5
4
- data.tar.gz: 21808cc90a6c101e5deee4f2f2928f6e771ce20f
2
+ SHA256:
3
+ metadata.gz: a3e997f500cb5e13f629c70ee4a960e449204dd4c0568721277b3adeb397277f
4
+ data.tar.gz: 6b5168a42468309c215a56d988166ff4fb32398df29790c52c28b04c8c6a9423
5
5
  SHA512:
6
- metadata.gz: 6a03d7fcd126de4537b06a898643805d1c32f01222421d1944fdbce72244fe3399b9ec2dc3e727d6fd7bbbd87ecf11739122229c4b69dc7d426833015daee2df
7
- data.tar.gz: d76d0351df16e25d0659a0c8422fa5bd5c06af0b1f0fe0406b4ce2d9b35a30046f0e5362393951fd9e7acae178fed40d629b160a483185c144698f43e032bdaf
6
+ metadata.gz: 5b864be3c323e0c912b26e4d45af8a5c7827e0d1d5431a68712ccc169a63e3c063b6fc0040e6d76fa2675a1ea4a10b7ac2b577683d670d21f0aee8f65de6ecc0
7
+ data.tar.gz: 7f35266d3f1454f61e3f207b2f709400643b2adcb31a29a8b783b2fbbf72805feb05948df48bebedc1c3ec4e3d6746da72ee7f3c78389184c5ed071c72c402b2
@@ -1,7 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.5.1
4
+ - 2.4.2
5
+ - 2.3.5
3
6
  - 2.2.2
4
7
  - 2.1.6
5
8
  - 2.0.0
6
- - 1.9.3
7
9
  before_install: gem install bundler -v 1.10.3
@@ -1,3 +1,7 @@
1
+ 0.8.1
2
+ -----
3
+ - Fix `#activity_logs_list` to allow passing in expected URL params.
4
+
1
5
  0.8.1
2
6
  -----
3
7
  - Post install cleanup
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
- ## Usage
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**, **CLIENT SECRET**, and **REDIRECT URI (Callback URL)** values for use in instantiating a *FitbitAPI::Client* object.
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
- Please reference the [fitbit_api_rails repo](https://github.com/zokioki/fitbit_api_rails) as an example of how to use this gem within Rails.
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
- ### Standalone
28
+ ### Quickstart
29
29
 
30
- - Create a client instance:
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
- client_secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
35
- redirect_uri: 'http://example.com/handle/callback')
34
+ client_secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
35
+ refresh_token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
36
36
  ```
37
37
 
38
- - Generate a link for the Fitbit authorization page:
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 approving your app, you're sent to the `redirect_uri`, with an appended authorization `code` param, which you'll exchange for an access token:
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 authenticated and can make calls to Fitbit's API:
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 the response more easily suited for attribute-assignment, it 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:
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
- # If for some reason you had to mix snake and camel case like below,
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: 100)
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
- get("user/#{user_id}/activities/list.json", opts)
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.
@@ -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
@@ -5,7 +5,7 @@ module FitbitAPI
5
5
 
6
6
  def format_date(date)
7
7
  if [Date, Time, DateTime].include?(date.class)
8
- date.strftime("%Y-%m-%d")
8
+ date.strftime('%Y-%m-%d')
9
9
  elsif date.is_a? String
10
10
  if date =~ /\d{4}\-\d{2}\-\d{2}/
11
11
  date
@@ -1,4 +1,4 @@
1
1
  module FitbitAPI
2
- VERSION = '0.8.1'
2
+ VERSION = '0.8.2'
3
3
  REPO_URL = 'https://github.com/zokioki/fitbit_api'
4
4
  end
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.1
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: 2017-09-17 00:00:00.000000000 Z
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.6.13
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.