fitbyte 0.2.3 → 0.2.4

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
2
  SHA1:
3
- metadata.gz: 2c55138f26ae4e67ce728f81f7458c9fd951f67d
4
- data.tar.gz: 5b31cb0811d68f489ea338266d269aefbd316b46
3
+ metadata.gz: 0e21658fcc86e8fea16b6de219039f1cdbd4a022
4
+ data.tar.gz: 54ed78187bf46a6dfcbbeab65537227d704c2aca
5
5
  SHA512:
6
- metadata.gz: 4606b123efddc148d64d238926f26cde4e6c304b66a32e57553f6f1ceeaffebde098932e8fe242ea9539dc6e2d6a094e0538585957260349809b3ad6f7cc7647
7
- data.tar.gz: 580553b0ccca421ee1d0a6adfdf7f6e25cb7ff74d5ddef4d4050b2ea44334ac84c64f64b84408c2f2f7dc82e1f5607c028843b30c1aecc2cfc8b811f87510b67
6
+ metadata.gz: ca64fab63f6ee50794649ac29a9d64741769c281724505a650eefcefe8012757d4f92bf61fe08068ff0297cbd82e5772b13042d635f98d24665514cd9a31c1b8
7
+ data.tar.gz: 830fed104faba746e6c341470d4e23b8add1dba28d8a97c8c6d66c30573b959e508188144bf7144aefb21506cbaeb9a6790621c9c6b548e83d440df09cae3da9
@@ -1,3 +1,7 @@
1
+ 0.2.4
2
+ -----
3
+ - Default result format for `get` calls now return OpenStruct objects, allowing for more convenient method-like attribute access. Specifying `raw: true` returns original JSON.
4
+
1
5
  0.2.3
2
6
  -----
3
7
  - Remove `require 'json'`
