fitgem_oauth2 0.0.5 → 0.0.6

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: 0efccedfb12ab6108ad90cba0ccc374135d0625a
4
- data.tar.gz: a4fa19ece3dea0919916967fcc5ac351d01cf02f
3
+ metadata.gz: fd516d574175e9fe9b90dac5242b1222b030de67
4
+ data.tar.gz: 789803a5149cc302e52db432445a805a45ab028e
5
5
  SHA512:
6
- metadata.gz: 8138725e9b7a274f2a55043240664173030e26fd0bd5c5c9a84a26c3b328721715276f28f6d4f2269748df935d13cdc07f7f79288a3f3e58e99f006feb8b87a6
7
- data.tar.gz: 84c1594d94978aec4b40a61a17cfca9bb5abe281e51af6eca0d2f7fa969f3d329bfd36f8b6ed26a568e08f27b396e86cf3e3e4831f5d474778c37c2eee31d43e
6
+ metadata.gz: 9e73b564bc27fcbb69d86632f7c8a3686a92f661048e75381f36322ea020e33425f80c666b88e7b92ed51db3b57b122ecbaaf0eebde0f02db443e517a6940894
7
+ data.tar.gz: 11cf3e2e0de03d356efba62cdcfbd0c80c38bb0386eada5cddf98635ff375fcefa654b354ddc59b6ada5136c3ef02e37dc6a059594185cd440d5351455be21fe
@@ -1,8 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ $:.unshift File.expand_path('../lib', __FILE__)
4
+ require 'fitgem_oauth2/version'
5
+
1
6
  Gem::Specification.new do |s|
2
7
  s.name = 'fitgem_oauth2'
3
- s.version = '0.0.5'
4
- s.date = '2016-01-18'
5
- s.summary = "This gem allows requesting data from Fitbit API using OAuth2"
8
+ s.version = FitgemOauth2::VERSION
9
+ s.date = Date.today.to_s
10
+ s.summary = "Fitbit API client library"
6
11
  s.description = "This gem allows requesting data from Fitbit API using OAuth2"
7
12
  s.authors = ["Ankit Gupta"]
8
13
  s.email = 'ankit.gupta2801@gmail.com'
@@ -11,4 +16,6 @@ Gem::Specification.new do |s|
11
16
  s.license = 'MIT'
12
17
 
13
18
  s.add_runtime_dependency 'faraday', '~> 0.9'
19
+ s.add_development_dependency "rspec", '~> 3.4'
20
+ s.add_development_dependency "dotenv", '~> 2.1'
14
21
  end
@@ -1,14 +1,46 @@
1
1
  module FitgemOauth2
2
2
  class Client
3
3
 
4
+ # ======================================
5
+ # Activities Retrieval Methods
6
+ # ======================================
7
+
8
+ allowed_activity_paths = %w("calories" "caloriesBMR" "steps" "distance" "floors" "elevation" "minutesSedentary" "minutesLightlyActive" "minutesFairlyActive" "minutesVeryActive" "activityCaloriestracker/calories" "tracker/steps" "tracker/distance" "tracker/floors" "tracker/elevation" "tracker/minutesSedentary" "tracker/minutesLightlyActive" "tracker/minutesFairlyActive" "tracker/minutesVeryActive" "tracker/activityCalories")
9
+
10
+ allowed_activity_periods = %w("1d" "7d" "30d" "1w" "1m" "3m" "6m" "1y" "max")
11
+
4
12
  def activities_on_date(date)
5
13
  get_call("1/user/#{user_id}/activities/date/#{format_date(date)}.json")
6
14
  end
7
15
 
