fitbyte 0.2.4 → 0.2.5
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/CHANGELOG.md +6 -0
- data/README.md +2 -2
- data/lib/fitbyte.rb +1 -0
- data/lib/fitbyte/client.rb +18 -11
- data/lib/fitbyte/fitstruct.rb +3 -0
- data/lib/fitbyte/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2288b2aa276802af1ee13b8203f7f95bb58c871d
|
4
|
+
data.tar.gz: 15e907b187d26a2faaeb8132506edc32830ca9ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5c642754e899b14be4b0ffc9e5013920e35d5903e47e5f10c5d5b063daf53c8f53e50f9d2353ec1c77c2f51fca25f74bce70c8f04b150d2802e706189012dd4
|
7
|
+
data.tar.gz: 490c4ce5f77788c5f011d683f16dd8afdc36394186987233d185e2f3efd1332caf5bf4c95a772f178381edfe9bdf943ee101c57140b1cfc48baa788c868ea676
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
0.2.5
|
2
|
+
-----
|
3
|
+
- Responses now return FitStruct objects (inherit from OpenStruct).
|
4
|
+
|
5
|
+
- Ability to set default data return format by setting `raw_response` on Fitbyte::Client instance (defaults to using FitStruct objects). Can be overridden on each API call by specifying the `raw` boolean option.
|
6
|
+
|
1
7
|
0.2.4
|
2
8
|
-----
|
3
9
|
- Default result format for `get` calls now return OpenStruct objects, allowing for more convenient method-like attribute access. Specifying `raw: true` returns original JSON.
|
data/README.md
CHANGED
@@ -47,10 +47,10 @@ You're now authenticated and can make calls to Fitbit's API:
|
|
47
47
|
|
48
48
|
```ruby
|
49
49
|
client.food_logs Date.today
|
50
|
-
# => #<
|
50
|
+
# => #<Fitbyte::FitStruct foods=[#<Fitbyte::FitStruct isFavorite=true, logDate="2015-06-26", logId=1820, loggedFood=#<Fitbyte::FitStruct accessLevel="PUBLIC", amount=132.57, brand="", calories=752, ...]
|
51
51
|
```
|
52
52
|
|
53
|
-
If your
|
53
|
+
If your JSON library allows, the default format for resulting data returns OpenStruct-based FitStruct objects, allowing for more convenient method-like attribute access.
|
54
54
|
|
55
55
|
To return the original JSON, `raw: true` can be specified as an option:
|
56
56
|
|
data/lib/fitbyte.rb
CHANGED
data/lib/fitbyte/client.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "fitbyte/fitstruct"
|
1
2
|
require "fitbyte/helpers"
|
2
3
|
require "fitbyte/activities"
|
3
4
|
require "fitbyte/alarms"
|
@@ -11,25 +12,28 @@ require "fitbyte/water"
|
|
11
12
|
|
12
13
|
module Fitbyte
|
13
14
|
class Client
|
14
|
-
attr_accessor :api_version, :unit_system, :locale, :scope
|
15
|
+
attr_accessor :api_version, :unit_system, :locale, :scope, :raw_response
|
15
16
|
|
16
17
|
def initialize(opts)
|
17
18
|
missing_args = [:client_id, :client_secret, :redirect_uri] - opts.keys
|
18
|
-
|
19
19
|
raise ArgumentError, "Required arguments: #{missing.join(', ')}" if missing_args.size > 0
|
20
20
|
|
21
|
+
opts = defaults.merge(opts)
|
22
|
+
|
21
23
|
@client_id = opts[:client_id]
|
22
24
|
@client_secret = opts[:client_secret]
|
23
25
|
|
24
26
|
@redirect_uri = opts[:redirect_uri]
|
25
|
-
@site_url = opts[:site_url]
|
26
|
-
@authorize_url = opts[:authorize_url]
|
27
|
-
@token_url = opts[:token_url]
|
27
|
+
@site_url = opts[:site_url]
|
28
|
+
@authorize_url = opts[:authorize_url]
|
29
|
+
@token_url = opts[:token_url]
|
30
|
+
|
31
|
+
@unit_system = opts[:unit_system]
|
32
|
+
@locale = opts[:locale]
|
33
|
+
@scope = format_scope(opts[:scope])
|
28
34
|
|
29
|
-
@
|
30
|
-
@
|
31
|
-
@locale = opts[:locale] || defaults[:locale]
|
32
|
-
@api_version = "1"
|
35
|
+
@api_version = opts[:api_version]
|
36
|
+
@raw_response = opts[:raw_response]
|
33
37
|
|
34
38
|
@client = OAuth2::Client.new(@client_id, @client_secret, site: @site_url,
|
35
39
|
authorize_url: @authorize_url, token_url: @token_url)
|
@@ -66,8 +70,9 @@ module Fitbyte
|
|
66
70
|
end
|
67
71
|
|
68
72
|
def get(path, opts={})
|
73
|
+
raw = opts[:raw].nil? ? @raw_response : opts[:raw]
|
69
74
|
MultiJson.load(token.get(("#{@api_version}/" + path), headers: request_headers).response.body,
|
70
|
-
symbolize_keys: true, object_class: (
|
75
|
+
symbolize_keys: true, object_class: (FitStruct unless raw))
|
71
76
|
end
|
72
77
|
|
73
78
|
def defaults
|
@@ -77,7 +82,9 @@ module Fitbyte
|
|
77
82
|
token_url: "https://api.fitbit.com/oauth2/token",
|
78
83
|
scope: "activity nutrition profile settings sleep social weight",
|
79
84
|
unit_system: "en_US",
|
80
|
-
locale: "en_US"
|
85
|
+
locale: "en_US",
|
86
|
+
api_version: "1",
|
87
|
+
raw_response: false
|
81
88
|
}
|
82
89
|
end
|
83
90
|
end
|
data/lib/fitbyte/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fitbyte
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zoran Pesic
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/fitbyte/body.rb
|
91
91
|
- lib/fitbyte/client.rb
|
92
92
|
- lib/fitbyte/devices.rb
|
93
|
+
- lib/fitbyte/fitstruct.rb
|
93
94
|
- lib/fitbyte/food.rb
|
94
95
|
- lib/fitbyte/friends.rb
|
95
96
|
- lib/fitbyte/helpers.rb
|