Class: StravaApi::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty, Clubs, Efforts, Rides, Segments
Defined in:
lib/strava-api/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Efforts

#effort_show

Methods included from Segments

#segment_efforts, #segment_show, #segments

Methods included from Rides

#ride_efforts, #ride_show, #ride_streams, #rides

Methods included from Clubs

#club_members, #club_show, #clubs

Constructor Details

#initializeBase

Returns a new instance of Base.



15
16
17
# File 'lib/strava-api/base.rb', line 15

def initialize
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



13
14
15
# File 'lib/strava-api/base.rb', line 13

def errors
  @errors
end

Instance Method Details

#call(command, key, options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/strava-api/base.rb', line 19

def call(command, key, options)
  begin
    result = self.class.get("/#{command}", :query => options)
  rescue HTTParty::UnsupportedFormat, HTTParty::UnsupportedURIScheme, HTTParty::ResponseError, HTTParty::RedirectionTooDeep
    raise NetworkError.new
  end
  
  if result && result.parsed_response == "<html><body><h1>500 Internal Server Error</h1></body></html>"
    @errors << "Strava returned a 500 error"
    raise CommandError.new 
  end
  
  @errors << result["error"] if result && result["error"]
  raise InvalidResponseError.new if result.nil? || !result["error"].blank? || (!key.nil? && result[key].nil?)
  
  result
end