runkeeper-activities 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,6 +10,8 @@ I have been using RunKeeper to track my running for about two years and really l
10
10
  is no official API or RSS-feed for your data yet, from their support forum it looks like it's planned for the future.
11
11
  I started to feel the urge to be able to access my recent activites on RunKeeper via Ruby so I made this gem.
12
12
 
13
+ *Update* 7 June - {A ”graph” API is on the way}[http://developer.runkeeper.com]
14
+
13
15
  == Installation
14
16
 
15
17
  If your using Bundler add the gem to your Gemfile
@@ -27,14 +29,14 @@ and require the gem with
27
29
  require 'runkeeper-activities'
28
30
  user = RunKeeperActivities::User.find_by_username(YOUR_RUNKEEPER_USERNAME)
29
31
  activity = user.activities.first
30
- puts "On #{activity.start_time} #{user.name} completed a #{activity.distance} #{activity.distance_unit} #{activity.type.downcase} activity"
32
+ puts "On #{activity.start_time} #{user.name} completed a #{activity.distance} #{user.distance_unit} #{activity.type.downcase} activity"
31
33
 
32
34
  === Available data
33
35
 
34
36
  On a +User+ instance you have access to +username+, +name+, +profile_url+, +profile_image_url+, +distance_unit+, +duration_unit+,
35
37
  +pace_unit+, +speed_unit+, +calories_unit+, +elevation_unit+ and +activities+.
36
38
  On a +Activity+ instance you can access +start_time+, +end_time+, +distance+, +duration+, +pace+, +speed+, +calories+, +elevation+
37
- and +summery+.
39
+ +message+ and +summery+.
38
40
 
39
41
  There is a bunch of more data available on RunKeeper that should be pretty easy to add support for.
40
42
 
@@ -26,51 +26,55 @@ module RunKeeperActivities
26
26
  end
27
27
 
28
28
  def start_time
29
- @start_time ||= (raw_data[:points] and raw_data[:points].any?) ? Time.parse(raw_data[:points][0][:time]) : nil
29
+ @start_time ||= (data[:points] and data[:points].any?) ? Time.parse(data[:points][0][:time]) : nil
30
30
  end
31
31
 
32
32
  def end_time
33
- @end_time ||= (raw_data[:points] and raw_data[:points].any?) ? Time.parse(raw_data[:points].last[:time]) : nil
33
+ @end_time ||= (data[:points] and data[:points].any?) ? Time.parse(data[:points].last[:time]) : nil
34
34
  end
35
35
 
36
36
  def distance
37
- @distance ||= raw_data[:statsDistance]
37
+ @distance ||= data[:statsDistance]
38
38
  end
39
39
 
40
40
  def duration
41
- @duration ||= raw_data[:statsDuration]
41
+ @duration ||= data[:statsDuration]
42
42
  end
43
43
 
44
44
  def pace
45
- @pace ||= raw_data[:statsPace]
45
+ @pace ||= data[:statsPace]
46
46
  end
47
47
 
48
48
  def speed
49
- @speed ||= raw_data[:statsSpeed]
49
+ @speed ||= data[:statsSpeed]
50
50
  end
51
51
 
52
52
  def calories
53
- @calories ||= raw_data[:statsCalories]
53
+ @calories ||= data[:statsCalories]
54
54
  end
55
55
 
56
56
  def elevation
57
- @elevation ||= raw_data[:statsElevation]
57
+ @elevation ||= data[:statsElevation]
58
+ end
59
+
60
+ def message
61
+ @message ||= data[:feedData][:message]
58
62
  end
59
63
 
60
64
  def summery
61
65
  @summery ||= "#{user.name} completed a #{distance} #{user.distance_unit} #{type.downcase} activity"
62
66
  end
63
67
 
68
+ def data
69
+ @data ||= Yajl::Parser.parse(raw_json_data, :symbolize_keys => true)
70
+ end
71
+
64
72
  def json_endpoint
65
73
  @json_endpoint ||= Utils.runkeeper_url("/ajax/pointData?activityId=#{id}")
66
74
  end
67
75
 
68
- def raw_data
69
- @raw_data ||= {}.tap do |_raw_data|
70
- Yajl::HttpStream.get(json_endpoint, :symbolize_keys => true) do |_data|
71
- _raw_data.merge!(_data)
72
- end
73
- end
76
+ def raw_json_data
77
+ @raw_json_data ||= open(json_endpoint).readlines.join("\n").encode('UTF-8')
74
78
  end
75
79
  end
76
80
  end
@@ -1,3 +1,3 @@
1
1
  module RunKeeperActivites
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -9,7 +9,7 @@ require 'test/unit'
9
9
  require 'webmock/test_unit'
10
10
  include WebMock::API
11
11
 
12
- require 'runkeeper_activities'
12
+ require 'runkeeper-activities'
13
13
 
14
14
  class Test::Unit::TestCase
15
15
  def data_dir
@@ -25,6 +25,6 @@ class Test::Unit::TestCase
25
25
  end
26
26
 
27
27
  def stub_get_activity
28
- stub_request(:get, /runkeeper.com\/user\/.+\/activity\/.+/).to_return(File.new(File.join(data_dir, 'activity.txt')))
28
+ stub_request(:get, /runkeeper.com\/ajax\/.+/).to_return(File.new(File.join(data_dir, 'activity.txt')))
29
29
  end
30
30
  end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runkeeper-activities
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 3
10
- version: 0.0.3
5
+ version: 0.0.4
11
6
  platform: ruby
12
7
  authors:
13
8
  - Arvid Andersson
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-06-05 00:00:00 +02:00
13
+ date: 2011-06-07 00:00:00 +02:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,11 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ">="
28
23
  - !ruby/object:Gem::Version
29
- hash: 23
30
- segments:
31
- - 1
32
- - 0
33
- - 0
34
24
  version: 1.0.0
35
25
  type: :development
36
26
  version_requirements: *id001
@@ -42,11 +32,6 @@ dependencies:
42
32
  requirements:
43
33
  - - ">="
44
34
  - !ruby/object:Gem::Version
45
- hash: 11
46
- segments:
47
- - 2
48
- - 2
49
- - 6
50
35
  version: 2.2.6
51
36
  type: :development
52
37
  version_requirements: *id002
@@ -58,11 +43,6 @@ dependencies:
58
43
  requirements:
59
44
  - - ">="
60
45
  - !ruby/object:Gem::Version
61
- hash: 7
62
- segments:
63
- - 1
64
- - 6
65
- - 4
66
46
  version: 1.6.4
67
47
  type: :development
68
48
  version_requirements: *id003
@@ -74,11 +54,6 @@ dependencies:
74
54
  requirements:
75
55
  - - ">="
76
56
  - !ruby/object:Gem::Version
77
- hash: 15
78
- segments:
79
- - 1
80
- - 4
81
- - 4
82
57
  version: 1.4.4
83
58
  type: :runtime
84
59
  version_requirements: *id004
@@ -90,11 +65,6 @@ dependencies:
90
65
  requirements:
91
66
  - - ">="
92
67
  - !ruby/object:Gem::Version
93
- hash: 59
94
- segments:
95
- - 0
96
- - 8
97
- - 2
98
68
  version: 0.8.2
99
69
  type: :runtime
100
70
  version_requirements: *id005
@@ -137,25 +107,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
107
  requirements:
138
108
  - - ">="
139
109
  - !ruby/object:Gem::Version
140
- hash: 3
141
- segments:
142
- - 0
143
110
  version: "0"
144
111
  required_rubygems_version: !ruby/object:Gem::Requirement
145
112
  none: false
146
113
  requirements:
147
114
  - - ">="
148
115
  - !ruby/object:Gem::Version
149
- hash: 23
150
- segments:
151
- - 1
152
- - 3
153
- - 6
154
116
  version: 1.3.6
155
117
  requirements: []
156
118
 
157
119
  rubyforge_project:
158
- rubygems_version: 1.4.2
120
+ rubygems_version: 1.6.2
159
121
  signing_key:
160
122
  specification_version: 3
161
123
  summary: Scraper for latest activities on RunKeeper