fitbyte 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/README.md +17 -17
- data/fitbyte.gemspec +1 -1
- data/lib/fitbyte/activities.rb +7 -7
- data/lib/fitbyte/alarms.rb +1 -1
- data/lib/fitbyte/body.rb +4 -4
- data/lib/fitbyte/client.rb +26 -12
- data/lib/fitbyte/devices.rb +1 -1
- data/lib/fitbyte/food.rb +5 -5
- data/lib/fitbyte/friends.rb +2 -2
- data/lib/fitbyte/helpers.rb +4 -0
- data/lib/fitbyte/sleep.rb +1 -1
- data/lib/fitbyte/user.rb +2 -2
- data/lib/fitbyte/version.rb +1 -1
- data/lib/fitbyte/water.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d0655317d528786ceaf0f17b6c784cc8b5efeb1
|
4
|
+
data.tar.gz: 619f36cf862d95e9ddde9e8d1f77e6bd9cbfb7e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09a3f33748d49d7bfcc248fb72a776c80bc4051fb3b894230d67c0f07e01c202729aef6fef5b89fbaa265ca0f81574bcbeaa20312915654b4ed3a3352e35fc1d
|
7
|
+
data.tar.gz: 30275329df704750b1b8178bfedd01d022e949c8a382b29a2e21ae42ca7528f8a57c99f42513e8844b66f6219eeb9ecd85e3dd68c86bb83a80e58bba52d5da86
|
data/README.md
CHANGED
@@ -1,51 +1,51 @@
|
|
1
1
|
# Fitbyte
|
2
2
|
|
3
|
-
Fitbyte is a gem that allows interaction with Fitbit's REST API, using the OAuth 2.0 protocol for user authorization.
|
3
|
+
Fitbyte is a gem that allows interaction with [Fitbit's REST API](https://dev.fitbit.com/docs/basics/), using the OAuth 2.0 protocol for user authorization.
|
4
4
|
|
5
|
-
**
|
5
|
+
**Note:** Fitbit's API is currently in beta, and is in active/rapid development. Breaking changes to certain endpoints may be introduced during early development of this gem, until Fitbit's API solidifies.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
|
9
|
+
To install the latest release:
|
10
|
+
|
11
|
+
$ gem install fitbyte
|
12
|
+
|
13
|
+
To include in a Rails project, add it to the Gemfile:
|
10
14
|
|
11
15
|
```ruby
|
12
16
|
gem "fitbyte"
|
13
17
|
```
|
14
18
|
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install fitbyte
|
22
|
-
|
23
19
|
## Usage
|
24
20
|
|
25
|
-
|
21
|
+
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** values for use in instantiating a *Fitbyte::Client* object.
|
22
|
+
|
23
|
+
- Create a client instance:
|
26
24
|
|
27
25
|
```ruby
|
28
|
-
client = Fitbyte::Client.new(client_id: my_client_id,
|
26
|
+
client = Fitbyte::Client.new(client_id: my_client_id,
|
27
|
+
client_secret: my_client_secret,
|
28
|
+
redirect_uri: "http://example.com")
|
29
29
|
```
|
30
30
|
|
31
|
-
Generate a link for the Fitbit authorization page:
|
31
|
+
- Generate a link for the Fitbit authorization page:
|
32
32
|
|
33
33
|
```ruby
|
34
34
|
client.auth_page_link
|
35
35
|
# => https://fitbit.com/oauth2/authorize?client_id=123XYZ&redirect_uri=...
|
36
36
|
```
|
37
37
|
|
38
|
-
Follow generated link to Fitbit's authorization page.
|
38
|
+
- Follow 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:
|
39
39
|
|
40
40
|
```ruby
|
41
41
|
client.get_token(auth_code)
|
42
42
|
```
|
43
43
|
|
44
|
-
You
|
44
|
+
You're now authenticated and can make calls to Fitbit's API:
|
45
45
|
|
46
46
|
```ruby
|
47
47
|
client.food_logs
|
48
|
-
# => returns JSON of
|
48
|
+
# => returns JSON of current day's food logs
|
49
49
|
```
|
50
50
|
|
51
51
|
## License
|
data/fitbyte.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'fitbyte/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "fitbyte"
|
8
8
|
spec.version = Fitbyte::VERSION
|
9
|
-
spec.authors = ["Zoran"]
|
9
|
+
spec.authors = ["Zoran Pesic"]
|
10
10
|
spec.email = ["zoran1991@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{A gem that allows interaction with Fitbit's REST API, using OAuth2 for user authorization.}
|
data/lib/fitbyte/activities.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
module Fitbyte
|
2
2
|
class Client
|
3
3
|
def daily_activity_summary(date=Date.today)
|
4
|
-
get("
|
4
|
+
get("user/-/activities/date/#{format_date(date)}.json")
|
5
5
|
end
|
6
6
|
|
7
7
|
def frequent_activities
|
8
|
-
get("
|
8
|
+
get("user/-/activities/frequent.json")
|
9
9
|
end
|
10
10
|
|
11
11
|
def favorite_activities
|
12
|
-
get("
|
12
|
+
get("user/-/activities/favorite.json")
|
13
13
|
end
|
14
14
|
|
15
15
|
def all_activities
|
16
|
-
get("
|
16
|
+
get("activities.json")
|
17
17
|
end
|
18
18
|
|
19
19
|
def lifetime_stats
|
20
|
-
get("
|
20
|
+
get("user/-/activities.json")
|
21
21
|
end
|
22
22
|
|
23
23
|
def daily_goals
|
24
|
-
get("
|
24
|
+
get("user/-/activities/goals/daily.json")
|
25
25
|
end
|
26
26
|
|
27
27
|
def weekly_goals
|
28
|
-
get("
|
28
|
+
get("user/-/activities/goals/weekly.json")
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
data/lib/fitbyte/alarms.rb
CHANGED
data/lib/fitbyte/body.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
module Fitbyte
|
2
2
|
class Client
|
3
3
|
def weight_logs(date=Date.today)
|
4
|
-
get("
|
4
|
+
get("user/-/body/log/weight/date/#{format_date(date)}.json")
|
5
5
|
end
|
6
6
|
|
7
7
|
def body_fat_logs(date=Date.today)
|
8
|
-
get("
|
8
|
+
get("user/-/body/log/fat/date/#{format_date(date)}.json")
|
9
9
|
end
|
10
10
|
|
11
11
|
def weight_goals
|
12
|
-
get("
|
12
|
+
get("user/-/body/log/weight/goal.json")
|
13
13
|
end
|
14
14
|
|
15
15
|
def body_fat_goals
|
16
|
-
get("
|
16
|
+
get("user/-/body/log/fat/goal.json")
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/fitbyte/client.rb
CHANGED
@@ -11,22 +11,25 @@ require "fitbyte/water"
|
|
11
11
|
|
12
12
|
module Fitbyte
|
13
13
|
class Client
|
14
|
+
attr_accessor :api_version, :unit_system, :locale, :scope
|
15
|
+
|
14
16
|
def initialize(options)
|
15
|
-
missing_args = [:client_id, :client_secret] - options.keys
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
missing_args = [:client_id, :client_secret, :redirect_uri] - options.keys
|
18
|
+
|
19
|
+
raise ArgumentError, "Required arguments: #{missing.join(', ')}" if missing_args.size > 0
|
20
|
+
|
19
21
|
@client_id = options[:client_id]
|
20
22
|
@client_secret = options[:client_secret]
|
21
23
|
|
22
24
|
@redirect_uri = options[:redirect_uri]
|
23
|
-
@site_url = options[:site_url] ||
|
24
|
-
@authorize_url = options[:authorize_url] ||
|
25
|
-
@token_url = options[:token_url] ||
|
25
|
+
@site_url = options[:site_url] || defaults[:site_url]
|
26
|
+
@authorize_url = options[:authorize_url] || defaults[:authorize_url]
|
27
|
+
@token_url = options[:token_url] || defaults[:token_url]
|
26
28
|
|
27
|
-
@scope = options[:scope]
|
28
|
-
@unit_system = options[:unit_system] ||
|
29
|
-
@locale = options[:locale] ||
|
29
|
+
@scope = format_scope(options[:scope]) || defaults[:scope]
|
30
|
+
@unit_system = options[:unit_system] || defaults[:unit_system]
|
31
|
+
@locale = options[:locale] || defaults[:locale]
|
32
|
+
@api_version = "1"
|
30
33
|
|
31
34
|
@client = OAuth2::Client.new(@client_id, @client_secret, site: @site_url,
|
32
35
|
authorize_url: @authorize_url, token_url: @token_url)
|
@@ -54,14 +57,25 @@ module Fitbyte
|
|
54
57
|
|
55
58
|
def request_headers
|
56
59
|
{
|
57
|
-
"User-Agent" => "fitbyte-#{Fitbyte::VERSION} gem(#{Fitbyte::REPO_URL})",
|
60
|
+
"User-Agent" => "fitbyte-#{Fitbyte::VERSION} gem (#{Fitbyte::REPO_URL})",
|
58
61
|
"Accept-Language" => @unit_system,
|
59
62
|
"Accept-Locale" => @locale
|
60
63
|
}
|
61
64
|
end
|
62
65
|
|
66
|
+
def defaults
|
67
|
+
{
|
68
|
+
site_url: "https://api.fitbit.com",
|
69
|
+
authorize_url: "https://www.fitbit.com/oauth2/authorize",
|
70
|
+
token_url: "https://api.fitbit.com/oauth2/token",
|
71
|
+
scope: "activity nutrition profile settings sleep social weight",
|
72
|
+
unit_system: "en_US",
|
73
|
+
locale: "en_US"
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
63
77
|
def get(path)
|
64
|
-
JSON.parse(token.get(path, headers: request_headers).response.body)
|
78
|
+
JSON.parse(token.get(("#{@api_version}/" + path), headers: request_headers).response.body)
|
65
79
|
end
|
66
80
|
end
|
67
81
|
end
|
data/lib/fitbyte/devices.rb
CHANGED
data/lib/fitbyte/food.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
module Fitbyte
|
2
2
|
class Client
|
3
3
|
def food_logs(date=Date.today)
|
4
|
-
get("
|
4
|
+
get("user/-/foods/log/date/#{format_date(date)}.json")
|
5
5
|
end
|
6
6
|
|
7
7
|
def recent_foods
|
8
|
-
get("
|
8
|
+
get("user/-/foods/recent.json")
|
9
9
|
end
|
10
10
|
|
11
11
|
def frequent_foods
|
12
|
-
get("
|
12
|
+
get("user/-/foods/log/frequent.json")
|
13
13
|
end
|
14
14
|
|
15
15
|
def favorite_foods
|
16
|
-
get("
|
16
|
+
get("user/-/foods/log/favorite.json")
|
17
17
|
end
|
18
18
|
|
19
19
|
def food_goals
|
20
|
-
get("
|
20
|
+
get("user/-/foods/log/goal.json")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/fitbyte/friends.rb
CHANGED
data/lib/fitbyte/helpers.rb
CHANGED
data/lib/fitbyte/sleep.rb
CHANGED
data/lib/fitbyte/user.rb
CHANGED
data/lib/fitbyte/version.rb
CHANGED
data/lib/fitbyte/water.rb
CHANGED