Class: RunKeeperActivities::Activity
- Inherits:
-
Object
- Object
- RunKeeperActivities::Activity
- Defined in:
- lib/runkeeper_activities/activity.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #calories ⇒ Object
- #data ⇒ Object
- #distance ⇒ Object
- #duration ⇒ Object
- #elevation ⇒ Object
- #end_time ⇒ Object
- #id ⇒ Object
-
#initialize(options = {}) ⇒ Activity
constructor
A new instance of Activity.
- #json_endpoint ⇒ Object
- #message ⇒ Object
- #pace ⇒ Object
- #raw_json_data ⇒ Object
- #speed ⇒ Object
- #start_time ⇒ Object
- #summery ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Activity
Returns a new instance of Activity.
20 21 22 |
# File 'lib/runkeeper_activities/activity.rb', line 20 def initialize( = {}) .each { |k,v| instance_variable_set("@#{k}".to_sym, v) } end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/runkeeper_activities/activity.rb', line 3 def type @type end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/runkeeper_activities/activity.rb', line 3 def url @url end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
3 4 5 |
# File 'lib/runkeeper_activities/activity.rb', line 3 def user @user end |
Class Method Details
.activities_from_user(user) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/runkeeper_activities/activity.rb', line 8 def activities_from_user(user) user.page.css('#activityHistoryMenu .menuItem').collect do |_feed_item| RunKeeperActivities::Activity.new({ :user => user, :url => Utils.runkeeper_url(_feed_item['link']), :distance => _feed_item.at_css('.distance').text, :type => _feed_item.at_css('.mainText').text }) end end |
Instance Method Details
#calories ⇒ Object
52 53 54 |
# File 'lib/runkeeper_activities/activity.rb', line 52 def calories @calories ||= data[:statsCalories] end |
#data ⇒ Object
68 69 70 |
# File 'lib/runkeeper_activities/activity.rb', line 68 def data @data ||= Yajl::Parser.parse(raw_json_data, :symbolize_keys => true) end |
#distance ⇒ Object
36 37 38 |
# File 'lib/runkeeper_activities/activity.rb', line 36 def distance @distance ||= data[:statsDistance] end |
#duration ⇒ Object
40 41 42 |
# File 'lib/runkeeper_activities/activity.rb', line 40 def duration @duration ||= data[:statsDuration] end |
#elevation ⇒ Object
56 57 58 |
# File 'lib/runkeeper_activities/activity.rb', line 56 def elevation @elevation ||= data[:statsElevation] end |
#end_time ⇒ Object
32 33 34 |
# File 'lib/runkeeper_activities/activity.rb', line 32 def end_time @end_time ||= (data[:points] and data[:points].any?) ? Time.parse(data[:points].last[:time]) : nil end |
#id ⇒ Object
24 25 26 |
# File 'lib/runkeeper_activities/activity.rb', line 24 def id @id ||= (_match = @url.match(/\/(\d+)$/)) ? _match[1] : (raise "Need profile url to find user id") end |
#json_endpoint ⇒ Object
72 73 74 |
# File 'lib/runkeeper_activities/activity.rb', line 72 def json_endpoint @json_endpoint ||= Utils.runkeeper_url("/ajax/pointData?activityId=#{id}") end |
#message ⇒ Object
60 61 62 |
# File 'lib/runkeeper_activities/activity.rb', line 60 def ||= data[:feedData][:message] end |
#pace ⇒ Object
44 45 46 |
# File 'lib/runkeeper_activities/activity.rb', line 44 def pace @pace ||= data[:statsPace] end |
#raw_json_data ⇒ Object
76 77 78 |
# File 'lib/runkeeper_activities/activity.rb', line 76 def raw_json_data @raw_json_data ||= open(json_endpoint).readlines.join("\n").encode('UTF-8') end |
#speed ⇒ Object
48 49 50 |
# File 'lib/runkeeper_activities/activity.rb', line 48 def speed @speed ||= data[:statsSpeed] end |
#start_time ⇒ Object
28 29 30 |
# File 'lib/runkeeper_activities/activity.rb', line 28 def start_time @start_time ||= (data[:points] and data[:points].any?) ? Time.parse(data[:points][0][:time]) : nil end |
#summery ⇒ Object
64 65 66 |
# File 'lib/runkeeper_activities/activity.rb', line 64 def summery @summery ||= "#{user.name} completed a #{distance} #{user.distance_unit} #{type.downcase} activity" end |