16
+ def activities_in_period(resource_path, date, period)
17
+ if activity_resource_path?(resource_path)
18
+ if activity_period?(period)
19
+ get_activities(resource_path, resource_path, period)
20
+ else
21
+ raise FitgemOauth2::InvalidArgumentError, "period should be one of #{allowed_activity_periods}"
22
+ end
23
+ else
24
+ raise FitgemOauth2::InvalidArgumentError, "resource_path should be one of #{allowed_activity_paths}"
25
+ end
26
+ end
27
+
28
+ def activities_in_range(resource_path, base_date, end_date)
29
+ if activity_resource_path?(resource_path)
30
+ get_activities(resource_path, format_date(base_date), format_dat(end_date))
31
+ else
32
+ raise FitgemOauth2::InvalidArgumentError, "resource_path should be one of #{allowed_activity_paths}"
33
+ end
34
+ end
35
+
36
+ # <b>DEPRECATED</b> Please use <b>activities_on_date</b> instead
8
37
  def calories_on_date(date)
9
38
  get_call("1/user/#{user_id}/activities/calories/date/#{format_date(date)}/1d.json")
10
39
  end
11
40
 
41
+ # ======================================
42
+ # Intraday Series
43
+ # ======================================
12
44
 
13
45
  def intraday_time_series(opts)
14
46
  unless opts[:resource] && [:calories, :steps, :distance, :floors, :elevation].include?(opts[:resource])
@@ -38,5 +70,59 @@ module FitgemOauth2
38
70
  end
39
71
  get_call(resource_path)
40
72
  end
73
+
74
+ # ======================================
75
+ # Activity Types
76
+ # ======================================
77
+ def activities
78
+ get_call("1/activities.json")
79
+ end
80
+
81
+ def activity(id)
82
+ get_call("1/activities/#{id}.json")
83
+ end
84
+
85
+ def frequent_activities
86
+ get_call("1/user/#{@user_id}/activities/frequent.json")
87
+ end
88
+
89
+ def recent_activities
90
+ get_call("1/user/#{@user_id}/activities/recent.json")
91
+ end
92
+
93
+ def favorite_activities
94
+ get_call("1/user/#{@user_id}/activities/favorite.json")
95
+ end
96
+
97
+ # ======================================
98
+ # Activity Goals
99
+ # ======================================
100
+
101
+ def goals(period)
102
+ unless period && [:daily, :weekly].include?(period)
103
+ raise FitgemOauth2::InvalidArgumentError, "Goal period should either be 'daily' or 'weekly'"
104
+ end
105
+ end
106
+
107
+ def lifetime_stats
108
+ get_call("1/user/#{@user_id}/activities.json")
109
+ end
110
+
111
+ # ======================================
112
+ # Private Methods
113
+ # ======================================
114
+
115
+ private
116
+ def get_activities(resource_path, first, second)
117
+ get_call("1/user/#{user_id}/#{resource_path}/date/#{first}/#{second}.json")
118
+ end
119
+
120
+ def activity_resource_path?(resource_path)
121
+ return resource_path && allowed_activity_paths.include?(resource_path)
122
+ end
123
+
124
+ def activity_period?(period)
125
+ return period && allowed_activity_periods.include?(period)
126
+ end
41
127
  end
42
128
  end
