health_graph 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rvmrc +7 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +43 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/lib/health_graph.rb +16 -0
- data/lib/health_graph/api.rb +52 -0
- data/lib/health_graph/authentication.rb +15 -0
- data/lib/health_graph/configuration.rb +74 -0
- data/lib/health_graph/model.rb +40 -0
- data/lib/health_graph/models/fitness_activities_feed.rb +23 -0
- data/lib/health_graph/models/profile.rb +17 -0
- data/lib/health_graph/models/sleep_feed.rb +23 -0
- data/lib/health_graph/models/user.rb +29 -0
- data/lib/health_graph/models/weight_feed.rb +23 -0
- data/test/fixtures/background_activities_feed.json +1 -0
- data/test/fixtures/background_activity.json +1 -0
- data/test/fixtures/fitness_activities_feed.json +1 -0
- data/test/fixtures/fitness_activity.json +1 -0
- data/test/fixtures/profile_get.json +1 -0
- data/test/fixtures/records.json +1 -0
- data/test/fixtures/sleep_feed_get.json +1 -0
- data/test/fixtures/team_get_empty.json +1 -0
- data/test/fixtures/user_get.json +1 -0
- data/test/fixtures/weight_feed_get.json +1 -0
- data/test/fixtures/weight_get_empty.json +1 -0
- data/test/health_graph/test_fitness_activities_feed.rb +110 -0
- data/test/health_graph/test_profile.rb +59 -0
- data/test/health_graph/test_sleep_feed.rb +66 -0
- data/test/health_graph/test_user.rb +40 -0
- data/test/health_graph/test_weight_feed.rb +56 -0
- data/test/helper.rb +25 -0
- data/test/test_health_graph.rb +137 -0
- metadata +306 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
module HealthGraph
|
2
|
+
class User
|
3
|
+
include Model
|
4
|
+
|
5
|
+
hash_attr_accessor :userID
|
6
|
+
|
7
|
+
def initialize(access_token)
|
8
|
+
self.access_token = access_token
|
9
|
+
@body = get "user", HealthGraph.accept_headers[:user]
|
10
|
+
populate_from_hash! @body
|
11
|
+
end
|
12
|
+
|
13
|
+
def profile
|
14
|
+
HealthGraph::Profile.new self.access_token, @body["profile"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def weight
|
18
|
+
HealthGraph::WeightFeed.new self.access_token, @body["weight"]
|
19
|
+
end
|
20
|
+
|
21
|
+
def sleep
|
22
|
+
HealthGraph::SleepFeed.new self.access_token, @body["sleep"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def fitness_activities
|
26
|
+
HealthGraph::FitnessActivitiesFeed.new self.access_token, @body["fitness_activities"]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module HealthGraph
|
2
|
+
class WeightFeed
|
3
|
+
include Model
|
4
|
+
|
5
|
+
hash_attr_accessor :items
|
6
|
+
|
7
|
+
class Item
|
8
|
+
include Model
|
9
|
+
|
10
|
+
hash_attr_accessor :timestamp, :weight, :free_mass, :mass_weight, :fat_percent, :bmi, :uri
|
11
|
+
|
12
|
+
def initialize(hash)
|
13
|
+
populate_from_hash! hash
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(access_token, path)
|
18
|
+
self.access_token = access_token
|
19
|
+
@body = get path, HealthGraph.accept_headers[:weight_feed]
|
20
|
+
populate_from_hash! @body
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"items":[{"timestamp":"Fri, 7 Oct 2011 00:00:00","steps":5242,"uri":"/backgroundActivities/6587124"},{"timestamp":"Fri, 7 Oct 2011 00:00:00","uri":"/backgroundActivities/6587123","calories_burned":1915},{"timestamp":"Wed, 5 Oct 2011 00:00:00","steps":18,"uri":"/backgroundActivities/6539462"},{"timestamp":"Wed, 5 Oct 2011 00:00:00","uri":"/backgroundActivities/6539461","calories_burned":739},{"timestamp":"Tue, 4 Oct 2011 00:00:00","uri":"/backgroundActivities/6539459","calories_burned":2059},{"timestamp":"Tue, 4 Oct 2011 00:00:00","steps":4325,"uri":"/backgroundActivities/6539460"},{"timestamp":"Mon, 3 Oct 2011 00:00:00","uri":"/backgroundActivities/6539456","calories_burned":1930},{"timestamp":"Mon, 3 Oct 2011 00:00:00","steps":4404,"uri":"/backgroundActivities/6539457"},{"timestamp":"Sun, 2 Oct 2011 00:00:00","uri":"/backgroundActivities/6444135","calories_burned":2350},{"timestamp":"Sun, 2 Oct 2011 00:00:00","steps":2578,"uri":"/backgroundActivities/6539458"},{"timestamp":"Sat, 1 Oct 2011 00:00:00","steps":9654,"uri":"/backgroundActivities/6441910"},{"timestamp":"Sat, 1 Oct 2011 00:00:00","uri":"/backgroundActivities/6441909","calories_burned":2098},{"timestamp":"Fri, 30 Sep 2011 00:00:00","steps":2718,"uri":"/backgroundActivities/6441908"},{"timestamp":"Fri, 30 Sep 2011 00:00:00","uri":"/backgroundActivities/6441907","calories_burned":2350},{"timestamp":"Thu, 29 Sep 2011 00:00:00","uri":"/backgroundActivities/6397626","calories_burned":2187},{"timestamp":"Thu, 29 Sep 2011 00:00:00","steps":6459,"uri":"/backgroundActivities/6397627"},{"timestamp":"Fri, 23 Sep 2011 00:00:00","uri":"/backgroundActivities/6253976","calories_burned":1023},{"timestamp":"Fri, 23 Sep 2011 00:00:00","steps":3606,"uri":"/backgroundActivities/6253977"},{"timestamp":"Thu, 22 Sep 2011 00:00:00","steps":5696,"uri":"/backgroundActivities/6253946"},{"timestamp":"Thu, 22 Sep 2011 00:00:00","uri":"/backgroundActivities/6253945","calories_burned":2124},{"timestamp":"Wed, 21 Sep 2011 00:00:00","uri":"/backgroundActivities/6253943","calories_burned":2144},{"timestamp":"Wed, 21 Sep 2011 00:00:00","steps":8128,"uri":"/backgroundActivities/6253944"},{"timestamp":"Tue, 20 Sep 2011 00:00:00","steps":5703,"uri":"/backgroundActivities/6253942"},{"timestamp":"Tue, 20 Sep 2011 00:00:00","uri":"/backgroundActivities/6253941","calories_burned":2043},{"timestamp":"Mon, 19 Sep 2011 00:00:00","steps":6591,"uri":"/backgroundActivities/6253940"}],"next":"/backgroundActivities/?page=1&pageSize=25&noEarlierThan=1970-01-01&noLaterThan=2011-10-12&modifiedNoEarlierThan=1970-01-01&modifiedNoLaterThan=2011-10-12","size":36}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"nearest_weight":"/weight/6626834","nearest_teammate_weight":[],"previous":"/backgroundActivities/6539461","nearest_teammate_sleep":[],"nearest_teammate_fitness_activities":[],"uri":"/backgroundActivities/6587123","nearest_teammate_general_measurements":[],"timestamp":"Fri, 7 Oct 2011 00:00:00","userID":5362813,"nearest_teammate_strength_training_activities":[],"nearest_teammate_diabetes":[],"nearest_sleep":"/sleep/6253947","nearest_teammate_background_activities":[],"nearest_teammate_nutrition":[],"calories_burned":1915,"nearest_fitness_activity":"/fitnessActivities/52367938"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"items":[{"duration":7920,"total_distance":62764.416,"start_time":"Thu, 15 Sep 2011 13:28:59","type":"Cycling","uri":"/fitnessActivities/52367938"},{"duration":1080,"total_distance":2574.9504,"start_time":"Thu, 15 Sep 2011 08:00:00","type":"Walking","uri":"/fitnessActivities/52367984"},{"duration":2880,"total_distance":7402.9824,"start_time":"Wed, 14 Sep 2011 20:00:00","type":"Running","uri":"/fitnessActivities/52368041"},{"duration":3060,"total_distance":7724.8512,"start_time":"Tue, 13 Sep 2011 20:00:00","type":"Running","uri":"/fitnessActivities/52368120"},{"duration":4500,"total_distance":5632.704,"start_time":"Tue, 13 Sep 2011 08:00:00","type":"Running","uri":"/fitnessActivities/52126193"}],"size":5}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"nearest_teammate_weight":[],"type":"Cycling","distance":[],"nearest_background_activity":"/backgroundActivities/6253973","nearest_teammate_strength_training_activities":[],"nearest_teammate_diabetes":[],"path":[],"calories":[],"total_calories":1983,"nearest_teammate_nutrition":[],"activity":"http://runkeeper.com/user/kennyma/activity/52367938","nearest_weight":"/weight/6626834","total_distance":62764.416,"previous":"/fitnessActivities/52367984","nearest_teammate_sleep":[],"nearest_teammate_fitness_activities":[],"uri":"/fitnessActivities/52367938","nearest_teammate_general_measurements":[],"userID":5362813,"duration":7920,"heart_rate":[],"images":[],"start_time":"Thu, 15 Sep 2011 13:28:59","nearest_sleep":"/sleep/6253947","nearest_teammate_background_activities":[]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"location":"San Francisco, CA, USA","name":"Kenny Ma","elite":"true","gender":"M","athlete_type":"Runner","profile":"http://runkeeper.com/user/kennyma"}
|
@@ -0,0 +1 @@
|
|
1
|
+
[{"stats":[{"stat_type":"BEST_ACTIVITY","value":4.8},{"stat_type":"BEST_WEEK","value":12.899999999999999,"date":"Sun, 11 Sep 2011 00:00:00"},{"stat_type":"LAST_WEEK","value":0},{"stat_type":"THIS_WEEK","value":0},{"stat_type":"BEST_MONTH","value":12.899999999999999,"date":"Thu, 1 Sep 2011 00:00:00"},{"stat_type":"LAST_MONTH","value":12.899999999999999},{"stat_type":"THIS_MONTH","value":0},{"stat_type":"OVERALL","value":20760.5376}],"activity_type":"Running"},{"stats":[{"stat_type":"BEST_ACTIVITY","value":38.99999999999999},{"stat_type":"BEST_WEEK","value":38.99999999999999,"date":"Sun, 11 Sep 2011 00:00:00"},{"stat_type":"LAST_WEEK","value":0},{"stat_type":"THIS_WEEK","value":0},{"stat_type":"BEST_MONTH","value":38.99999999999999,"date":"Thu, 1 Sep 2011 00:00:00"},{"stat_type":"LAST_MONTH","value":38.99999999999999},{"stat_type":"THIS_MONTH","value":0},{"stat_type":"OVERALL","value":62764.416}],"activity_type":"Cycling"},{"stats":[{"stat_type":"OVERALL","value":0}],"activity_type":"Mountain Biking"},{"stats":[{"stat_type":"BEST_ACTIVITY","value":1.5999999999999999},{"stat_type":"BEST_WEEK","value":1.5999999999999999,"date":"Sun, 11 Sep 2011 00:00:00"},{"stat_type":"LAST_WEEK","value":0},{"stat_type":"THIS_WEEK","value":0},{"stat_type":"BEST_MONTH","value":1.5999999999999999,"date":"Thu, 1 Sep 2011 00:00:00"},{"stat_type":"LAST_MONTH","value":1.5999999999999999},{"stat_type":"THIS_MONTH","value":0},{"stat_type":"OVERALL","value":2574.9504}],"activity_type":"Walking"},{"stats":[{"stat_type":"OVERALL","value":0}],"activity_type":"Hiking"},{"stats":[{"stat_type":"OVERALL","value":0}],"activity_type":"Downhill Skiing"},{"stats":[{"stat_type":"OVERALL","value":0}],"activity_type":"Cross-Country Skiing"},{"stats":[{"stat_type":"OVERALL","value":0}],"activity_type":"Snowboarding"},{"stats":[{"stat_type":"OVERALL","value":0}],"activity_type":"Skating"},{"stats":[{"stat_type":"OVERALL","value":0}],"activity_type":"Swimming"},{"stats":[{"stat_type":"OVERALL","value":0}],"activity_type":"Wheelchair"},{"stats":[{"stat_type":"OVERALL","value":0}],"activity_type":"Rowing"},{"stats":[{"stat_type":"OVERALL","value":0}],"activity_type":"Elliptical"},{"stats":[{"stat_type":"OVERALL","value":0}],"activity_type":"Other"}]
|
@@ -0,0 +1 @@
|
|
1
|
+
{"items":[{"timestamp":"Thu, 22 Sep 2011 00:00:00","total_sleep":822,"uri":"/sleep/6253947"},{"timestamp":"Thu, 22 Sep 2011 00:00:00","uri":"/sleep/6253948","times_woken":29}],"size":2}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"items":[],"size":0}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"strength_training_activities":"/strengthTrainingActivities","weight":"/weight","settings":"/settings","diabetes":"/diabetes","team":"/team","sleep":"/sleep","fitness_activities":"/fitnessActivities","userID":5568845,"nutrition":"/nutrition","general_measurements":"/generalMeasurements","background_activities":"/backgroundActivities","records":"/records","profile":"/profile"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"items":[{"timestamp":"Mon, 10 Oct 2011 01:31:47","weight":63.502931853253,"uri":"/weight/6626834"}],"size":1}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"items":[],"size":0}
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestFitnessActivitiesFeed < Test::Unit::TestCase
|
4
|
+
context "fitness activities" do
|
5
|
+
setup do
|
6
|
+
stub_request(:get, HealthGraph.endpoint + '/user')
|
7
|
+
.with(:header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:user]})
|
8
|
+
.to_return(:body => fixture('user_get.json'))
|
9
|
+
|
10
|
+
stub_request(:get, HealthGraph.endpoint + '/fitnessActivities')
|
11
|
+
.with(:header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:fitness_activities_feed]})
|
12
|
+
.to_return(:body => fixture('fitness_activities_feed.json'))
|
13
|
+
|
14
|
+
@user = HealthGraph::User.new(TEST_USER_TOKEN)
|
15
|
+
end
|
16
|
+
|
17
|
+
should "make request to api" do
|
18
|
+
activities = @user.fitness_activities
|
19
|
+
assert_requested :get, HealthGraph.endpoint + '/user', :header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:user]}, :times => 1
|
20
|
+
assert_requested :get, HealthGraph.endpoint + '/fitnessActivities', :header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:fitness_activities_feed]}, :times => 1
|
21
|
+
end
|
22
|
+
|
23
|
+
should "get body" do
|
24
|
+
expected = {"items"=>
|
25
|
+
[{"duration"=>7920,
|
26
|
+
"total_distance"=>62764.416,
|
27
|
+
"start_time"=>"Thu, 15 Sep 2011 13:28:59",
|
28
|
+
"type"=>"Cycling",
|
29
|
+
"uri"=>"/fitnessActivities/52367938"},
|
30
|
+
{"duration"=>1080,
|
31
|
+
"total_distance"=>2574.9504,
|
32
|
+
"start_time"=>"Thu, 15 Sep 2011 08:00:00",
|
33
|
+
"type"=>"Walking",
|
34
|
+
"uri"=>"/fitnessActivities/52367984"},
|
35
|
+
{"duration"=>2880,
|
36
|
+
"total_distance"=>7402.9824,
|
37
|
+
"start_time"=>"Wed, 14 Sep 2011 20:00:00",
|
38
|
+
"type"=>"Running",
|
39
|
+
"uri"=>"/fitnessActivities/52368041"},
|
40
|
+
{"duration"=>3060,
|
41
|
+
"total_distance"=>7724.8512,
|
42
|
+
"start_time"=>"Tue, 13 Sep 2011 20:00:00",
|
43
|
+
"type"=>"Running",
|
44
|
+
"uri"=>"/fitnessActivities/52368120"},
|
45
|
+
{"duration"=>4500,
|
46
|
+
"total_distance"=>5632.704,
|
47
|
+
"start_time"=>"Tue, 13 Sep 2011 08:00:00",
|
48
|
+
"type"=>"Running",
|
49
|
+
"uri"=>"/fitnessActivities/52126193"}],
|
50
|
+
"size"=>5}
|
51
|
+
|
52
|
+
assert_equal expected, @user.fitness_activities.body
|
53
|
+
end
|
54
|
+
|
55
|
+
context "item" do
|
56
|
+
should "get items" do
|
57
|
+
expected = [{"duration"=>7920,
|
58
|
+
"total_distance"=>62764.416,
|
59
|
+
"start_time"=>"Thu, 15 Sep 2011 13:28:59",
|
60
|
+
"type"=>"Cycling",
|
61
|
+
"uri"=>"/fitnessActivities/52367938"},
|
62
|
+
{"duration"=>1080,
|
63
|
+
"total_distance"=>2574.9504,
|
64
|
+
"start_time"=>"Thu, 15 Sep 2011 08:00:00",
|
65
|
+
"type"=>"Walking",
|
66
|
+
"uri"=>"/fitnessActivities/52367984"},
|
67
|
+
{"duration"=>2880,
|
68
|
+
"total_distance"=>7402.9824,
|
69
|
+
"start_time"=>"Wed, 14 Sep 2011 20:00:00",
|
70
|
+
"type"=>"Running",
|
71
|
+
"uri"=>"/fitnessActivities/52368041"},
|
72
|
+
{"duration"=>3060,
|
73
|
+
"total_distance"=>7724.8512,
|
74
|
+
"start_time"=>"Tue, 13 Sep 2011 20:00:00",
|
75
|
+
"type"=>"Running",
|
76
|
+
"uri"=>"/fitnessActivities/52368120"},
|
77
|
+
{"duration"=>4500,
|
78
|
+
"total_distance"=>5632.704,
|
79
|
+
"start_time"=>"Tue, 13 Sep 2011 08:00:00",
|
80
|
+
"type"=>"Running",
|
81
|
+
"uri"=>"/fitnessActivities/52126193"}]
|
82
|
+
|
83
|
+
assert_equal expected, @user.fitness_activities.items
|
84
|
+
assert_equal 5, @user.fitness_activities.items.size
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
should "get start time" do
|
89
|
+
assert_equal "Thu, 15 Sep 2011 13:28:59", @user.fitness_activities.items[0].start_time
|
90
|
+
end
|
91
|
+
|
92
|
+
should "get duration" do
|
93
|
+
assert_equal 7920, @user.fitness_activities.items[0].duration
|
94
|
+
end
|
95
|
+
|
96
|
+
should "get total distance" do
|
97
|
+
assert_equal 62764.416, @user.fitness_activities.items[0].total_distance
|
98
|
+
end
|
99
|
+
|
100
|
+
should "get type" do
|
101
|
+
assert_not_equal nil, @user.fitness_activities.items[0].type
|
102
|
+
end
|
103
|
+
|
104
|
+
should "get uri" do
|
105
|
+
assert_not_equal nil, @user.fitness_activities.items[0].uri
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestProfile < Test::Unit::TestCase
|
4
|
+
context "profile" do
|
5
|
+
setup do
|
6
|
+
stub_request(:get, HealthGraph.endpoint + '/user')
|
7
|
+
.with(:header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:user]})
|
8
|
+
.to_return(:body => fixture('user_get.json'))
|
9
|
+
|
10
|
+
stub_request(:get, HealthGraph.endpoint + '/profile')
|
11
|
+
.with(:header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:profile]})
|
12
|
+
.to_return(:body => fixture('profile_get.json'))
|
13
|
+
|
14
|
+
@user = HealthGraph::User.new(TEST_USER_TOKEN)
|
15
|
+
end
|
16
|
+
|
17
|
+
should "make request to api" do
|
18
|
+
profile = @user.profile
|
19
|
+
assert_requested :get, HealthGraph.endpoint + '/user', :header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:user]}, :times => 1
|
20
|
+
assert_requested :get, HealthGraph.endpoint + '/profile', :header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:profile]}, :times => 1
|
21
|
+
end
|
22
|
+
|
23
|
+
should "get body" do
|
24
|
+
expected = {"location"=>"San Francisco, CA, USA",
|
25
|
+
"name"=>"Kenny Ma",
|
26
|
+
"elite"=>"true",
|
27
|
+
"gender"=>"M",
|
28
|
+
"athlete_type"=>"Runner",
|
29
|
+
"profile"=>"http://runkeeper.com/user/kennyma"}
|
30
|
+
|
31
|
+
|
32
|
+
assert_equal expected, @user.profile.body
|
33
|
+
end
|
34
|
+
|
35
|
+
should "get location" do
|
36
|
+
assert_equal "San Francisco, CA, USA", @user.profile.location
|
37
|
+
end
|
38
|
+
|
39
|
+
should "get name" do
|
40
|
+
assert_equal "Kenny Ma", @user.profile.name
|
41
|
+
end
|
42
|
+
|
43
|
+
should "get elite" do
|
44
|
+
assert_equal true, @user.profile.elite?
|
45
|
+
end
|
46
|
+
|
47
|
+
should "get gender" do
|
48
|
+
assert_equal "M", @user.profile.gender
|
49
|
+
end
|
50
|
+
|
51
|
+
should "get authlete type" do
|
52
|
+
assert_equal "Runner", @user.profile.athlete_type
|
53
|
+
end
|
54
|
+
|
55
|
+
should "get profile url" do
|
56
|
+
assert_equal "http://runkeeper.com/user/kennyma", @user.profile.profile
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSleepFeed < Test::Unit::TestCase
|
4
|
+
context "sleep" do
|
5
|
+
setup do
|
6
|
+
stub_request(:get, HealthGraph.endpoint + '/user')
|
7
|
+
.with(:header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:user]})
|
8
|
+
.to_return(:body => fixture('user_get.json'))
|
9
|
+
|
10
|
+
stub_request(:get, HealthGraph.endpoint + '/sleep')
|
11
|
+
.with(:header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:sleep_feed]})
|
12
|
+
.to_return(:body => fixture('sleep_feed_get.json'))
|
13
|
+
|
14
|
+
@user = HealthGraph::User.new(TEST_USER_TOKEN)
|
15
|
+
end
|
16
|
+
|
17
|
+
should "make request to api" do
|
18
|
+
sleep = @user.sleep
|
19
|
+
assert_requested :get, HealthGraph.endpoint + '/user', :header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:user]}, :times => 1
|
20
|
+
assert_requested :get, HealthGraph.endpoint + '/sleep', :header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:sleep_feed]}, :times => 1
|
21
|
+
end
|
22
|
+
|
23
|
+
should "get body" do
|
24
|
+
expected = {"items"=>
|
25
|
+
[{"timestamp"=>"Thu, 22 Sep 2011 00:00:00",
|
26
|
+
"total_sleep"=>822,
|
27
|
+
"uri"=>"/sleep/6253947"},
|
28
|
+
{"timestamp"=>"Thu, 22 Sep 2011 00:00:00",
|
29
|
+
"uri"=>"/sleep/6253948",
|
30
|
+
"times_woken"=>29}],
|
31
|
+
"size"=>2}
|
32
|
+
|
33
|
+
assert_equal expected, @user.sleep.body
|
34
|
+
end
|
35
|
+
|
36
|
+
context "item" do
|
37
|
+
should "get items" do
|
38
|
+
expected = [{"timestamp"=>"Thu, 22 Sep 2011 00:00:00",
|
39
|
+
"total_sleep"=>822,
|
40
|
+
"uri"=>"/sleep/6253947"},
|
41
|
+
{"timestamp"=>"Thu, 22 Sep 2011 00:00:00",
|
42
|
+
"uri"=>"/sleep/6253948",
|
43
|
+
"times_woken"=>29}]
|
44
|
+
|
45
|
+
assert_equal expected, @user.sleep.items
|
46
|
+
assert_equal 2, @user.sleep.items.size
|
47
|
+
end
|
48
|
+
|
49
|
+
should "get timestamp" do
|
50
|
+
assert_equal "Thu, 22 Sep 2011 00:00:00", @user.sleep.items[0].timestamp
|
51
|
+
end
|
52
|
+
|
53
|
+
should "get time sleep" do
|
54
|
+
assert_equal 822, @user.sleep.items[0].total_sleep
|
55
|
+
end
|
56
|
+
|
57
|
+
should "get time woken" do
|
58
|
+
assert_equal 29, @user.sleep.items[1].times_woken
|
59
|
+
end
|
60
|
+
|
61
|
+
should "get uri" do
|
62
|
+
assert_equal "/sleep/6253947", @user.sleep.items[0].uri
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestUser < Test::Unit::TestCase
|
4
|
+
context "user" do
|
5
|
+
setup do
|
6
|
+
stub_request(:get, HealthGraph.endpoint + '/user')
|
7
|
+
.with(:header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:user]})
|
8
|
+
.to_return(:body => fixture('user_get.json'))
|
9
|
+
end
|
10
|
+
|
11
|
+
should "make request to api" do
|
12
|
+
user = HealthGraph::User.new(TEST_USER_TOKEN)
|
13
|
+
assert_requested :get, HealthGraph.endpoint + '/user', :header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:user]}, :times => 1
|
14
|
+
end
|
15
|
+
|
16
|
+
should "get body" do
|
17
|
+
expected = {"strength_training_activities"=>"/strengthTrainingActivities",
|
18
|
+
"weight"=>"/weight",
|
19
|
+
"settings"=>"/settings",
|
20
|
+
"diabetes"=>"/diabetes",
|
21
|
+
"team"=>"/team",
|
22
|
+
"sleep"=>"/sleep",
|
23
|
+
"fitness_activities"=>"/fitnessActivities",
|
24
|
+
"userID"=>5568845,
|
25
|
+
"nutrition"=>"/nutrition",
|
26
|
+
"general_measurements"=>"/generalMeasurements",
|
27
|
+
"background_activities"=>"/backgroundActivities",
|
28
|
+
"records"=>"/records",
|
29
|
+
"profile"=>"/profile"}
|
30
|
+
|
31
|
+
user = HealthGraph::User.new(TEST_USER_TOKEN)
|
32
|
+
assert_equal expected, user.body
|
33
|
+
end
|
34
|
+
|
35
|
+
should "get user id" do
|
36
|
+
user = HealthGraph::User.new(TEST_USER_TOKEN)
|
37
|
+
assert_equal 5568845, user.userID
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestWeightFeed < Test::Unit::TestCase
|
4
|
+
context "weight" do
|
5
|
+
setup do
|
6
|
+
stub_request(:get, HealthGraph.endpoint + '/user')
|
7
|
+
.with(:header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:user]})
|
8
|
+
.to_return(:body => fixture('user_get.json'))
|
9
|
+
|
10
|
+
stub_request(:get, HealthGraph.endpoint + '/weight')
|
11
|
+
.with(:header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:weight_feed]})
|
12
|
+
.to_return(:body => fixture('weight_feed_get.json'))
|
13
|
+
|
14
|
+
@user = HealthGraph::User.new(TEST_USER_TOKEN)
|
15
|
+
end
|
16
|
+
|
17
|
+
should "make request to api" do
|
18
|
+
weight = @user.weight
|
19
|
+
assert_requested :get, HealthGraph.endpoint + '/user', :header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:user]}, :times => 1
|
20
|
+
assert_requested :get, HealthGraph.endpoint + '/weight', :header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:weight_feed]}, :times => 1
|
21
|
+
end
|
22
|
+
|
23
|
+
should "get body" do
|
24
|
+
expected = {"items"=>
|
25
|
+
[{"timestamp"=>"Mon, 10 Oct 2011 01:31:47",
|
26
|
+
"weight"=>63.502931853253,
|
27
|
+
"uri"=>"/weight/6626834"}],
|
28
|
+
"size"=>1}
|
29
|
+
|
30
|
+
assert_equal expected, @user.weight.body
|
31
|
+
end
|
32
|
+
|
33
|
+
context "item" do
|
34
|
+
should "get one item" do
|
35
|
+
expected = [{"timestamp"=>"Mon, 10 Oct 2011 01:31:47",
|
36
|
+
"weight"=>63.502931853253,
|
37
|
+
"uri"=>"/weight/6626834"}]
|
38
|
+
|
39
|
+
assert_equal expected, @user.weight.items
|
40
|
+
assert_equal 1, @user.weight.items.size
|
41
|
+
end
|
42
|
+
|
43
|
+
should "get timestamp" do
|
44
|
+
assert_equal "Mon, 10 Oct 2011 01:31:47", @user.weight.items[0].timestamp
|
45
|
+
end
|
46
|
+
|
47
|
+
should "get weight" do
|
48
|
+
assert_equal 63.502931853253, @user.weight.items[0].weight
|
49
|
+
end
|
50
|
+
|
51
|
+
should "get uri" do
|
52
|
+
assert_equal "/weight/6626834", @user.weight.items[0].uri
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
require 'webmock/test_unit'
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
15
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
16
|
+
require 'health_graph'
|
17
|
+
|
18
|
+
class Test::Unit::TestCase
|
19
|
+
TEST_USER_TOKEN = "b9aaf2581480432a939a72f894bf".freeze
|
20
|
+
|
21
|
+
def fixture(file)
|
22
|
+
path = File.expand_path("../fixtures", __FILE__)
|
23
|
+
File.new(path + '/' + file)
|
24
|
+
end
|
25
|
+
end
|