Class: NikeV2::Activity
- Inherits:
-
Resource
show all
- Extended by:
- Forwardable
- Defined in:
- lib/nike_v2/activity.rb
Constant Summary
collapse
- API_URL =
'/me/sport/activities'
Constants inherited
from Resource
Resource::RESP_MSG_INVALID_TOKEN
Instance Method Summary
collapse
Methods inherited from Resource
#fetch_data, #get
Constructor Details
#initialize(attributes = {}) ⇒ Activity
Returns a new instance of Activity.
17
18
19
20
21
22
23
|
# File 'lib/nike_v2/activity.rb', line 17
def initialize(attributes = {})
raise "#{self.class} requires s person." unless attributes.keys.include?(:person)
raise "#{self.class} requires an activityId." unless attributes.keys.include?('activityId')
build_metrics(attributes)
super(attributes)
end
|
Instance Method Details
#ended_at ⇒ Object
some reason activities aren’t always complete so we need metrics to figure out how long they are
51
52
53
|
# File 'lib/nike_v2/activity.rb', line 51
def ended_at
@ended_at ||= self.respond_to?(:end_time) ? Time.parse(self.end_time.gsub('Z', '-') + '00:00') : started_at + (metrics.durations.to.seconds).to_f
end
|
#gps_data ⇒ Object
29
30
31
|
# File 'lib/nike_v2/activity.rb', line 29
def gps_data
@gps_data ||= NikeV2::GpsData.new(:activity => self)
end
|
#load_data ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/nike_v2/activity.rb', line 38
def load_data
data = fetch_data
build_metrics(data)
set_attributes(data)
true
end
|
#metrics ⇒ Object
33
34
35
36
|
# File 'lib/nike_v2/activity.rb', line 33
def metrics
load_data unless @metrics.is_a?(NikeV2::Metrics)
@metrics
end
|
#started_at ⇒ Object
46
47
48
|
# File 'lib/nike_v2/activity.rb', line 46
def started_at
@started_at ||= Time.parse(self.start_time.gsub('Z', '-') + '00:00')
end
|
63
64
65
|
# File 'lib/nike_v2/activity.rb', line 63
def tags_as_hash
Hash[tags.map {|k| [k['tagType'].downcase.to_sym, k['tagValue']] }]
end
|
#to_tz(time) ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/nike_v2/activity.rb', line 55
def to_tz(time)
if time.respond_to?(:strftime)
return Time.parse(time.strftime('%Y-%m-%d %H:%M:%S ' + self.tz.to_s))
else
return Time.parse(time + ' ' + self.tz.to_s)
end
end
|
#tz ⇒ Object
25
26
27
|
# File 'lib/nike_v2/activity.rb', line 25
def tz
TZInfo::Timezone.get(self.activity_time_zone)
end
|