Class: Runkeeper::Activity
- Inherits:
-
Object
- Object
- Runkeeper::Activity
- Defined in:
- lib/runkeeper/activity.rb
Instance Attribute Summary collapse
-
#average_heart_rate ⇒ Object
Returns the value of attribute average_heart_rate.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#path ⇒ Object
Returns the value of attribute path.
-
#post_to_facebook ⇒ Object
Returns the value of attribute post_to_facebook.
-
#post_to_twitter ⇒ Object
Returns the value of attribute post_to_twitter.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#total_calories ⇒ Object
Returns the value of attribute total_calories.
-
#total_distance ⇒ Object
Returns the value of attribute total_distance.
-
#type ⇒ Object
Returns the value of attribute type.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #formatted_start_time ⇒ Object
- #id ⇒ Object
-
#initialize(connection, attrs) ⇒ Activity
constructor
A new instance of Activity.
- #optional_attrs ⇒ Object
- #save ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(connection, attrs) ⇒ Activity
Returns a new instance of Activity.
7 8 9 10 11 12 13 |
# File 'lib/runkeeper/activity.rb', line 7 def initialize(connection, attrs) @connection = connection @attrs = attrs attrs.each do |k,v| instance_variable_set("@#{k}", v) end end |
Instance Attribute Details
#average_heart_rate ⇒ Object
Returns the value of attribute average_heart_rate.
5 6 7 |
# File 'lib/runkeeper/activity.rb', line 5 def average_heart_rate @average_heart_rate end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
4 5 6 |
# File 'lib/runkeeper/activity.rb', line 4 def connection @connection end |
#duration ⇒ Object
Returns the value of attribute duration.
5 6 7 |
# File 'lib/runkeeper/activity.rb', line 5 def duration @duration end |
#notes ⇒ Object
Returns the value of attribute notes.
5 6 7 |
# File 'lib/runkeeper/activity.rb', line 5 def notes @notes end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/runkeeper/activity.rb', line 5 def path @path end |
#post_to_facebook ⇒ Object
Returns the value of attribute post_to_facebook.
5 6 7 |
# File 'lib/runkeeper/activity.rb', line 5 def post_to_facebook @post_to_facebook end |
#post_to_twitter ⇒ Object
Returns the value of attribute post_to_twitter.
5 6 7 |
# File 'lib/runkeeper/activity.rb', line 5 def post_to_twitter @post_to_twitter end |
#start_time ⇒ Object
Returns the value of attribute start_time.
5 6 7 |
# File 'lib/runkeeper/activity.rb', line 5 def start_time @start_time end |
#total_calories ⇒ Object
Returns the value of attribute total_calories.
5 6 7 |
# File 'lib/runkeeper/activity.rb', line 5 def total_calories @total_calories end |
#total_distance ⇒ Object
Returns the value of attribute total_distance.
5 6 7 |
# File 'lib/runkeeper/activity.rb', line 5 def total_distance @total_distance end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/runkeeper/activity.rb', line 5 def type @type end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
4 5 6 |
# File 'lib/runkeeper/activity.rb', line 4 def url @url end |
Instance Method Details
#formatted_start_time ⇒ Object
23 24 25 |
# File 'lib/runkeeper/activity.rb', line 23 def formatted_start_time start_time.strftime("%a, %d %b %Y %H:%M:%S %Z") end |
#id ⇒ Object
19 20 21 |
# File 'lib/runkeeper/activity.rb', line 19 def id @save_response && @save_response.headers['location'][/\d+$/] end |
#optional_attrs ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/runkeeper/activity.rb', line 36 def optional_attrs h = {} [ :total_distance, :average_heart_rate, :total_calories, :notes, :path, :post_to_facebook, :post_to_twitter ].each do |method_name| v = send(method_name) h[method_name] = v if v end h end |
#save ⇒ Object
15 16 17 |
# File 'lib/runkeeper/activity.rb', line 15 def save @save_response = connection.save_activity(to_hash) end |
#to_hash ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/runkeeper/activity.rb', line 27 def to_hash main = { :type => type, :start_time => formatted_start_time, :duration => duration } main.merge! optional_attrs end |