fitbyte 0.2.4 → 0.2.5

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: 0e21658fcc86e8fea16b6de219039f1cdbd4a022
4
- data.tar.gz: 54ed78187bf46a6dfcbbeab65537227d704c2aca
3
+ metadata.gz: 2288b2aa276802af1ee13b8203f7f95bb58c871d
4
+ data.tar.gz: 15e907b187d26a2faaeb8132506edc32830ca9ab
5
5
  SHA512:
6
- metadata.gz: ca64fab63f6ee50794649ac29a9d64741769c281724505a650eefcefe8012757d4f92bf61fe08068ff0297cbd82e5772b13042d635f98d24665514cd9a31c1b8
7
- data.tar.gz: 830fed104faba746e6c341470d4e23b8add1dba28d8a97c8c6d66c30573b959e508188144bf7144aefb21506cbaeb9a6790621c9c6b548e83d440df09cae3da9
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
- # => #<OpenStruct foods=[#<OpenStruct isFavorite=true, logDate="2015-06-26", logId=1820, loggedFood=#<OpenStruct accessLevel="PUBLIC", amount=132.57, brand="", calories=752, ...]
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 available JSON library allows, the default format for resulting data returns OpenStruct objects, allowing for more convenient method-like attribute access.
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
@@ -1,5 +1,6 @@
1
1
  require "oauth2"
2
2
  require "date"
3
+ require "ostruct"
3
4
  require "fitbyte/version"
4
5
  require "fitbyte/client"
5
6
 
@@ -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] || defaults[:site_url]
26
- @authorize_url = opts[:authorize_url] || defaults[:authorize_url]
27
- @token_url = opts[:token_url] || defaults[: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
- @scope = format_scope(opts[:scope]) || defaults[:scope]
30
- @unit_system = opts[:unit_system] || defaults[:unit_system]
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: (OpenStruct unless opts[:raw]))
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
@@ -0,0 +1,3 @@
1
+ module Fitbyte
2
+ class FitStruct < OpenStruct; end
3
+ end
@@ -1,4 +1,4 @@
1
1
  module Fitbyte
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  REPO_URL = "https://github.com/zokioki/fitbyte"
4
4
  end
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
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