Class: Strava::Base Abstract
- Inherits:
-
Object
- Object
- Strava::Base
- Defined in:
- lib/strava/base.rb
Overview
This class is abstract.
Base class for Strava objects. Handles setting up the object, mainly data and a client.
Direct Known Subclasses
Activity, Athlete, Club, ClubAnnouncement, Comment, Gear, GroupEvent, Lap, Leaderboard, LeaderboardEntry, Photo, Route, RunningRace, Segment, SegmentEffort
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #detailed? ⇒ Boolean
-
#initialize(data, client: nil, token: nil, **opts) ⇒ Base
constructor
A new instance of Base.
- #resource_state ⇒ Object
- #summary? ⇒ Boolean
-
#update(data, **opts) ⇒ Object
abstract
Parse incoming data.
Constructor Details
#initialize(data, client: nil, token: nil, **opts) ⇒ Base
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/strava/base.rb', line 9 def initialize(data, client: nil, token: nil, **opts) raise 'missing client or access token' unless (client || token) @client = client || Client.new(token) if data.is_a?(Hash) @id = data['id'] set_ivars update(data, **opts) else @id = data set_ivars end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/strava/base.rb', line 7 def client @client end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/strava/base.rb', line 7 def id @id end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/strava/base.rb', line 7 def response @response end |
Class Method Details
.resource_states ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/strava/base.rb', line 77 def self.resource_states @resource_states ||= { 1 => 'meta', 2 => 'summary', 3 => 'detailed', } end |
Instance Method Details
#detailed? ⇒ Boolean
73 74 75 |
# File 'lib/strava/base.rb', line 73 def detailed? @resource_state == 3 end |
#resource_state ⇒ Object
65 66 67 |
# File 'lib/strava/base.rb', line 65 def resource_state self.class.resource_states[@resource_state] end |
#summary? ⇒ Boolean
69 70 71 |
# File 'lib/strava/base.rb', line 69 def summary? @resource_state == 2 end |
#update(data, **opts) ⇒ Object
This method is abstract.
Parse incoming data. Should be defined by subclasses.
26 27 28 29 30 |
# File 'lib/strava/base.rb', line 26 def update(data, **opts) @response = data @resource_state = data['resource_state'] self end |