fitgem 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -1
- data/fitgem.gemspec +1 -3
- data/lib/fitgem.rb +1 -1
- data/lib/fitgem/activities.rb +20 -15
- data/lib/fitgem/client.rb +6 -5
- data/lib/fitgem/foods.rb +28 -13
- data/lib/fitgem/units.rb +40 -2
- metadata +3 -3
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm
|
1
|
+
rvm 1.9.2@fitbit --create
|
data/fitgem.gemspec
CHANGED
@@ -2,11 +2,9 @@
|
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
3
|
$:.push File.join(File.dirname(__FILE__), '.', 'lib')
|
4
4
|
|
5
|
-
require 'fitgem'
|
6
|
-
|
7
5
|
Gem::Specification.new do |s|
|
8
6
|
s.name = "fitgem"
|
9
|
-
s.version =
|
7
|
+
s.version = "0.3.1"
|
10
8
|
s.platform = Gem::Platform::RUBY
|
11
9
|
s.authors = ["Zachery Moneypenny"]
|
12
10
|
s.email = ["fitgem@whazzmaster.com"]
|
data/lib/fitgem.rb
CHANGED
data/lib/fitgem/activities.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
module Fitgem
|
2
2
|
class Client
|
3
|
-
|
3
|
+
|
4
4
|
# ==========================================
|
5
5
|
# Activity Retrieval Methods
|
6
6
|
# ==========================================
|
7
7
|
def activities_on_date(date)
|
8
8
|
get("/user/#{@user_id}/activities/date/#{format_date(date)}.json")
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def frequent_activities()
|
12
12
|
get("/user/#{@user_id}/activities/frequent.json")
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def recent_activities()
|
16
16
|
get("/user/#{@user_id}/activities/recent.json")
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def favorite_activities()
|
20
20
|
get("/user/#{@user_id}/activities/favorite.json")
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def activity(id, options ={})
|
24
24
|
get("/activities/#{id}.json")
|
25
25
|
end
|
@@ -27,33 +27,38 @@ module Fitgem
|
|
27
27
|
# ==========================================
|
28
28
|
# Activity Update Methods
|
29
29
|
# ==========================================
|
30
|
-
|
30
|
+
|
31
31
|
# The following values are REQUIRED when logging an activity:
|
32
|
-
# options[:activityId] => The activity
|
33
|
-
# options[:durationMillis] => Activity duration in milliseconds
|
34
|
-
# options[:distance] => Distance covered during activity date
|
32
|
+
# options[:activityId] => The id of the activity, directory activity or intensity level activity. See activity types at http://wiki.fitbit.com/display/API/API-Log-Activity for more information.
|
33
|
+
# options[:durationMillis] => Activity duration in milliseconds
|
35
34
|
# options[:startTime] => Activity start time hours and minutes in the format HH:mm
|
35
|
+
# options[:date] => Set to today's date when not provided
|
36
|
+
#
|
37
|
+
# The following value is REQUIRED when logging directory activity, OPTIONAL otherwise
|
38
|
+
# options[:distance]
|
39
|
+
#
|
36
40
|
# The following values are OPTIONAL when logging an activity:
|
37
|
-
# options[:
|
41
|
+
# options[:distanceUnit] => One of Fitgem::ApiDistanceUnit values
|
42
|
+
# options[:manualCalories] => Number of calories determined manually
|
38
43
|
def log_activity(options)
|
39
44
|
post("/user/#{@user_id}/activities.json", options)
|
40
45
|
end
|
41
|
-
|
46
|
+
|
42
47
|
def add_favorite_activity(activity_id)
|
43
48
|
post("/user/#{@user_id}/activities/log/favorite/#{activity_id}.json")
|
44
49
|
end
|
45
|
-
|
50
|
+
|
46
51
|
# ==========================================
|
47
52
|
# Activity Removal Methods
|
48
|
-
# ==========================================
|
53
|
+
# ==========================================
|
49
54
|
|
50
55
|
def delete_logged_activity(activity_log_id)
|
51
56
|
delete("/user/#{@user_id}/activities/#{activity_log_id}.json")
|
52
57
|
end
|
53
|
-
|
58
|
+
|
54
59
|
def remove_favorite_activity(activity_id)
|
55
60
|
delete("/user/#{@user_id}/activities/log/favorite/#{activity_id}.json")
|
56
|
-
|
61
|
+
|
57
62
|
end
|
58
63
|
end
|
59
64
|
end
|
data/lib/fitgem/client.rb
CHANGED
@@ -73,21 +73,22 @@ module Fitgem
|
|
73
73
|
|
74
74
|
def get(path, headers={})
|
75
75
|
headers.merge!("User-Agent" => "fitgem gem v#{Fitgem::VERSION}", "Accept-Language" => @api_unit_system)
|
76
|
-
|
76
|
+
uri = "/#{@api_version}#{path}"
|
77
|
+
oauth_response = access_token.get(uri, headers)
|
77
78
|
JSON.parse(oauth_response.body)
|
78
79
|
end
|
79
80
|
|
80
81
|
def post(path, body='', headers={})
|
81
82
|
headers.merge!("User-Agent" => "fitgem gem v#{Fitgem::VERSION}", "Accept-Language" => @api_unit_system)
|
82
|
-
|
83
|
+
uri = "/#{@api_version}#{path}"
|
84
|
+
oauth_response = access_token.post(uri, body, headers)
|
83
85
|
JSON.parse(oauth_response.body)
|
84
86
|
end
|
85
87
|
|
86
88
|
def delete(path, headers={})
|
87
|
-
p path
|
88
|
-
p headers
|
89
89
|
headers.merge!("User-Agent" => "fitgem gem v#{Fitgem::VERSION}", "Accept-Language" => @api_unit_system)
|
90
|
-
|
90
|
+
uri = "/#{@api_version}#{path}"
|
91
|
+
oauth_response = access_token.delete(uri, headers)
|
91
92
|
JSON.parse(oauth_response.body)
|
92
93
|
end
|
93
94
|
end
|
data/lib/fitgem/foods.rb
CHANGED
@@ -4,42 +4,42 @@ module Fitgem
|
|
4
4
|
# ==========================================
|
5
5
|
# Food Retrieval Methods
|
6
6
|
# ==========================================
|
7
|
-
|
7
|
+
|
8
8
|
def foods_on_date(date)
|
9
9
|
get("/user/#{@user_id}/foods/log/date/#{format_date(date)}.json")
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def recent_foods()
|
13
13
|
get("/user/#{@user_id}/foods/log/recent.json")
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def frequent_foods()
|
17
17
|
get("/user/#{@user_id}/foods/log/frequent.json")
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def favorite_foods()
|
21
21
|
get("/user/#{@user_id}/foods/log/favorite.json")
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def foods_units()
|
25
25
|
get("/foods/units.json")
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def find_food(query_string)
|
29
29
|
get("/foods/search.json?query=#{URI.escape(query_string)}")
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
# ==========================================
|
33
33
|
# Food Update Methods
|
34
34
|
# ==========================================
|
35
|
-
|
35
|
+
|
36
36
|
# Send the following required ID's in the options hash:
|
37
37
|
# options[:foodId] => ID of the food to log
|
38
38
|
# options[:mealTypeId] => ID of the meal to log the food for
|
39
39
|
# options[:unitId] => ID of the unit to log with the food
|
40
40
|
# (typically retrieved via a previous call to get Foods (all, recent, frequent, favorite) or Food Units. )
|
41
41
|
# options[:amount] => Amount consumed of the selected unit; a floating point number
|
42
|
-
# options[:date] => Log date in the format yyyy-MM-dd
|
42
|
+
# options[:date] => Log date in the format yyyy-MM-dd
|
43
43
|
def log_food(options)
|
44
44
|
post("/user/#{@user_id}/foods/log.json", options)
|
45
45
|
end
|
@@ -47,17 +47,32 @@ module Fitgem
|
|
47
47
|
def add_favorite_food(food_id)
|
48
48
|
post("/user/#{@user_id}/foods/log/favorite/#{food_id}.json")
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
# ==========================================
|
52
52
|
# Food Removal Methods
|
53
|
-
# ==========================================
|
54
|
-
|
53
|
+
# ==========================================
|
54
|
+
|
55
55
|
def delete_logged_food(food_log_id)
|
56
56
|
delete("/user/#{@user_id}/foods/log/#{food_log_id}.json")
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def remove_favorite_food(food_id)
|
60
60
|
delete("/user/#{@user_id}/foods/favorite/#{food_id}.json")
|
61
61
|
end
|
62
|
+
|
63
|
+
# ==========================================
|
64
|
+
# Food Creation Methods
|
65
|
+
# ==========================================
|
66
|
+
|
67
|
+
# Create a food defined by the following items in the options hash:
|
68
|
+
# options[:name] (required) => Food name
|
69
|
+
# options[:defaultFoodMeasurementUnitId] (required) => Unit id; default measurement unit; full list of units could be retrieved via a previous calls to Get Food Units
|
70
|
+
# options[:defaultServingSize] (required) => Size of the default serving; nutritional values should be provided for this serving size
|
71
|
+
# options[:calories] (required) => Calories in the default serving size
|
72
|
+
# options[:formType] (optional) => Form type; (LIQUID or DRY)
|
73
|
+
# options[:description] (optional) => Description
|
74
|
+
def create_food(options)
|
75
|
+
post("/foods.json", options)
|
76
|
+
end
|
62
77
|
end
|
63
78
|
end
|
data/lib/fitgem/units.rb
CHANGED
@@ -3,13 +3,51 @@ module Fitgem
|
|
3
3
|
def self.US
|
4
4
|
"en_US"
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
def self.UK
|
8
8
|
"en_UK"
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def self.METRIC
|
12
12
|
""
|
13
13
|
end
|
14
14
|
end
|
15
|
+
|
16
|
+
class ApiDistanceUnit
|
17
|
+
def self.centimeters
|
18
|
+
"Centimeter"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.feet
|
22
|
+
"Foot"
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.inches
|
26
|
+
"Inch"
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.kilometers
|
30
|
+
"Kilometer"
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.meters
|
34
|
+
"Meter"
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.miles
|
38
|
+
"Mile"
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.millimeters
|
42
|
+
"Millimeter"
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.steps
|
46
|
+
"Steps"
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.yards
|
50
|
+
"Yards"
|
51
|
+
end
|
52
|
+
end
|
15
53
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: fitgem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Zachery Moneypenny
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-08-01 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
138
|
requirements: []
|
139
139
|
|
140
140
|
rubyforge_project: fitgem
|
141
|
-
rubygems_version: 1.
|
141
|
+
rubygems_version: 1.6.2
|
142
142
|
signing_key:
|
143
143
|
specification_version: 3
|
144
144
|
summary: OAuth client library to the data on fitbit.com
|