health_graph 0.5.1 → 0.5.2
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.
- data/Gemfile +2 -2
- data/Gemfile.lock +7 -7
- data/README.rdoc +38 -1
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/health_graph.gemspec +118 -0
- data/lib/health_graph/api.rb +8 -6
- data/lib/health_graph/configuration.rb +5 -5
- data/lib/health_graph/model.rb +4 -2
- data/lib/health_graph/models/fitness_activities_feed.rb +3 -2
- data/lib/health_graph/models/new_fitness_activity.rb +15 -0
- data/lib/health_graph/models/profile.rb +4 -3
- data/lib/health_graph/models/sleep_feed.rb +3 -2
- data/lib/health_graph/models/user.rb +11 -6
- data/lib/health_graph/models/weight_feed.rb +3 -2
- data/lib/health_graph.rb +1 -0
- data/test/fixtures/new_fitness_activity_params.json +1 -0
- data/test/health_graph/test_new_fitness_activity.rb +26 -0
- data/test/helper.rb +5 -0
- data/test/test_health_graph.rb +6 -6
- metadata +16 -15
- data/.rvmrc +0 -7
data/Gemfile
CHANGED
@@ -3,10 +3,10 @@ source "http://rubygems.org"
|
|
3
3
|
# Example:
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
5
5
|
|
6
|
-
gem "oauth2", "= 0.5.
|
6
|
+
gem "oauth2", "= 0.5.2"
|
7
7
|
gem "faraday", "= 0.7.4"
|
8
8
|
gem "faraday_middleware", "= 0.7.0"
|
9
|
-
gem "hashie", "= 1.
|
9
|
+
gem "hashie", "= 1.2"
|
10
10
|
|
11
11
|
# Add dependencies to develop your gem here.
|
12
12
|
# Include everything needed to run rake, tests, features, etc.
|
data/Gemfile.lock
CHANGED
@@ -10,16 +10,16 @@ GEM
|
|
10
10
|
faraday_middleware (0.7.0)
|
11
11
|
faraday (~> 0.7.3)
|
12
12
|
git (1.2.5)
|
13
|
-
hashie (1.
|
13
|
+
hashie (1.2.0)
|
14
14
|
jeweler (1.6.4)
|
15
15
|
bundler (~> 1.0)
|
16
16
|
git (>= 1.2.5)
|
17
17
|
rake
|
18
|
-
multi_json (1.0.
|
18
|
+
multi_json (1.0.4)
|
19
19
|
multipart-post (1.1.3)
|
20
|
-
oauth2 (0.5.
|
21
|
-
faraday (~> 0.7
|
22
|
-
multi_json (~> 1.0
|
20
|
+
oauth2 (0.5.2)
|
21
|
+
faraday (~> 0.7)
|
22
|
+
multi_json (~> 1.0)
|
23
23
|
rack (1.3.4)
|
24
24
|
rake (0.9.2)
|
25
25
|
rcov (0.9.10)
|
@@ -35,9 +35,9 @@ DEPENDENCIES
|
|
35
35
|
bundler (~> 1.0.0)
|
36
36
|
faraday (= 0.7.4)
|
37
37
|
faraday_middleware (= 0.7.0)
|
38
|
-
hashie (= 1.
|
38
|
+
hashie (= 1.2)
|
39
39
|
jeweler (~> 1.6.4)
|
40
|
-
oauth2 (= 0.5.
|
40
|
+
oauth2 (= 0.5.2)
|
41
41
|
rcov
|
42
42
|
shoulda
|
43
43
|
webmock (= 1.7.4)
|
data/README.rdoc
CHANGED
@@ -1,6 +1,43 @@
|
|
1
1
|
= health_graph
|
2
2
|
|
3
|
-
Ruby gem to work with RunKeeper Health Graph API.
|
3
|
+
Ruby gem to work with RunKeeper Health Graph API. More information about RunKeeper Health Graph API http://developer.runkeeper.com/healthgraph.
|
4
|
+
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
=== Authentication
|
8
|
+
|
9
|
+
HealthGraph.configure do |config|
|
10
|
+
config.client_id = [YOUR HEALTH GRAPH CLIENT ID]
|
11
|
+
config.client_secret = [YOUR HEALTH GRAPH CLIENT SECRET]
|
12
|
+
config.authorization_redirect_url = [PAGE TO REDIRECT THE USER TO AFTER AUTH]
|
13
|
+
end
|
14
|
+
|
15
|
+
auth_url = HealthGraph.authorize_url
|
16
|
+
|
17
|
+
access_token = HealthGraph.access_token(auth_code)
|
18
|
+
|
19
|
+
For more information on authentication & authorization, see http://developer.runkeeper.com/healthgraph/registration-authorization
|
20
|
+
|
21
|
+
=== Accessing Health Graph API
|
22
|
+
|
23
|
+
user = HealthGraph::User.new(access_token)
|
24
|
+
profile = user.profile
|
25
|
+
fitness_activities = user.fitness_activities.items
|
26
|
+
sleep = user.sleep.items
|
27
|
+
weight = user.weight.items
|
28
|
+
|
29
|
+
=== Other Configuration options
|
30
|
+
|
31
|
+
HealthGraph.configure do |config|
|
32
|
+
config.client_id = [YOUR HEALTH GRAPH CLIENT ID. REQUIRED.]
|
33
|
+
config.client_secret = [YOUR HEALTH GRAPH CLIENT SECRET. REQUIRED.]
|
34
|
+
config.authorization_redirect_url = [PAGE TO REDIRECT THE USER TO AFTER AUTH. REQUIRED.]
|
35
|
+
config.authorization_url = [URL TO AUTHORIZE USER. DEFAULT IS http://runkeeper.com/apps/authorize]
|
36
|
+
config.access_token_url = [URL TO GET USER ACCESS TOKEN. DEFAULT IS http://runkeeper.com/apps/token]
|
37
|
+
config.endpoint = [API ENDPOINT. DEFAULT IS http://api.runkeeper.com]
|
38
|
+
config.adapter = [FARADAY ADAPTER. DEFAULT IS net_http]
|
39
|
+
config.faraday_options = [ADDITIONAL FARADAY OPTIONS. DEFAULT IS EMPTY.]
|
40
|
+
end
|
4
41
|
|
5
42
|
== Contributing to health_graph
|
6
43
|
|
data/Rakefile
CHANGED
@@ -22,10 +22,10 @@ Jeweler::Tasks.new do |gem|
|
|
22
22
|
gem.email = "kenny@kennyma.me"
|
23
23
|
gem.authors = ["Kenny Ma"]
|
24
24
|
# dependencies defined in Gemfile
|
25
|
-
gem.add_dependency 'oauth2', '= 0.5.
|
25
|
+
gem.add_dependency 'oauth2', '= 0.5.2'
|
26
26
|
gem.add_dependency 'faraday', '= 0.7.4'
|
27
27
|
gem.add_dependency 'faraday_middleware', '= 0.7.0'
|
28
|
-
gem.add_dependency 'hashie', '= 1.
|
28
|
+
gem.add_dependency 'hashie', '= 1.2'
|
29
29
|
gem.add_dependency 'webmock', '= 1.7.6'
|
30
30
|
end
|
31
31
|
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.2
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{health_graph}
|
8
|
+
s.version = "0.5.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kenny Ma"]
|
12
|
+
s.date = %q{2012-02-18}
|
13
|
+
s.description = %q{This is a wrapper for RunKeeper Health Graph RESTful API.}
|
14
|
+
s.email = %q{kenny@kennyma.me}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"health_graph.gemspec",
|
28
|
+
"lib/health_graph.rb",
|
29
|
+
"lib/health_graph/api.rb",
|
30
|
+
"lib/health_graph/authentication.rb",
|
31
|
+
"lib/health_graph/configuration.rb",
|
32
|
+
"lib/health_graph/model.rb",
|
33
|
+
"lib/health_graph/models/fitness_activities_feed.rb",
|
34
|
+
"lib/health_graph/models/new_fitness_activity.rb",
|
35
|
+
"lib/health_graph/models/profile.rb",
|
36
|
+
"lib/health_graph/models/sleep_feed.rb",
|
37
|
+
"lib/health_graph/models/user.rb",
|
38
|
+
"lib/health_graph/models/weight_feed.rb",
|
39
|
+
"test/fixtures/background_activities_feed.json",
|
40
|
+
"test/fixtures/background_activity.json",
|
41
|
+
"test/fixtures/fitness_activities_feed.json",
|
42
|
+
"test/fixtures/fitness_activity.json",
|
43
|
+
"test/fixtures/new_fitness_activity_params.json",
|
44
|
+
"test/fixtures/profile_get.json",
|
45
|
+
"test/fixtures/records.json",
|
46
|
+
"test/fixtures/sleep_feed_get.json",
|
47
|
+
"test/fixtures/team_get_empty.json",
|
48
|
+
"test/fixtures/user_get.json",
|
49
|
+
"test/fixtures/weight_feed_get.json",
|
50
|
+
"test/fixtures/weight_get_empty.json",
|
51
|
+
"test/health_graph/test_fitness_activities_feed.rb",
|
52
|
+
"test/health_graph/test_new_fitness_activity.rb",
|
53
|
+
"test/health_graph/test_profile.rb",
|
54
|
+
"test/health_graph/test_sleep_feed.rb",
|
55
|
+
"test/health_graph/test_user.rb",
|
56
|
+
"test/health_graph/test_weight_feed.rb",
|
57
|
+
"test/helper.rb",
|
58
|
+
"test/test_health_graph.rb"
|
59
|
+
]
|
60
|
+
s.homepage = %q{http://github.com/kennyma/health_graph}
|
61
|
+
s.licenses = ["MIT"]
|
62
|
+
s.require_paths = ["lib"]
|
63
|
+
s.rubygems_version = %q{1.3.7}
|
64
|
+
s.summary = %q{Ruby gem for RunKeeper Health Graph API}
|
65
|
+
|
66
|
+
if s.respond_to? :specification_version then
|
67
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
68
|
+
s.specification_version = 3
|
69
|
+
|
70
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
71
|
+
s.add_runtime_dependency(%q<oauth2>, ["= 0.5.2"])
|
72
|
+
s.add_runtime_dependency(%q<faraday>, ["= 0.7.4"])
|
73
|
+
s.add_runtime_dependency(%q<faraday_middleware>, ["= 0.7.0"])
|
74
|
+
s.add_runtime_dependency(%q<hashie>, ["= 1.2"])
|
75
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
76
|
+
s.add_development_dependency(%q<webmock>, ["= 1.7.4"])
|
77
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
78
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
79
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
80
|
+
s.add_runtime_dependency(%q<oauth2>, ["= 0.5.2"])
|
81
|
+
s.add_runtime_dependency(%q<faraday>, ["= 0.7.4"])
|
82
|
+
s.add_runtime_dependency(%q<faraday_middleware>, ["= 0.7.0"])
|
83
|
+
s.add_runtime_dependency(%q<hashie>, ["= 1.2"])
|
84
|
+
s.add_runtime_dependency(%q<webmock>, ["= 1.7.6"])
|
85
|
+
else
|
86
|
+
s.add_dependency(%q<oauth2>, ["= 0.5.2"])
|
87
|
+
s.add_dependency(%q<faraday>, ["= 0.7.4"])
|
88
|
+
s.add_dependency(%q<faraday_middleware>, ["= 0.7.0"])
|
89
|
+
s.add_dependency(%q<hashie>, ["= 1.2"])
|
90
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
91
|
+
s.add_dependency(%q<webmock>, ["= 1.7.4"])
|
92
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
93
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
94
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
95
|
+
s.add_dependency(%q<oauth2>, ["= 0.5.2"])
|
96
|
+
s.add_dependency(%q<faraday>, ["= 0.7.4"])
|
97
|
+
s.add_dependency(%q<faraday_middleware>, ["= 0.7.0"])
|
98
|
+
s.add_dependency(%q<hashie>, ["= 1.2"])
|
99
|
+
s.add_dependency(%q<webmock>, ["= 1.7.6"])
|
100
|
+
end
|
101
|
+
else
|
102
|
+
s.add_dependency(%q<oauth2>, ["= 0.5.2"])
|
103
|
+
s.add_dependency(%q<faraday>, ["= 0.7.4"])
|
104
|
+
s.add_dependency(%q<faraday_middleware>, ["= 0.7.0"])
|
105
|
+
s.add_dependency(%q<hashie>, ["= 1.2"])
|
106
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
107
|
+
s.add_dependency(%q<webmock>, ["= 1.7.4"])
|
108
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
109
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
110
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
111
|
+
s.add_dependency(%q<oauth2>, ["= 0.5.2"])
|
112
|
+
s.add_dependency(%q<faraday>, ["= 0.7.4"])
|
113
|
+
s.add_dependency(%q<faraday_middleware>, ["= 0.7.0"])
|
114
|
+
s.add_dependency(%q<hashie>, ["= 1.2"])
|
115
|
+
s.add_dependency(%q<webmock>, ["= 1.7.6"])
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
data/lib/health_graph/api.rb
CHANGED
@@ -21,28 +21,30 @@ module HealthGraph
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def request(method, accept_header, path, params)
|
24
|
-
response = connection.send(method) do |request|
|
24
|
+
response = connection(method).send(method) do |request|
|
25
25
|
request.headers['Authorization'] = "Bearer #{access_token}"
|
26
|
-
request.headers['Accept'] = accept_header
|
27
26
|
|
28
27
|
case method.to_sym
|
29
28
|
when :get, :delete
|
29
|
+
request.headers['Accept'] = accept_header
|
30
30
|
request.url(path, params)
|
31
31
|
when :put, :post
|
32
|
+
request.headers['Content-Type'] = accept_header
|
32
33
|
request.path = path
|
33
|
-
request.body = params unless params.empty?
|
34
|
+
request.body = params.to_json unless params.empty?
|
34
35
|
end
|
35
36
|
end
|
36
|
-
response
|
37
|
+
response
|
37
38
|
end
|
38
39
|
|
39
|
-
def connection
|
40
|
+
def connection method
|
40
41
|
merged_options = HealthGraph.faraday_options.merge({
|
41
42
|
:url => HealthGraph.endpoint
|
42
43
|
})
|
43
|
-
|
44
|
+
|
44
45
|
Faraday.new(merged_options) do |builder|
|
45
46
|
builder.use Faraday::Request::UrlEncoded
|
47
|
+
builder.use Faraday::Request::JSON if method == :post
|
46
48
|
builder.use Faraday::Response::Mashify
|
47
49
|
builder.use Faraday::Response::ParseJson
|
48
50
|
builder.adapter(HealthGraph.adapter)
|
@@ -13,16 +13,17 @@ module HealthGraph
|
|
13
13
|
|
14
14
|
DEFAULT_CLIENT_ID = nil
|
15
15
|
DEFAULT_CLIENT_SECRET = nil
|
16
|
-
DEFAULT_AUTHORIZATION_URL = "
|
17
|
-
DEFAULT_ACCESS_TOKEN_URL = "
|
16
|
+
DEFAULT_AUTHORIZATION_URL = "https://runkeeper.com/apps/authorize".freeze
|
17
|
+
DEFAULT_ACCESS_TOKEN_URL = "https://runkeeper.com/apps/token".freeze
|
18
18
|
DEFAULT_AUTHORIZATION_REDIRECT_URL = nil
|
19
|
-
DEFAULT_ENDPOINT = "
|
19
|
+
DEFAULT_ENDPOINT = "https://api.runkeeper.com".freeze
|
20
20
|
DEFAULT_ADAPTER = :net_http
|
21
21
|
DEFAULT_FARADAY_OPTIONS = {}.freeze
|
22
22
|
DEFAULT_ACCEPT_HEADERS = {
|
23
23
|
:user => "application/vnd.com.runkeeper.User+json",
|
24
24
|
:fitness_activity_feed => "application/vnd.com.runkeeper.FitnessActivityFeed+json",
|
25
25
|
:fitness_activity => "application/vnd.com.runkeeper.FitnessActivity+json",
|
26
|
+
:new_fitness_activity => "application/vnd.com.runkeeper.NewFitnessActivity+json",
|
26
27
|
:strength_training_activity_feed => "application/vnd.com.runkeeper.StrengthTrainingActivityFeed+json",
|
27
28
|
:strength_training_activity => "application/vnd.com.runkeeper.StrengthTrainingActivity+json",
|
28
29
|
:background_activity_feed => "application/vnd.com.runkeeper.BackgroundActivityFeed+json",
|
@@ -38,8 +39,7 @@ module HealthGraph
|
|
38
39
|
:diabetes_feed => "application/vnd.com.runkeeper.DiabetesFeed+json",
|
39
40
|
:diatetes_measurement => "application/vnd.com.runkeeper.DiabetesMeasurement+json",
|
40
41
|
:records => "application/vnd.com.runkeeper.Records+json",
|
41
|
-
:profile => "application/vnd.com.runkeeper.Profile+json"
|
42
|
-
:new_activity => "application/vnd.com.runkeeper.NewFitnessActivity+json"
|
42
|
+
:profile => "application/vnd.com.runkeeper.Profile+json"
|
43
43
|
}.freeze
|
44
44
|
|
45
45
|
attr_accessor *VALID_OPTIONS_KEYS
|
data/lib/health_graph/model.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module HealthGraph
|
2
2
|
module Model
|
3
3
|
include API
|
4
|
-
|
4
|
+
|
5
5
|
attr_accessor :body
|
6
6
|
|
7
7
|
def self.included(includer)
|
@@ -26,11 +26,13 @@ module HealthGraph
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def populate_from_hash!(hash)
|
29
|
+
return unless hash
|
30
|
+
|
29
31
|
hash.each do |key, value|
|
30
32
|
set_attr_method = "#{key}="
|
31
33
|
unless value.nil?
|
32
34
|
if respond_to?(set_attr_method)
|
33
|
-
self.__send__(set_attr_method, value)
|
35
|
+
self.__send__(set_attr_method, value)
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -16,8 +16,9 @@ module HealthGraph
|
|
16
16
|
|
17
17
|
def initialize(access_token, path)
|
18
18
|
self.access_token = access_token
|
19
|
-
|
20
|
-
|
19
|
+
response = get path, HealthGraph.accept_headers[:fitness_activity_feed]
|
20
|
+
self.body = response.body
|
21
|
+
populate_from_hash! self.body
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module HealthGraph
|
2
|
+
class NewFitnessActivity
|
3
|
+
include Model
|
4
|
+
|
5
|
+
hash_attr_accessor :location, :status
|
6
|
+
|
7
|
+
def initialize access_token, params
|
8
|
+
self.access_token = access_token
|
9
|
+
response = post "/fitnessActivities", HealthGraph.accept_headers[:new_fitness_activity], params
|
10
|
+
|
11
|
+
self.location = response.headers[:location]
|
12
|
+
self.status = response.status
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -6,12 +6,13 @@ module HealthGraph
|
|
6
6
|
|
7
7
|
def initialize(access_token, path)
|
8
8
|
self.access_token = access_token
|
9
|
-
|
10
|
-
|
9
|
+
response = get path, HealthGraph.accept_headers[:profile]
|
10
|
+
self.body = response.body
|
11
|
+
populate_from_hash! self.body
|
11
12
|
end
|
12
13
|
|
13
14
|
def elite?
|
14
|
-
|
15
|
+
self.body["elite"] == "true"
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
@@ -16,8 +16,9 @@ module HealthGraph
|
|
16
16
|
|
17
17
|
def initialize(access_token, path)
|
18
18
|
self.access_token = access_token
|
19
|
-
|
20
|
-
|
19
|
+
response = get path, HealthGraph.accept_headers[:sleep_feed]
|
20
|
+
self.body = response.body
|
21
|
+
populate_from_hash! self.body
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
@@ -6,24 +6,29 @@ module HealthGraph
|
|
6
6
|
|
7
7
|
def initialize(access_token)
|
8
8
|
self.access_token = access_token
|
9
|
-
|
10
|
-
|
9
|
+
response = get "user", HealthGraph.accept_headers[:user]
|
10
|
+
self.body = response.body
|
11
|
+
populate_from_hash! self.body
|
11
12
|
end
|
12
13
|
|
13
14
|
def profile
|
14
|
-
HealthGraph::Profile.new self.access_token,
|
15
|
+
HealthGraph::Profile.new self.access_token, self.body["profile"]
|
15
16
|
end
|
16
17
|
|
17
18
|
def weight
|
18
|
-
HealthGraph::WeightFeed.new self.access_token,
|
19
|
+
HealthGraph::WeightFeed.new self.access_token, self.body["weight"]
|
19
20
|
end
|
20
21
|
|
21
22
|
def sleep
|
22
|
-
HealthGraph::SleepFeed.new self.access_token,
|
23
|
+
HealthGraph::SleepFeed.new self.access_token, self.body["sleep"]
|
23
24
|
end
|
24
25
|
|
25
26
|
def fitness_activities
|
26
|
-
HealthGraph::FitnessActivitiesFeed.new self.access_token,
|
27
|
+
HealthGraph::FitnessActivitiesFeed.new self.access_token, self.body["fitness_activities"]
|
28
|
+
end
|
29
|
+
|
30
|
+
def new_fitness_activity(params)
|
31
|
+
HealthGraph::NewFitnessActivity.new self.access_token, params
|
27
32
|
end
|
28
33
|
end
|
29
34
|
end
|
@@ -16,8 +16,9 @@ module HealthGraph
|
|
16
16
|
|
17
17
|
def initialize(access_token, path)
|
18
18
|
self.access_token = access_token
|
19
|
-
|
20
|
-
|
19
|
+
response = get path, HealthGraph.accept_headers[:weight_feed]
|
20
|
+
self.body = response.body
|
21
|
+
populate_from_hash! self.body
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
data/lib/health_graph.rb
CHANGED
@@ -9,6 +9,7 @@ require 'health_graph/models/profile'
|
|
9
9
|
require 'health_graph/models/weight_feed'
|
10
10
|
require 'health_graph/models/sleep_feed'
|
11
11
|
require 'health_graph/models/fitness_activities_feed'
|
12
|
+
require 'health_graph/models/new_fitness_activity'
|
12
13
|
|
13
14
|
module HealthGraph
|
14
15
|
extend Configuration
|
@@ -0,0 +1 @@
|
|
1
|
+
{"type": "Running","start_time": "Sat, 1 Jan 2011 00:00:00","notes": "My first late-night run", "path": [{"timestamp":0,"altitude":0,"longitude":-70.95182336425782,"latitude":42.312620297384676,"type":"start"},{"timestamp":8,"altitude":0,"longitude":-70.95255292510987,"latitude":42.31230294498018,"type":"end"}], "post_to_facebook": true,"post_to_twitter": true}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestNewFitnessActivity < Test::Unit::TestCase
|
4
|
+
context "New Fitness Activity" do
|
5
|
+
setup do
|
6
|
+
stub_request(:post, HealthGraph.endpoint + '/fitnessActivities')
|
7
|
+
.with(:header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:new_fitness_activity]})
|
8
|
+
.to_return(:status => 201, :headers => {'location' => '/fitnessActivities/20'})
|
9
|
+
end
|
10
|
+
|
11
|
+
should "make request to api" do
|
12
|
+
activity = HealthGraph::NewFitnessActivity.new(TEST_USER_TOKEN, json_fixture('new_fitness_activity_params.json'))
|
13
|
+
assert_requested :post, HealthGraph.endpoint + '/fitnessActivities', :header => {'Authorization' => 'Bearer ' + TEST_USER_TOKEN, 'Accept' => HealthGraph.accept_headers[:new_fitness_activity]}, :times => 1
|
14
|
+
end
|
15
|
+
|
16
|
+
should "get location" do
|
17
|
+
activity = HealthGraph::NewFitnessActivity.new(TEST_USER_TOKEN, json_fixture('new_fitness_activity_params.json'))
|
18
|
+
assert_equal '/fitnessActivities/20', activity.location
|
19
|
+
end
|
20
|
+
|
21
|
+
should "get success status" do
|
22
|
+
activity = HealthGraph::NewFitnessActivity.new(TEST_USER_TOKEN, json_fixture('new_fitness_activity_params.json'))
|
23
|
+
assert_equal 201, activity.status
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/test/helper.rb
CHANGED
data/test/test_health_graph.rb
CHANGED
@@ -27,7 +27,7 @@ class TestHealthGraph < Test::Unit::TestCase
|
|
27
27
|
end
|
28
28
|
|
29
29
|
should "get default authorization url" do
|
30
|
-
assert_equal "
|
30
|
+
assert_equal "https://runkeeper.com/apps/authorize", HealthGraph.authorization_url
|
31
31
|
end
|
32
32
|
|
33
33
|
should "set authorization url" do
|
@@ -37,7 +37,7 @@ class TestHealthGraph < Test::Unit::TestCase
|
|
37
37
|
end
|
38
38
|
|
39
39
|
should "get default access token url" do
|
40
|
-
assert_equal "
|
40
|
+
assert_equal "https://runkeeper.com/apps/token", HealthGraph.access_token_url
|
41
41
|
end
|
42
42
|
|
43
43
|
should "set access token url" do
|
@@ -57,11 +57,11 @@ class TestHealthGraph < Test::Unit::TestCase
|
|
57
57
|
end
|
58
58
|
|
59
59
|
should "get default api endpoint" do
|
60
|
-
assert_equal "
|
60
|
+
assert_equal "https://api.runkeeper.com", HealthGraph.endpoint
|
61
61
|
end
|
62
62
|
|
63
63
|
should "set api endpoont" do
|
64
|
-
new_endpoint = "
|
64
|
+
new_endpoint = "https://api.somesite.com"
|
65
65
|
HealthGraph.endpoint = new_endpoint
|
66
66
|
assert_equal new_endpoint, HealthGraph.endpoint
|
67
67
|
end
|
@@ -91,6 +91,7 @@ class TestHealthGraph < Test::Unit::TestCase
|
|
91
91
|
:user => "application/vnd.com.runkeeper.User+json",
|
92
92
|
:fitness_activity_feed => "application/vnd.com.runkeeper.FitnessActivityFeed+json",
|
93
93
|
:fitness_activity => "application/vnd.com.runkeeper.FitnessActivity+json",
|
94
|
+
:new_fitness_activity => "application/vnd.com.runkeeper.NewFitnessActivity+json",
|
94
95
|
:strength_training_activity_feed => "application/vnd.com.runkeeper.StrengthTrainingActivityFeed+json",
|
95
96
|
:strength_training_activity => "application/vnd.com.runkeeper.StrengthTrainingActivity+json",
|
96
97
|
:background_activity_feed => "application/vnd.com.runkeeper.BackgroundActivityFeed+json",
|
@@ -106,8 +107,7 @@ class TestHealthGraph < Test::Unit::TestCase
|
|
106
107
|
:diabetes_feed => "application/vnd.com.runkeeper.DiabetesFeed+json",
|
107
108
|
:diatetes_measurement => "application/vnd.com.runkeeper.DiabetesMeasurement+json",
|
108
109
|
:records => "application/vnd.com.runkeeper.Records+json",
|
109
|
-
:profile => "application/vnd.com.runkeeper.Profile+json"
|
110
|
-
:new_activity => "application/vnd.com.runkeeper.NewFitnessActivity+json"
|
110
|
+
:profile => "application/vnd.com.runkeeper.Profile+json"
|
111
111
|
}
|
112
112
|
|
113
113
|
assert_equal options, HealthGraph.accept_headers
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
8
|
+
- 2
|
9
|
+
version: 0.5.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kenny Ma
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2012-02-18 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -27,8 +27,8 @@ dependencies:
|
|
27
27
|
segments:
|
28
28
|
- 0
|
29
29
|
- 5
|
30
|
-
-
|
31
|
-
version: 0.5.
|
30
|
+
- 2
|
31
|
+
version: 0.5.2
|
32
32
|
type: :runtime
|
33
33
|
prerelease: false
|
34
34
|
version_requirements: *id001
|
@@ -71,9 +71,8 @@ dependencies:
|
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
segments:
|
73
73
|
- 1
|
74
|
-
-
|
75
|
-
|
76
|
-
version: 1.1.0
|
74
|
+
- 2
|
75
|
+
version: "1.2"
|
77
76
|
type: :runtime
|
78
77
|
prerelease: false
|
79
78
|
version_requirements: *id004
|
@@ -158,8 +157,8 @@ dependencies:
|
|
158
157
|
segments:
|
159
158
|
- 0
|
160
159
|
- 5
|
161
|
-
-
|
162
|
-
version: 0.5.
|
160
|
+
- 2
|
161
|
+
version: 0.5.2
|
163
162
|
type: :runtime
|
164
163
|
prerelease: false
|
165
164
|
version_requirements: *id010
|
@@ -202,9 +201,8 @@ dependencies:
|
|
202
201
|
- !ruby/object:Gem::Version
|
203
202
|
segments:
|
204
203
|
- 1
|
205
|
-
-
|
206
|
-
|
207
|
-
version: 1.1.0
|
204
|
+
- 2
|
205
|
+
version: "1.2"
|
208
206
|
type: :runtime
|
209
207
|
prerelease: false
|
210
208
|
version_requirements: *id013
|
@@ -234,19 +232,20 @@ extra_rdoc_files:
|
|
234
232
|
- README.rdoc
|
235
233
|
files:
|
236
234
|
- .document
|
237
|
-
- .rvmrc
|
238
235
|
- Gemfile
|
239
236
|
- Gemfile.lock
|
240
237
|
- LICENSE.txt
|
241
238
|
- README.rdoc
|
242
239
|
- Rakefile
|
243
240
|
- VERSION
|
241
|
+
- health_graph.gemspec
|
244
242
|
- lib/health_graph.rb
|
245
243
|
- lib/health_graph/api.rb
|
246
244
|
- lib/health_graph/authentication.rb
|
247
245
|
- lib/health_graph/configuration.rb
|
248
246
|
- lib/health_graph/model.rb
|
249
247
|
- lib/health_graph/models/fitness_activities_feed.rb
|
248
|
+
- lib/health_graph/models/new_fitness_activity.rb
|
250
249
|
- lib/health_graph/models/profile.rb
|
251
250
|
- lib/health_graph/models/sleep_feed.rb
|
252
251
|
- lib/health_graph/models/user.rb
|
@@ -255,6 +254,7 @@ files:
|
|
255
254
|
- test/fixtures/background_activity.json
|
256
255
|
- test/fixtures/fitness_activities_feed.json
|
257
256
|
- test/fixtures/fitness_activity.json
|
257
|
+
- test/fixtures/new_fitness_activity_params.json
|
258
258
|
- test/fixtures/profile_get.json
|
259
259
|
- test/fixtures/records.json
|
260
260
|
- test/fixtures/sleep_feed_get.json
|
@@ -263,6 +263,7 @@ files:
|
|
263
263
|
- test/fixtures/weight_feed_get.json
|
264
264
|
- test/fixtures/weight_get_empty.json
|
265
265
|
- test/health_graph/test_fitness_activities_feed.rb
|
266
|
+
- test/health_graph/test_new_fitness_activity.rb
|
266
267
|
- test/health_graph/test_profile.rb
|
267
268
|
- test/health_graph/test_sleep_feed.rb
|
268
269
|
- test/health_graph/test_user.rb
|
@@ -283,7 +284,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
283
284
|
requirements:
|
284
285
|
- - ">="
|
285
286
|
- !ruby/object:Gem::Version
|
286
|
-
hash:
|
287
|
+
hash: 2017150975927793976
|
287
288
|
segments:
|
288
289
|
- 0
|
289
290
|
version: "0"
|
data/.rvmrc
DELETED