fitbyte 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/LICENSE.txt +1 -1
- data/README.md +12 -14
- data/fitbyte.gemspec +16 -12
- data/lib/fitbyte.rb +4 -4
- data/lib/fitbyte/activities.rb +4 -4
- data/lib/fitbyte/base.rb +12 -12
- data/lib/fitbyte/body.rb +1 -1
- data/lib/fitbyte/client.rb +22 -22
- data/lib/fitbyte/food.rb +1 -1
- data/lib/fitbyte/heart_rate.rb +3 -3
- data/lib/fitbyte/helpers/utils.rb +4 -4
- data/lib/fitbyte/sleep.rb +1 -1
- data/lib/fitbyte/version.rb +2 -2
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32ef68e0f19a55d7faf91fcaca68c7cb51c98ad1
|
4
|
+
data.tar.gz: 1d889dff0e1711e09963e7cb7d16e72d2a8b36b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89c9338d9898e5f6c31eda652d0996c22fb04213cdb6bb7b9ec9f3696f1d99722a0de857fcb36876cc1e674fae4a082540ce093d97d018ae2e77872ab9326edd
|
7
|
+
data.tar.gz: 706c3c73f71bffd00e2f2a17646a2b1a33e30a8fbf1ee4f2c7e292e9d5d4d546d8d96dd4b12d738495b1c63ca476de98a724c329f674c65b91ff31d32a664b23
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -3,9 +3,7 @@
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/fitbyte.svg)](https://badge.fury.io/rb/fitbyte)
|
4
4
|
[![Build Status](https://travis-ci.org/zokioki/fitbyte.svg?branch=master)](https://travis-ci.org/zokioki/fitbyte)
|
5
5
|
|
6
|
-
Fitbyte
|
7
|
-
|
8
|
-
It was started as a small personal project to provide a Ruby API interface using OAuth2, after Fitbit announced the eventual drop of OAuth1 support for the developer API.
|
6
|
+
Fitbyte provides a Ruby interface to the [Fitbit Web API](https://dev.fitbit.com/reference/web-api/quickstart).
|
9
7
|
|
10
8
|
## Installation
|
11
9
|
|
@@ -16,7 +14,7 @@ To install the latest release:
|
|
16
14
|
To include in a Rails project, add it to the Gemfile:
|
17
15
|
|
18
16
|
```ruby
|
19
|
-
gem
|
17
|
+
gem 'fitbyte'
|
20
18
|
```
|
21
19
|
|
22
20
|
## Usage
|
@@ -32,15 +30,15 @@ Please reference the [fitbyte-rails repo](https://github.com/zokioki/fitbyte-rai
|
|
32
30
|
- Create a client instance:
|
33
31
|
|
34
32
|
```ruby
|
35
|
-
client = Fitbyte::Client.new(client_id:
|
36
|
-
client_secret:
|
37
|
-
redirect_uri:
|
33
|
+
client = Fitbyte::Client.new(client_id: 'XXXXXX',
|
34
|
+
client_secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
35
|
+
redirect_uri: 'http://example.com/handle/callback')
|
38
36
|
```
|
39
37
|
|
40
38
|
- Generate a link for the Fitbit authorization page:
|
41
39
|
|
42
40
|
```ruby
|
43
|
-
client.
|
41
|
+
client.auth_url
|
44
42
|
# => https://fitbit.com/oauth2/authorize?client_id=123XYZ&redirect_uri=...
|
45
43
|
```
|
46
44
|
|
@@ -57,10 +55,10 @@ client.food_logs Date.today
|
|
57
55
|
# => { "foods" => [{ "isFavorite" => true, "logDate" => "2015-06-26", "logId" => 1820, "loggedFood" => { "accessLevel" => "PUBLIC", "amount" => 132.57, "brand" => "", "calories" => 752, ...}] }
|
58
56
|
```
|
59
57
|
|
60
|
-
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 `
|
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:
|
61
59
|
|
62
60
|
```ruby
|
63
|
-
client.
|
61
|
+
client.snake_case_keys = true
|
64
62
|
client.food_logs Date.today
|
65
63
|
# => { "foods" => [{ "is_favorite" => true, "log_date" => "2015-06-26", "log_id" => 1820, "logged_food" => { "access_level" => "PUBLIC", "amount" => 132.57, "brand" => "", "calories" => 752, ...}] }
|
66
64
|
```
|
@@ -68,11 +66,11 @@ client.food_logs Date.today
|
|
68
66
|
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:
|
69
67
|
|
70
68
|
```ruby
|
71
|
-
client.log_activity activity_id: 12345, duration_millis:
|
72
|
-
client.log_activity activityId: 54321, durationMillis:
|
69
|
+
client.log_activity activity_id: 12345, duration_millis: '50000'
|
70
|
+
client.log_activity activityId: 54321, durationMillis: '44100'
|
73
71
|
# If for some reason you had to mix snake and camel case like below,
|
74
72
|
# Fitbyte would make sure the result is a validly formatted request
|
75
|
-
client.log_activity activity_id: 12345, durationMillis:
|
73
|
+
client.log_activity activity_id: 12345, durationMillis: '683300'
|
76
74
|
```
|
77
75
|
|
78
76
|
### Options
|
@@ -87,7 +85,7 @@ When initializing a `Fitbyte::Client` instance, you're given access to a handful
|
|
87
85
|
|
88
86
|
- `:scope` - A space-delimited list of the permissions you are requesting (default: "activity nutrition profile settings sleep social weight heartrate" | available: "activity", "heartrate", "location", "nutrition", "profile", "settings" "sleep", "social" and "weight")
|
89
87
|
|
90
|
-
- `:
|
88
|
+
- `:snake_case_keys` - Transform returned object's keys to snake case format (default: false)
|
91
89
|
|
92
90
|
- `:symbolize_keys` - Transform returned object's keys to symbols (default: false)
|
93
91
|
|
data/fitbyte.gemspec
CHANGED
@@ -4,25 +4,29 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'fitbyte/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'fitbyte'
|
8
8
|
spec.version = Fitbyte::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = ["zoran1991@gmail.com"]
|
9
|
+
spec.authors = ['Zoran']
|
11
10
|
|
12
|
-
spec.summary = %q{A Ruby interface to the Fitbit API, using OAuth2
|
11
|
+
spec.summary = %q{A Ruby interface to the Fitbit API, using OAuth2 (renamed to fitbit_api)}
|
13
12
|
spec.homepage = Fitbyte::REPO_URL
|
14
|
-
spec.license =
|
13
|
+
spec.license = 'MIT'
|
15
14
|
|
16
15
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
-
spec.bindir =
|
16
|
+
spec.bindir = 'exe'
|
18
17
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
-
spec.require_paths = [
|
18
|
+
spec.require_paths = ['lib']
|
20
19
|
|
21
|
-
spec.required_ruby_version =
|
20
|
+
spec.required_ruby_version = '>= 1.9.3'
|
22
21
|
|
23
|
-
spec.add_runtime_dependency
|
22
|
+
spec.add_runtime_dependency 'oauth2', '~> 1.0'
|
24
23
|
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
|
28
|
+
spec.post_install_message = %q{
|
29
|
+
The fitbyte gem has been renamed to fitbit_api and will no longer be supported.
|
30
|
+
Please switch to using fitbit_api for all versions greater than 0.7.1.
|
31
|
+
}
|
28
32
|
end
|
data/lib/fitbyte.rb
CHANGED
data/lib/fitbyte/activities.rb
CHANGED
@@ -42,7 +42,7 @@ module Fitbyte
|
|
42
42
|
# the activities catalog as well as private custom activities the user created.
|
43
43
|
|
44
44
|
def all_activities(opts={})
|
45
|
-
get(
|
45
|
+
get('activities.json', opts)
|
46
46
|
end
|
47
47
|
|
48
48
|
# Retrieves a list of a user's activity log entries before or after a given day with
|
@@ -85,7 +85,7 @@ module Fitbyte
|
|
85
85
|
end
|
86
86
|
|
87
87
|
if [start_date, period].none?
|
88
|
-
raise Fitbyte::InvalidArgumentError,
|
88
|
+
raise Fitbyte::InvalidArgumentError, 'A start_date or period is required.'
|
89
89
|
end
|
90
90
|
|
91
91
|
if period && !PERIODS.include?(period)
|
@@ -112,7 +112,7 @@ module Fitbyte
|
|
112
112
|
end
|
113
113
|
|
114
114
|
if [date, detail_level].any?(&:nil?)
|
115
|
-
raise Fitbyte::InvalidArgumentError,
|
115
|
+
raise Fitbyte::InvalidArgumentError, 'A date and detail_level are required.'
|
116
116
|
end
|
117
117
|
|
118
118
|
unless %(1min 15min).include? detail_level
|
@@ -120,7 +120,7 @@ module Fitbyte
|
|
120
120
|
end
|
121
121
|
|
122
122
|
if (start_time || end_time) && !(start_time && end_time)
|
123
|
-
raise Fitbyte::InvalidArgumentError,
|
123
|
+
raise Fitbyte::InvalidArgumentError, 'Both start_time and end_time are required if time is being specified.'
|
124
124
|
end
|
125
125
|
|
126
126
|
if (start_time && end_time)
|
data/lib/fitbyte/base.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'fitbyte/helpers/configuration'
|
2
|
+
require 'fitbyte/helpers/utils'
|
3
|
+
require 'fitbyte/helpers/exceptions'
|
4
4
|
|
5
5
|
module Fitbyte
|
6
6
|
extend Configuration
|
@@ -9,16 +9,16 @@ module Fitbyte
|
|
9
9
|
define_setting :client_secret
|
10
10
|
define_setting :redirect_uri
|
11
11
|
|
12
|
-
define_setting :site_url,
|
13
|
-
define_setting :authorize_url,
|
14
|
-
define_setting :token_url,
|
12
|
+
define_setting :site_url, 'https://api.fitbit.com'
|
13
|
+
define_setting :authorize_url, 'https://www.fitbit.com/oauth2/authorize'
|
14
|
+
define_setting :token_url, 'https://api.fitbit.com/oauth2/token'
|
15
15
|
|
16
|
-
define_setting :unit_system,
|
17
|
-
define_setting :locale,
|
18
|
-
define_setting :scope,
|
16
|
+
define_setting :unit_system, 'en_US'
|
17
|
+
define_setting :locale, 'en_US'
|
18
|
+
define_setting :scope, 'activity nutrition profile settings sleep social weight heartrate'
|
19
19
|
|
20
|
-
define_setting :api_version,
|
20
|
+
define_setting :api_version, '1'
|
21
21
|
|
22
|
-
define_setting :
|
23
|
-
define_setting :symbolize_keys,
|
22
|
+
define_setting :snake_case_keys, false
|
23
|
+
define_setting :symbolize_keys, false
|
24
24
|
end
|
data/lib/fitbyte/body.rb
CHANGED
@@ -20,7 +20,7 @@ module Fitbyte
|
|
20
20
|
end
|
21
21
|
|
22
22
|
if [period, start_date].none?
|
23
|
-
raise Fitbyte::InvalidArgumentError,
|
23
|
+
raise Fitbyte::InvalidArgumentError, 'A start_date or period is required.'
|
24
24
|
end
|
25
25
|
|
26
26
|
if period && !PERIODS.include?(period)
|
data/lib/fitbyte/client.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
1
|
+
require 'fitbyte/base'
|
2
|
+
require 'fitbyte/activities'
|
3
|
+
require 'fitbyte/heart_rate'
|
4
|
+
require 'fitbyte/goals'
|
5
|
+
require 'fitbyte/alarms'
|
6
|
+
require 'fitbyte/body'
|
7
|
+
require 'fitbyte/devices'
|
8
|
+
require 'fitbyte/food'
|
9
|
+
require 'fitbyte/friends'
|
10
|
+
require 'fitbyte/sleep'
|
11
|
+
require 'fitbyte/user'
|
12
|
+
require 'fitbyte/water'
|
13
13
|
|
14
14
|
module Fitbyte
|
15
15
|
class Client
|
16
|
-
attr_accessor :api_version, :unit_system, :locale, :scope, :
|
16
|
+
attr_accessor :api_version, :unit_system, :locale, :scope, :snake_case_keys, :symbolize_keys
|
17
17
|
attr_reader :user_id
|
18
18
|
|
19
19
|
def initialize(opts)
|
@@ -21,7 +21,7 @@ module Fitbyte
|
|
21
21
|
raise Fitbyte::InvalidArgumentError, "Required arguments: #{missing_args.join(', ')}" if missing_args.size > 0
|
22
22
|
|
23
23
|
%w(client_id client_secret redirect_uri site_url authorize_url token_url
|
24
|
-
unit_system locale scope api_version
|
24
|
+
unit_system locale scope api_version snake_case_keys symbolize_keys).each do |attr|
|
25
25
|
instance_variable_set("@#{attr}", (opts[attr.to_sym] || Fitbyte.send(attr)))
|
26
26
|
end
|
27
27
|
|
@@ -31,19 +31,19 @@ module Fitbyte
|
|
31
31
|
restore_token(opts[:refresh_token]) if opts[:refresh_token]
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
34
|
+
def auth_url
|
35
35
|
@client.auth_code.authorize_url(redirect_uri: @redirect_uri, scope: @scope)
|
36
36
|
end
|
37
37
|
|
38
38
|
def get_token(auth_code)
|
39
39
|
@token = @client.auth_code.get_token(auth_code, redirect_uri: @redirect_uri, headers: auth_header)
|
40
|
-
@user_id = @token.params[
|
40
|
+
@user_id = @token.params['user_id']
|
41
41
|
return @token
|
42
42
|
end
|
43
43
|
|
44
44
|
def restore_token(refresh_token)
|
45
45
|
@token = OAuth2::AccessToken.from_hash(@client, refresh_token: refresh_token).refresh!(headers: auth_header)
|
46
|
-
@user_id = @token.params[
|
46
|
+
@user_id = @token.params['user_id']
|
47
47
|
return @token
|
48
48
|
end
|
49
49
|
|
@@ -56,14 +56,14 @@ module Fitbyte
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def auth_header
|
59
|
-
{
|
59
|
+
{ 'Authorization' => ('Basic ' + Base64.encode64(@client_id + ':' + @client_secret)) }
|
60
60
|
end
|
61
61
|
|
62
62
|
def request_headers
|
63
63
|
{
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
'User-Agent' => "fitbyte-#{Fitbyte::VERSION} gem (#{Fitbyte::REPO_URL})",
|
65
|
+
'Accept-Language' => @unit_system,
|
66
|
+
'Accept-Locale' => @locale
|
67
67
|
}
|
68
68
|
end
|
69
69
|
|
@@ -86,7 +86,7 @@ module Fitbyte
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def process_keys!(object, opts={})
|
89
|
-
deep_keys_to_snake_case!(object) if (opts[:
|
89
|
+
deep_keys_to_snake_case!(object) if (opts[:snake_case_keys] || snake_case_keys)
|
90
90
|
deep_symbolize_keys!(object) if (opts[:symbolize_keys] || symbolize_keys)
|
91
91
|
return object
|
92
92
|
end
|
data/lib/fitbyte/food.rb
CHANGED
@@ -32,7 +32,7 @@ module Fitbyte
|
|
32
32
|
end
|
33
33
|
|
34
34
|
if [period, start_date].none?
|
35
|
-
raise Fitbyte::InvalidArgumentError,
|
35
|
+
raise Fitbyte::InvalidArgumentError, 'A start_date or period is required.'
|
36
36
|
end
|
37
37
|
|
38
38
|
if period && !PERIODS.include?(period)
|
data/lib/fitbyte/heart_rate.rb
CHANGED
@@ -6,7 +6,7 @@ module Fitbyte
|
|
6
6
|
period = opts[:period]
|
7
7
|
|
8
8
|
if [period, start_date].none?
|
9
|
-
raise Fitbyte::InvalidArgumentError,
|
9
|
+
raise Fitbyte::InvalidArgumentError, 'A start_date or period is required.'
|
10
10
|
end
|
11
11
|
|
12
12
|
if period && !PERIODS.include?(period)
|
@@ -29,7 +29,7 @@ module Fitbyte
|
|
29
29
|
end_time = opts[:end_time]
|
30
30
|
|
31
31
|
if [date, detail_level].any?(&:nil?)
|
32
|
-
raise Fitbyte::InvalidArgumentError,
|
32
|
+
raise Fitbyte::InvalidArgumentError, 'A date and detail_level are required.'
|
33
33
|
end
|
34
34
|
|
35
35
|
unless %(1sec 1min).include? detail_level
|
@@ -37,7 +37,7 @@ module Fitbyte
|
|
37
37
|
end
|
38
38
|
|
39
39
|
if (start_time || end_time) && !(start_time && end_time)
|
40
|
-
raise Fitbyte::InvalidArgumentError,
|
40
|
+
raise Fitbyte::InvalidArgumentError, 'Both start_time and end_time are required if time is being specified.'
|
41
41
|
end
|
42
42
|
|
43
43
|
if (start_time && end_time)
|
@@ -19,7 +19,7 @@ module Fitbyte
|
|
19
19
|
|
20
20
|
def format_time(time)
|
21
21
|
if [Time, DateTime].include?(time.class)
|
22
|
-
time.strftime(
|
22
|
+
time.strftime('%H:%M')
|
23
23
|
elsif time.is_a? String
|
24
24
|
if time =~ /\d{2}\:\d{2}/
|
25
25
|
time
|
@@ -32,7 +32,7 @@ module Fitbyte
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def format_scope(scope)
|
35
|
-
scope.is_a?(Array) ? scope.join(
|
35
|
+
scope.is_a?(Array) ? scope.join(' ') : scope
|
36
36
|
end
|
37
37
|
|
38
38
|
def deep_keys_to_snake_case!(object)
|
@@ -68,14 +68,14 @@ module Fitbyte
|
|
68
68
|
return string.downcase if string.match(/\A[A-Z]+\z/)
|
69
69
|
string.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
70
70
|
string.gsub!(/([a-z])([A-Z])/, '\1_\2')
|
71
|
-
string.gsub!(
|
71
|
+
string.gsub!('-', '_') if opts[:replace_dashes]
|
72
72
|
string.downcase
|
73
73
|
end
|
74
74
|
|
75
75
|
def to_camel_case(word, opts={})
|
76
76
|
string = word.to_s
|
77
77
|
return string if string.match(/[A-Z]|[a-z]([A-Z0-9]*[a-z][a-z0-9]*[A-Z]|[a-z0-9]*[A-Z][A-Z0-9]*[a-z])[A-Za-z0-9]*/)
|
78
|
-
string = word.to_s.split(
|
78
|
+
string = word.to_s.split('_').collect(&:capitalize).join
|
79
79
|
string.gsub!(/^\w{1}/) { |word| word.downcase } if opts[:lower]
|
80
80
|
return string
|
81
81
|
end
|
data/lib/fitbyte/sleep.rb
CHANGED
@@ -17,7 +17,7 @@ module Fitbyte
|
|
17
17
|
end
|
18
18
|
|
19
19
|
if [period, start_date].none?
|
20
|
-
raise Fitbyte::InvalidArgumentError,
|
20
|
+
raise Fitbyte::InvalidArgumentError, 'A start_date or period is required.'
|
21
21
|
end
|
22
22
|
|
23
23
|
if period && !PERIODS.include?(period)
|
data/lib/fitbyte/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fitbyte
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Zoran
|
7
|
+
- Zoran
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|
@@ -67,8 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description:
|
70
|
-
email:
|
71
|
-
- zoran1991@gmail.com
|
70
|
+
email:
|
72
71
|
executables: []
|
73
72
|
extensions: []
|
74
73
|
extra_rdoc_files: []
|
@@ -104,7 +103,9 @@ homepage: https://github.com/zokioki/fitbyte
|
|
104
103
|
licenses:
|
105
104
|
- MIT
|
106
105
|
metadata: {}
|
107
|
-
post_install_message:
|
106
|
+
post_install_message: "\n The fitbyte gem has been renamed to fitbit_api and will
|
107
|
+
no longer be supported.\n Please switch to using fitbit_api for all versions
|
108
|
+
greater than 0.7.1.\n "
|
108
109
|
rdoc_options: []
|
109
110
|
require_paths:
|
110
111
|
- lib
|
@@ -120,8 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
121
|
version: '0'
|
121
122
|
requirements: []
|
122
123
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.6.13
|
124
125
|
signing_key:
|
125
126
|
specification_version: 4
|
126
|
-
summary: A Ruby interface to the Fitbit API, using OAuth2
|
127
|
+
summary: A Ruby interface to the Fitbit API, using OAuth2 (renamed to fitbit_api)
|
127
128
|
test_files: []
|