data/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/fitbyte.svg)](https://badge.fury.io/rb/fitbyte)
4
4
 
5
- This gem allows interaction with [Fitbit's REST API](https://dev.fitbit.com/docs/basics/), using the OAuth 2.0 protocol for user authorization.
5
+ This gem allows interaction with [Fitbit's REST API](https://dev.fitbit.com/docs/basics/).
6
6
 
7
- **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.
7
+ **NOTE:** Fitbit's API is currently in beta, and is in active development. Breaking changes to certain endpoints may be introduced during early development of this gem, until Fitbit's API solidifies.
8
8
 
9
9
  ## Installation
10
10
 
@@ -46,10 +46,19 @@ client.get_token(auth_code)
46
46
  You're now authenticated and can make calls to Fitbit's API:
47
47
 
48
48
  ```ruby
49
- client.food_logs
49
+ client.food_logs Date.today
50
+ # => #<OpenStruct foods=[#<OpenStruct isFavorite=true, logDate="2015-06-26", logId=1820, loggedFood=#<OpenStruct accessLevel="PUBLIC", amount=132.57, brand="", calories=752, ...]
51
+ ```
52
+
53
+ If your available JSON library allows, the default format for resulting data returns OpenStruct objects, allowing for more convenient method-like attribute access.
54
+
55
+ To return the original JSON, `raw: true` can be specified as an option:
56
+
57
+ ```ruby
58
+ client.food_logs Date.today, raw: true
50
59
  # => { :foods => [{ :isFavorite => true, :logDate => "2015-06-26", :logId => 1820, :loggedFood => { :accessLevel => "PUBLIC", :amount => 132.57, :brand => "", :calories => 752, ...}] }
51
60
  ```
52
61
 
53
62
  ## License
54
63
 
55
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
64
+ This gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Zoran Pesic"]
10
10
  spec.email = ["zoran1991@gmail.com"]
11
11
 
12
- spec.summary = %q{This gem allows interaction with Fitbit's REST API, using OAuth2 for user authorization.}
12
+ spec.summary = %q{This gem allows interaction with Fitbit's REST API.}
13
13
  spec.homepage = Fitbyte::REPO_URL
14
14
  spec.license = "MIT"
15
15
 
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "oauth2", "~> 1.0.0"
21
+ spec.add_runtime_dependency "oauth2", "~> 1.0"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.10"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,31 +1,31 @@
1
1
  module Fitbyte
2
2
  class Client
3
- def daily_activity_summary(date=Date.today)
4
- get("user/#{@user_id}/activities/date/#{format_date(date)}.json")
3
+ def daily_activity_summary(date=Date.today, opts={})
4
+ get("user/#{@user_id}/activities/date/#{format_date(date)}.json", opts)
5
5
  end
6
6
 
7
- def frequent_activities
8
- get("user/#{@user_id}/activities/frequent.json")
7
+ def frequent_activities(opts={})
8
+ get("user/#{@user_id}/activities/frequent.json", opts)
9
9
  end
10
10
 
11
- def favorite_activities
12
- get("user/#{@user_id}/activities/favorite.json")
11
+ def favorite_activities(opts={})
12
+ get("user/#{@user_id}/activities/favorite.json", opts)
13
13
  end
14
14
 
15
- def all_activities
16
- get("activities.json")
15
+ def all_activities(opts={})
16
+ get("activities.json", opts)
17
17
  end
18
18
 
19
- def lifetime_stats
20
- get("user/#{@user_id}/activities.json")
19
+ def lifetime_stats(opts={})
20
+ get("user/#{@user_id}/activities.json", opts)
21
21
  end
22
22
 
23
- def daily_goals
24
- get("user/#{@user_id}/activities/goals/daily.json")
23
+ def daily_goals(opts={})
24
+ get("user/#{@user_id}/activities/goals/daily.json", opts)
25
25
  end
26
26
 
27
- def weekly_goals
28
- get("user/#{@user_id}/activities/goals/weekly.json")
27
+ def weekly_goals(opts={})
28
+ get("user/#{@user_id}/activities/goals/weekly.json", opts)
29
29
  end
30
30
  end
31
31
  end
@@ -1,7 +1,7 @@
1
1
  module Fitbyte
2
2
  class Client
3
- def alarms(tracker_id)
4
- get("user/#{@user_id}/devices/tracker/#{tracker_id}/alarms.json")
3
+ def alarms(tracker_id, opts={})
4
+ get("user/#{@user_id}/devices/tracker/#{tracker_id}/alarms.json", opts)
5
5
  end
6
6
  end
7
7
  end
@@ -1,19 +1,19 @@
1
1
  module Fitbyte
2
2
  class Client
3
- def weight_logs(date=Date.today)
4
- get("user/-/body/log/weight/date/#{format_date(date)}.json")
3
+ def weight_logs(date=Date.today, opts={})
4
+ get("user/-/body/log/weight/date/#{format_date(date)}.json", opts)
5
5
  end
6
6
 
7
- def body_fat_logs(date=Date.today)
8
- get("user/-/body/log/fat/date/#{format_date(date)}.json")
7
+ def body_fat_logs(date=Date.today, opts={})
8
+ get("user/-/body/log/fat/date/#{format_date(date)}.json", opts)
9
9
  end
10
10
 
11
- def weight_goals
12
- get("user/-/body/log/weight/goal.json")
11
+ def weight_goals(opts={})
12
+ get("user/-/body/log/weight/goal.json", opts)
13
13
  end
14
14
 
15
- def body_fat_goals
16
- get("user/-/body/log/fat/goal.json")
15
+ def body_fat_goals(opts={})
16
+ get("user/-/body/log/fat/goal.json", opts)
17
17
  end
18
18
  end
19
19
  end
@@ -13,22 +13,22 @@ module Fitbyte
13
13
  class Client
14
14
  attr_accessor :api_version, :unit_system, :locale, :scope
15
15
 
16
- def initialize(options)
17
- missing_args = [:client_id, :client_secret, :redirect_uri] - options.keys
16
+ def initialize(opts)
17
+ missing_args = [:client_id, :client_secret, :redirect_uri] - opts.keys
18
18
 
19
19
  raise ArgumentError, "Required arguments: #{missing.join(', ')}" if missing_args.size > 0
20
20
 
21
- @client_id = options[:client_id]
22
- @client_secret = options[:client_secret]
21
+ @client_id = opts[:client_id]
22
+ @client_secret = opts[:client_secret]
23
23
 
24
- @redirect_uri = options[:redirect_uri]
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]
24
+ @redirect_uri = opts[:redirect_uri]
25
+ @site_url = opts[:site_url] || defaults[:site_url]
26
+ @authorize_url = opts[:authorize_url] || defaults[:authorize_url]
27
+ @token_url = opts[:token_url] || defaults[:token_url]
28
28
 
29
- @scope = format_scope(options[:scope]) || defaults[:scope]
30
- @unit_system = options[:unit_system] || defaults[:unit_system]
31
- @locale = options[:locale] || defaults[:locale]
29
+ @scope = format_scope(opts[:scope]) || defaults[:scope]
30
+ @unit_system = opts[:unit_system] || defaults[:unit_system]
31
+ @locale = opts[:locale] || defaults[:locale]
32
32
  @api_version = "1"
33
33
 
34
34
  @client = OAuth2::Client.new(@client_id, @client_secret, site: @site_url,
@@ -65,8 +65,9 @@ module Fitbyte
65
65
  }
66
66
  end
67
67
 
68
- def get(path)
69
- MultiJson.load(token.get(("#{@api_version}/" + path), headers: request_headers).response.body, symbolize_keys: true)
68
+ def get(path, opts={})
69
+ MultiJson.load(token.get(("#{@api_version}/" + path), headers: request_headers).response.body,
70
+ symbolize_keys: true, object_class: (OpenStruct unless opts[:raw]))
70
71
  end
71
72
 
72
73
  def defaults
@@ -1,7 +1,7 @@
1
1
  module Fitbyte
2
2
  class Client
3
- def devices
4
- get("user/#{@user_id}/devices.json")
3
+ def devices(opts={})
4
+ get("user/#{@user_id}/devices.json", opts)
5
5
  end
6
6
  end
7
7
  end
@@ -1,23 +1,23 @@
1
1
  module Fitbyte
2
2
  class Client
3
- def food_logs(date=Date.today)
4
- get("user/#{@user_id}/foods/log/date/#{format_date(date)}.json")
3
+ def food_logs(date=Date.today, opts={})
4
+ get("user/#{@user_id}/foods/log/date/#{format_date(date)}.json", opts)
5
5
  end
6
6
 
7
- def recent_foods
8
- get("user/#{@user_id}/foods/recent.json")
7
+ def recent_foods(opts={})
8
+ get("user/#{@user_id}/foods/log/recent.json", opts)
9
9
  end
10
10
 
11
- def frequent_foods
12
- get("user/#{@user_id}/foods/log/frequent.json")
11
+ def frequent_foods(opts={})
12
+ get("user/#{@user_id}/foods/log/frequent.json", opts)
13
13
  end
14
14
 
15
- def favorite_foods
16
- get("user/#{@user_id}/foods/log/favorite.json")
15
+ def favorite_foods(opts={})
16
+ get("user/#{@user_id}/foods/log/favorite.json", opts)
17
17
  end
18
18
 
19
- def food_goals
20
- get("user/#{@user_id}/foods/log/goal.json")
19
+ def food_goals(opts={})
20
+ get("user/#{@user_id}/foods/log/goal.json", opts)
21
21
  end
22
22
  end
23
23
  end
@@ -1,11 +1,11 @@
1
1
  module Fitbyte
2
2
  class Client
3
- def friends
4
- get("user/#{@user_id}/friends.json")
3
+ def friends(opts={})
4
+ get("user/#{@user_id}/friends.json", opts)
5
5
  end
6
6
 
7
- def friends_leaderboard
8
- get("user/#{@user_id}/friends/leaderboard.json")
7
+ def friends_leaderboard(opts={})
8
+ get("user/#{@user_id}/friends/leaderboard.json", opts)
9
9
  end
10
10
  end
11
11
  end
@@ -1,7 +1,7 @@
1
1
  module Fitbyte
2
2
  class Client
3
- def sleep_logs(date=Date.today)
4
- get("user/#{@user_id}/sleep/date/#{format_date(date)}.json")
3
+ def sleep_logs(date=Date.today, opts={})
4
+ get("user/#{@user_id}/sleep/date/#{format_date(date)}.json", opts)
5
5
  end
6
6
  end
7
7
  end
@@ -1,11 +1,11 @@
1
1
  module Fitbyte
2
2
  class Client
3
- def profile
4
- get("user/#{@user_id}/profile.json")
3
+ def profile(opts={})
4
+ get("user/#{@user_id}/profile.json", opts)
5
5
  end
6
6
 
7
- def badges
8
- get("user/#{@user_id}/badges.json")
7
+ def badges(opts={})
8
+ get("user/#{@user_id}/badges.json", opts)
9
9
  end
10
10
  end
11
11
  end
@@ -1,4 +1,4 @@
1
1
  module Fitbyte
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  REPO_URL = "https://github.com/zokioki/fitbyte"
4
4
  end
@@ -1,7 +1,7 @@
1
1
  module Fitbyte
2
2
  class Client
3
- def water_logs(date=Date.today)
4
- get("user/#{@user_id}/foods/log/water/date/#{format_date(date)}.json")
3
+ def water_logs(date=Date.today, opts={})
4
+ get("user/#{@user_id}/foods/log/water/date/#{format_date(date)}.json", opts)
5
5
  end
6
6
  end
7
7
  end
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.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zoran Pesic
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-13 00:00:00.000000000 Z
11
+ date: 2015-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.0
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -120,6 +120,5 @@ rubyforge_project:
120
120
  rubygems_version: 2.4.5
121
121
  signing_key:
122
122
  specification_version: 4
123
- summary: This gem allows interaction with Fitbit's REST API, using OAuth2 for user
124
- authorization.
123
+ summary: This gem allows interaction with Fitbit's REST API.
125
124
  test_files: []