fitgem-app 2.2.0 → 2.3.0
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/bin/fitgem +69 -32
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97d44a1d25f258f2211c4296ab1d54b32c11ced4
|
4
|
+
data.tar.gz: 1481da14324a20f5ea0eec3bd289c39bf4448de4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ae5df19fcf24d0cdf84a567f3c532c01737a0e9a29363dc2674a88c66a30ac6e993da1fac31055709cbcd51eb2c1410215002a0cd7501d8f77fff00ae5a6892
|
7
|
+
data.tar.gz: a769a150e741a19f2db9c211c682346efbb788368ae08524f5e08c0a436ac327ad13ca5f5071ac08926ab90d4c87168bfa4c0c6ef91b7e0b02ad66bb7f1a5978
|
data/bin/fitgem
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
require 'httparty'
|
3
3
|
require 'multi_json'
|
4
4
|
|
5
|
+
class APIError < RuntimeError
|
6
|
+
end
|
7
|
+
|
5
8
|
class FitbitAccount
|
6
9
|
include HTTParty
|
7
10
|
@@base_uri = 'api.fitbit.com/1/user'
|
@@ -9,24 +12,33 @@ class FitbitAccount
|
|
9
12
|
def initialize()
|
10
13
|
@access_token = `echo -n $FB_ACCESS_TOKEN`
|
11
14
|
@user_id = `echo -n $FB_USER_ID`
|
15
|
+
end
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
def error_check
|
18
|
+
if @parsed_response["success"] == false
|
19
|
+
case @parsed_response.code
|
20
|
+
when 401
|
21
|
+
if @parsed_response["errors"][0]["errorType"] == "invalid_client"
|
22
|
+
puts "Please report this issue on the FitGem (juniorRubyist/fitgem) issue tracker on Github."
|
23
|
+
end
|
24
|
+
when 403
|
25
|
+
if @parsed_response["errors"][0]["errorType"] == "insufficient_scope"
|
26
|
+
puts "Please report this issue on the FitGem (juniorRubyist/fitgem) issue tracker on Github."
|
27
|
+
else
|
28
|
+
puts "You may need to modify your privacy settings. Then, try again."
|
29
|
+
end
|
30
|
+
when 404
|
31
|
+
puts "Please report this issue on the FitGem (juniorRubyist/fitgem) issue tracker on Github."
|
32
|
+
when 429
|
33
|
+
puts "Oops, you've exceeded your limit of 150 requests per hour. Try again on the :00."
|
34
|
+
exit
|
35
|
+
when 500...600
|
36
|
+
puts "Oh no, there might be a Fitbit service outage! Try again soon."
|
37
|
+
exit
|
38
|
+
else
|
39
|
+
puts "Please report this issue on the FitGem (juniorRubyist/fitgem) issue tracker on Github."
|
40
|
+
end
|
41
|
+
raise APIError, @parsed_response
|
30
42
|
end
|
31
43
|
end
|
32
44
|
|
@@ -34,6 +46,7 @@ class FitbitAccount
|
|
34
46
|
@response = self.class.get("https://#{@@base_uri}/#{@user_id}/activities/steps/date/today/1d/1min.json",
|
35
47
|
:headers => {"Authorization" => "Bearer #{@access_token}"})
|
36
48
|
@parsed_response = MultiJson.load(@response.body)
|
49
|
+
self.error_check
|
37
50
|
@parsed_response = @parsed_response["activities-steps"][0]["value"].to_i
|
38
51
|
end
|
39
52
|
|
@@ -41,6 +54,7 @@ class FitbitAccount
|
|
41
54
|
@response = self.class.get("https://#{@@base_uri}/#{@user_id}/activities/floors/date/today/1d/1min.json",
|
42
55
|
:headers => {"Authorization" => "Bearer #{@access_token}"})
|
43
56
|
@parsed_response = MultiJson.load(@response.body)
|
57
|
+
self.error_check
|
44
58
|
@parsed_response = @parsed_response["activities-floors"][0]["value"].to_i
|
45
59
|
end
|
46
60
|
|
@@ -48,6 +62,7 @@ class FitbitAccount
|
|
48
62
|
@response = self.class.get("https://#{@@base_uri}/#{@user_id}/activities/calories/date/today/1d/1min.json",
|
49
63
|
:headers => {"Authorization" => "Bearer #{@access_token}"})
|
50
64
|
@parsed_response = MultiJson.load(@response.body)
|
65
|
+
self.error_check
|
51
66
|
@parsed_response = @parsed_response["activities-calories"][0]["value"].to_i
|
52
67
|
end
|
53
68
|
|
@@ -55,6 +70,7 @@ class FitbitAccount
|
|
55
70
|
@response = self.class.get("https://#{@@base_uri}/#{@user_id}/activities/distance/date/today/1d/1min.json",
|
56
71
|
:headers => {"Authorization" => "Bearer #{@access_token}"})
|
57
72
|
@parsed_response = MultiJson.load(@response.body)
|
73
|
+
self.error_check
|
58
74
|
@parsed_response = @parsed_response["activities-distance"][0]["value"]
|
59
75
|
end
|
60
76
|
|
@@ -92,23 +108,44 @@ class FitbitAccount
|
|
92
108
|
puts "AUTHOR"
|
93
109
|
puts " Joseph Geis <geis28@gmail.com> (see files AUTHORS for details)."
|
94
110
|
end
|
111
|
+
|
112
|
+
def setup
|
113
|
+
if @access_token == "" && @user_id == ""
|
114
|
+
@configuration = File.new(ENV['HOME']+"/.fitgem", "a+")
|
115
|
+
@configuration.puts("")
|
116
|
+
|
117
|
+
print "Copy your Access Token: "
|
118
|
+
@access_token = gets.chomp
|
119
|
+
@default_shell.puts("export FB_ACCESS_TOKEN=\"#{@access_token}\"")
|
120
|
+
|
121
|
+
print "Copy your User ID: "
|
122
|
+
@user_id = gets.chomp
|
123
|
+
@default_shell.puts("export FB_USER_ID=\"#{@user_id}\"")
|
124
|
+
|
125
|
+
puts "Alright sparky! Close your terminal or logout and login to get started."
|
126
|
+
else
|
127
|
+
puts "Hey, you've already finished setup!"
|
128
|
+
end
|
129
|
+
end
|
95
130
|
end
|
96
131
|
|
97
132
|
fitgem = FitbitAccount.new()
|
98
133
|
choice = ARGV[0]
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
134
|
+
unless `echo -n $TRAVIS_CI` == "true"
|
135
|
+
case choice
|
136
|
+
when 'steps', 's'
|
137
|
+
puts "#{fitgem.steps} steps taken"
|
138
|
+
when 'distance', 'd'
|
139
|
+
puts "#{fitgem.distance} miles walked"
|
140
|
+
when 'floors', 'f'
|
141
|
+
puts "#{fitgem.floors} floors climbed"
|
142
|
+
when 'calories', 'c'
|
143
|
+
puts "#{fitgem.calories} calories burned"
|
144
|
+
when 'full', 'all', 'a'
|
145
|
+
fitgem.full_report
|
146
|
+
when 'help', 'h', '?'
|
147
|
+
fitgem.help
|
148
|
+
else
|
149
|
+
puts "Are you lost?, run fitgem help"
|
150
|
+
end
|
114
151
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fitgem-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Geis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|