runkeeper-activities 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/README.rdoc +43 -0
- data/Rakefile +9 -0
- data/lib/runkeeper_activities/activity.rb +76 -0
- data/lib/runkeeper_activities/user.rb +64 -0
- data/lib/runkeeper_activities/utils.rb +9 -0
- data/lib/runkeeper_activities/version.rb +3 -0
- data/lib/runkeeper_activities.rb +8 -0
- data/runkeeper-activities.gemspec +24 -0
- data/test/data/activity.txt +8 -0
- data/test/data/non_existing_profile.txt +408 -0
- data/test/data/profile.txt +1857 -0
- data/test/test_helper.rb +30 -0
- data/test/unit/runkeeper_activity_test.rb +29 -0
- data/test/unit/runkeeper_user_test.rb +35 -0
- metadata +163 -0
data/test/test_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'bundler/setup'
|
6
|
+
Bundler.setup :test
|
7
|
+
|
8
|
+
require 'test/unit'
|
9
|
+
require 'webmock/test_unit'
|
10
|
+
include WebMock::API
|
11
|
+
|
12
|
+
require 'runkeeper_activities'
|
13
|
+
|
14
|
+
class Test::Unit::TestCase
|
15
|
+
def data_dir
|
16
|
+
File.join(File.dirname(__FILE__), 'data')
|
17
|
+
end
|
18
|
+
|
19
|
+
def stub_get_profile
|
20
|
+
stub_request(:get, /runkeeper.com\/user\/.+\/activity$/).to_return(File.new(File.join(data_dir, 'profile.txt')))
|
21
|
+
end
|
22
|
+
|
23
|
+
def stub_get_non_existing_profile
|
24
|
+
stub_request(:get, /runkeeper.com\/user\/non-existing\/activity$/).to_return(File.new(File.join(data_dir, 'non_existing_profile.txt')))
|
25
|
+
end
|
26
|
+
|
27
|
+
def stub_get_activity
|
28
|
+
stub_request(:get, /runkeeper.com\/user\/.+\/activity\/.+/).to_return(File.new(File.join(data_dir, 'activity.txt')))
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class RunkeeperActivityTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_should_get_full_activity_info
|
6
|
+
stub_get_profile
|
7
|
+
stub_get_activity
|
8
|
+
runkeeper_user = RunKeeperActivities::User.find_by_username('kittensrule')
|
9
|
+
runkeeper_user.activities.first.tap do |_activity|
|
10
|
+
assert_equal '37709325', _activity.id
|
11
|
+
assert_equal 'Running', _activity.type
|
12
|
+
assert_equal '2011-06-01 18:16:16 +0200', _activity.start_time.to_s
|
13
|
+
assert_equal '2011-06-01 19:23:34 +0200', _activity.end_time.to_s
|
14
|
+
assert_equal '10.26', _activity.distance
|
15
|
+
assert_equal '1:07:18', _activity.duration
|
16
|
+
assert_equal '6:34', _activity.pace
|
17
|
+
assert_equal '9.15', _activity.speed
|
18
|
+
assert_equal '919', _activity.calories
|
19
|
+
assert_equal '76', _activity.elevation
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_should_generate_summery
|
24
|
+
stub_get_profile
|
25
|
+
runkeeper_user = RunKeeperActivities::User.find_by_username('kittensrule')
|
26
|
+
assert_equal "Arvid Andersson completed a 10.26 km running activity", runkeeper_user.activities.first.summery
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class RunkeeperUserTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_should_get_user_info
|
6
|
+
stub_get_profile
|
7
|
+
runkeeper_user = RunKeeperActivities::User.find_by_username('kittensrule')
|
8
|
+
assert_equal 'http://runkeeper.com/user/kittensrule/profile', runkeeper_user.profile_url
|
9
|
+
assert_equal 'Arvid Andersson', runkeeper_user.name
|
10
|
+
assert_equal 'http://s3.amazonaws.com/profilepic.runkeeper.com/5efrz7a3uZ9pZeCj0bDKiFUj_sm.jpg?', runkeeper_user.profile_image_url
|
11
|
+
assert_equal 'km', runkeeper_user.distance_unit
|
12
|
+
assert_equal 'h : m : s', runkeeper_user.duration_unit
|
13
|
+
assert_equal 'min/km', runkeeper_user.pace_unit
|
14
|
+
assert_equal 'km/h', runkeeper_user.speed_unit
|
15
|
+
assert_equal 'calories', runkeeper_user.calories_unit
|
16
|
+
assert_equal 'm', runkeeper_user.elevation_unit
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_should_raise_on_404
|
20
|
+
stub_get_non_existing_profile
|
21
|
+
assert_raises(OpenURI::HTTPError) { RunKeeperActivities::User.find_by_username('non-existing') }
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_get_user_activities
|
25
|
+
stub_get_profile
|
26
|
+
runkeeper_user = RunKeeperActivities::User.find_by_username('kittensrule')
|
27
|
+
assert_kind_of Array, runkeeper_user.activities
|
28
|
+
runkeeper_user.activities.first.tap do |activity|
|
29
|
+
assert_equal 'http://runkeeper.com/user/arvida/activity/37709325', activity.url
|
30
|
+
assert_equal '37709325', activity.id
|
31
|
+
assert_equal '10.26', activity.distance
|
32
|
+
assert_equal 'Running', activity.type
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: runkeeper-activities
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Arvid Andersson
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-05 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: bundler
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 23
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
version: 1.0.0
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: addressable
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 11
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 2
|
49
|
+
- 6
|
50
|
+
version: 2.2.6
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: webmock
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 7
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 6
|
65
|
+
- 4
|
66
|
+
version: 1.6.4
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: nokogiri
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 15
|
78
|
+
segments:
|
79
|
+
- 1
|
80
|
+
- 4
|
81
|
+
- 4
|
82
|
+
version: 1.4.4
|
83
|
+
type: :runtime
|
84
|
+
version_requirements: *id004
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: yajl-ruby
|
87
|
+
prerelease: false
|
88
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 59
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
- 8
|
97
|
+
- 2
|
98
|
+
version: 0.8.2
|
99
|
+
type: :runtime
|
100
|
+
version_requirements: *id005
|
101
|
+
description: A ruby interface for the latest activites on RunKeeper
|
102
|
+
email:
|
103
|
+
- arvid.andersson@oktavilla.se
|
104
|
+
executables: []
|
105
|
+
|
106
|
+
extensions: []
|
107
|
+
|
108
|
+
extra_rdoc_files: []
|
109
|
+
|
110
|
+
files:
|
111
|
+
- test/data/activity.txt
|
112
|
+
- test/data/non_existing_profile.txt
|
113
|
+
- test/data/profile.txt
|
114
|
+
- test/test_helper.rb
|
115
|
+
- test/unit/runkeeper_activity_test.rb
|
116
|
+
- test/unit/runkeeper_user_test.rb
|
117
|
+
- lib/runkeeper_activities/activity.rb
|
118
|
+
- lib/runkeeper_activities/user.rb
|
119
|
+
- lib/runkeeper_activities/utils.rb
|
120
|
+
- lib/runkeeper_activities/version.rb
|
121
|
+
- lib/runkeeper_activities.rb
|
122
|
+
- README.rdoc
|
123
|
+
- runkeeper-activities.gemspec
|
124
|
+
- Rakefile
|
125
|
+
- Gemfile
|
126
|
+
has_rdoc: true
|
127
|
+
homepage: http://github.org/arvida/runkeeper-activities
|
128
|
+
licenses: []
|
129
|
+
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
none: false
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
hash: 3
|
141
|
+
segments:
|
142
|
+
- 0
|
143
|
+
version: "0"
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
hash: 23
|
150
|
+
segments:
|
151
|
+
- 1
|
152
|
+
- 3
|
153
|
+
- 6
|
154
|
+
version: 1.3.6
|
155
|
+
requirements: []
|
156
|
+
|
157
|
+
rubyforge_project:
|
158
|
+
rubygems_version: 1.4.2
|
159
|
+
signing_key:
|
160
|
+
specification_version: 3
|
161
|
+
summary: Scraper for latest activites on RunKeeper
|
162
|
+
test_files: []
|
163
|
+
|