Class: Strava::Base Abstract

Inherits:
Object
  • Object
show all
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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/strava/base.rb', line 7

def client
  @client
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/strava/base.rb', line 7

def id
  @id
end

#responseObject (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_statesObject



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_stateObject



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