Module: Strava::BaseConnection

Included in:
V1::Connection, V2::Connection
Defined in:
lib/strava/base_connection.rb

Instance Method Summary collapse

Instance Method Details

#fetch(relative_uri, options) ⇒ Object

Raises:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/strava/base_connection.rb', line 6

def fetch(relative_uri, options)
  response = nil
  begin
    response = self.class.get("/#{relative_uri}", :query => options)
  rescue HTTParty::UnsupportedFormat, HTTParty::UnsupportedURIScheme, HTTParty::ResponseError, HTTParty::RedirectionTooDeep
    # if it's something we understand, it's probably a bad request.
    raise RequestError.new
  rescue Exception => e
    # anything else is presumably not from HTTParty - throw generic network error.
    raise NetworkError.new(e)
  end

  case response.code
    when 500...600
      raise StravaError.new
    when 404
      raise '404ed'
    when 200
      return response.parsed_response
  end
  raise NetworkError.new('Bad status ' + response.code.to_s)
end