@@ -0,0 +1,69 @@
1
+ module FitgemOauth2
2
+ class Client
3
+ fat_periods = %w("1d" "7d" "1w" "1m")
4
+ weight_periods = %("1d" "7d" "30d" "1w" "1m")
5
+ body_goals = %("fat" "weight")
6
+ # ======================================
7
+ # Boday Fat API
8
+ # ======================================
9
+
10
+ def fat_on_date(date)
11
+ get_call("/1/user/#{@user_id}/body/log/fat/date/#{format_date(date)}.json")
12
+ end
13
+
14
+ def fat_for_period(base_date, period)
15
+ if fat_period?(period)
16
+ get_call("1/user/#{@user_id}/body/log/fat/date/#{format_date(start_date)}/#{period}.json")
17
+ else
18
+ raise FitgemOauth2::InvalidArgumentError, "period should be one of #{fat_periods}"
19
+ end
20
+ end
21
+
22
+ def fat_for_range(start_date, end_date)
23
+ get_call("1/user/#{@user_id}/body/log/fat/date/#{format_date(start_date)}/#{format_date(end_date)}.json")
24
+ end
25
+
26
+ # ======================================
27
+ # Body Goals API
28
+ # ======================================
29
+
30
+ def body_goal(type)
31
+ if type && body_goals.include?(type)
32
+ get_call("1/user/#{@user_id}/body/log/#{type}/goal.json")
33
+ else
34
+ raise FitgemOauth2::InvalidArgumentError, "goal type should be one of #{body_goals}"
35
+ end
36
+ end
37
+
38
+ # ======================================
39
+ # Body Weight API
40
+ # ======================================
41
+
42
+ def weight_on_date(date)
43
+ get_call("/1/user/#{@user_id}/body/log/weight/date/#{format_date(date)}.json")
44
+ end
45
+
46
+ def weight_for_period(base_date, period)
47
+ if weight_period?(period)
48
+ get_call("1/user/#{@user_id}/body/log/weight/date/#{format_date(start_date)}/#{period}.json")
49
+ else
50
+ raise FitgemOauth2::InvalidArgumentError, "period should be one of #{weight_periods}"
51
+ end
52
+ end
53
+
54
+ def weight_for_range(start_date, end_date)
55
+ get_call("1/user/#{@user_id}/body/log/weight/date/#{format_date(start_date)}/#{format_date(end_date)}.json")
56
+ end
57
+
58
+
59
+ private
60
+ def fat_period?(period)
61
+ return period && fat_periods.include?(period)
62
+ end
63
+
64
+ def weight_period?(period)
65
+ return period && weight_periods.include?(period)
66
+ end
67
+
68
+ end
69
+ end
@@ -1,11 +1,11 @@
1
1
  require 'fitgem_oauth2/activity.rb'
2
+ require 'fitgem_oauth2/body_measurements.rb'
2
3
  require 'fitgem_oauth2/errors.rb'
3
4
  require 'fitgem_oauth2/sleep.rb'
4
5
  require 'fitgem_oauth2/steps.rb'
5
6
  require 'fitgem_oauth2/users.rb'
6
7
  require 'fitgem_oauth2/utils.rb'
7
-
8
-
8
+ require 'fitgem_oauth2/version.rb'
9
9
 
10
10
  require 'base64'
11
11
  require 'faraday'
@@ -39,7 +39,7 @@ module FitgemOauth2
39
39
 
40
40
  @user_id = opts[:user_id]
41
41
  if @user_id.nil?
42
- puts "TODO. Raise an exception due to missing fitbit user id"
42
+ @user_id = "-"
43
43
  end
44
44
 
45
45
  @connection = Faraday.new("https://api.fitbit.com")
@@ -0,0 +1,3 @@
1
+ module FitgemOauth2
2
+ VERSION = '0.0.6'
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fitgem_oauth2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ankit Gupta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-18 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
27
55
  description: This gem allows requesting data from Fitbit API using OAuth2
28
56
  email: ankit.gupta2801@gmail.com
29
57
  executables: []
@@ -33,12 +61,14 @@ files:
33
61
  - fitgem_oauth2.gemspec
34
62
  - lib/fitgem_oauth2.rb
35
63
  - lib/fitgem_oauth2/activity.rb
64
+ - lib/fitgem_oauth2/body_measurements.rb
36
65
  - lib/fitgem_oauth2/client.rb
37
66
  - lib/fitgem_oauth2/errors.rb
38
67
  - lib/fitgem_oauth2/sleep.rb
39
68
  - lib/fitgem_oauth2/steps.rb
40
69
  - lib/fitgem_oauth2/users.rb
41
70
  - lib/fitgem_oauth2/utils.rb
71
+ - lib/fitgem_oauth2/version.rb
42
72
  homepage: http://rubygems.org/gems/fitgem_oauth2
43
73
  licenses:
44
74
  - MIT
@@ -62,6 +92,5 @@ rubyforge_project:
62
92
  rubygems_version: 2.4.6
63
93
  signing_key:
64
94
  specification_version: 4
65
- summary: This gem allows requesting data from Fitbit API using OAuth2
95
+ summary: Fitbit API client library
66
96
  test_files: []
67
- has_rdoc: