fitgem_oauth2 0.0.3 → 0.0.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: 7c13af1faf691c9fd94171063bbedf8a90b74945
4
- data.tar.gz: 95ce7b1b9c9f4740c98202d7ffa851dc2e68c235
3
+ metadata.gz: 0efccedfb12ab6108ad90cba0ccc374135d0625a
4
+ data.tar.gz: a4fa19ece3dea0919916967fcc5ac351d01cf02f
5
5
  SHA512:
6
- metadata.gz: c197aa0391e56664f865c63ac149e07b62b807872f1a8a4d13b78c3e6288d21cd588f8d222d026a7633c54bec1bf7d8fff36d7c05c3bb464d39bd54f1c7ec7cd
7
- data.tar.gz: 8c68e5a17c6d811eecf96dcf5fe17bedd7de553a9948b30b1e039d6661f707a1bf955df22ebfec8bf9b440bce7220a681e0add22207855b55e958fcbbb85bfc9
6
+ metadata.gz: 8138725e9b7a274f2a55043240664173030e26fd0bd5c5c9a84a26c3b328721715276f28f6d4f2269748df935d13cdc07f7f79288a3f3e58e99f006feb8b87a6
7
+ data.tar.gz: 84c1594d94978aec4b40a61a17cfca9bb5abe281e51af6eca0d2f7fa969f3d329bfd36f8b6ed26a568e08f27b396e86cf3e3e4831f5d474778c37c2eee31d43e
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'fitgem_oauth2'
3
- s.version = '0.0.3'
3
+ s.version = '0.0.5'
4
4
  s.date = '2016-01-18'
5
5
  s.summary = "This gem allows requesting data from Fitbit API using OAuth2"
6
6
  s.description = "This gem allows requesting data from Fitbit API using OAuth2"
@@ -4,6 +4,39 @@ module FitgemOauth2
4
4
  def activities_on_date(date)
5
5
  get_call("1/user/#{user_id}/activities/date/#{format_date(date)}.json")
6
6
  end
7
-
7
+
8
+ def calories_on_date(date)
9
+ get_call("1/user/#{user_id}/activities/calories/date/#{format_date(date)}/1d.json")
10
+ end
11
+
12
+
13
+ def intraday_time_series(opts)
14
+ unless opts[:resource] && [:calories, :steps, :distance, :floors, :elevation].include?(opts[:resource])
15
+ raise FitgemOauth2::InvalidArgumentError, 'Must specify resource to fetch intraday time series data for. One of (:calories, :steps, :distance, :floors, or :elevation) is required.'
16
+ end
17
+
18
+ unless opts[:date]
19
+ raise FitgemOauth2::InvalidArgumentError, 'Must specify the date to fetch intraday time series data for.'
20
+ end
21
+
22
+ unless opts[:detailLevel] && %w(1min 15min).include?(opts[:detailLevel])
23
+ raise FitgemOauth2::InvalidArgumentError, 'Must specify the data resolution to fetch intraday time series data for. One of (\"1d\" or \"15min\") is required.'
24
+ end
25
+
26
+ resource = opts.delete(:resource)
27
+ date = format_date(opts.delete(:date))
28
+ detail_level = opts.delete(:detailLevel)
29
+ time_window_specified = opts[:startTime] || opts[:endTime]
30
+ resource_path = "1/user/#{@user_id}/activities/"
31
+
32
+ if time_window_specified
33
+ start_time = format_time(opts.delete(:startTime))
34
+ end_time = format_time(opts.delete(:endTime))
35
+ resource_path += "#{resource}/date/#{date}/1d/#{detail_level}/time/#{start_time}/#{end_time}.json"
36
+ else
37
+ resource_path += "#{resource}/date/#{date}/1d/#{detail_level}.json"
38
+ end
39
+ get_call(resource_path)
40
+ end
8
41
  end
9
42
  end
@@ -1,10 +1,11 @@
1
1
  require 'fitgem_oauth2/activity.rb'
2
+ require 'fitgem_oauth2/errors.rb'
2
3
  require 'fitgem_oauth2/sleep.rb'
3
4
  require 'fitgem_oauth2/steps.rb'
4
-
5
+ require 'fitgem_oauth2/users.rb'
5
6
  require 'fitgem_oauth2/utils.rb'
6
7
 
7
- require 'fitgem_oauth2/errors.rb'
8
+
8
9
 
9
10
  require 'base64'
10
11
  require 'faraday'
@@ -71,7 +72,7 @@ module FitgemOauth2
71
72
  request.params['grant_type'] = "refresh_token"
72
73
  request.params['refresh_token'] = refresh_token
73
74
  end
74
- response.body
75
+ return JSON.parse(response.body)
75
76
  end
76
77
 
77
78
  private
@@ -1,7 +1,10 @@
1
1
  module FitgemOauth2
2
2
  class InvalidDateArgument < ArgumentError
3
3
  end
4
-
4
+
5
+ class InvalidArgumentError < ArgumentError
6
+ end
7
+
5
8
  # HTTP errors
6
9
  class BadRequestError < StandardError
7
10
  end
@@ -0,0 +1,7 @@
1
+ module FitgemOauth2
2
+ class Client
3
+ def user_info()
4
+ get_call("1/user/#{user_id}/profile.json")
5
+ end
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fitgem_oauth2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ankit Gupta
@@ -37,6 +37,7 @@ files:
37
37
  - lib/fitgem_oauth2/errors.rb
38
38
  - lib/fitgem_oauth2/sleep.rb
39
39
  - lib/fitgem_oauth2/steps.rb
40
+ - lib/fitgem_oauth2/users.rb
40
41
  - lib/fitgem_oauth2/utils.rb
41
42
  homepage: http://rubygems.org/gems/fitgem_oauth2
42
43
  licenses: