class Strava::Client

Constants

BASE_URL

Attributes

token[R]
usage[R]

@return [Usage] Information on API quota usage

Public Class Methods

new(token) click to toggle source
# File lib/strava/client.rb, line 9
def initialize(token)
  @token = token
end

Public Instance Methods

check_for_error(response) click to toggle source
# File lib/strava/client.rb, line 46
def check_for_error(response)
  @usage = Usage.new(response.headers['X-Ratelimit-Limit'], response.headers['X-Ratelimit-Usage'])
  case response.code
  when 401, 403
    raise Strava::AccessError.new(response.to_h)
  end
end
delete(path, **params) click to toggle source
# File lib/strava/client.rb, line 25
def delete(path, **params)
  make_request(:delete, path, **params)
end
get(path, **params) click to toggle source
# File lib/strava/client.rb, line 13
def get(path, **params)
  make_request(:get, path, **params)
end
handle_params(params) click to toggle source
# File lib/strava/client.rb, line 37
def handle_params(params)
  if @token
    params.merge!(access_token: @token)
  else
    params.merge!(client_id: Strava.client_id, client_secret: Strava.secret)
  end
  params.reverse_each { |k, v| params.delete(k) if v.nil? }
end
list_races(year = Time.now.year) click to toggle source

non athlete calls

# File lib/strava/client.rb, line 56
def list_races(year = Time.now.year)
  RunningRace.list_races(self, year)
end
make_request(verb, path, **params) click to toggle source
# File lib/strava/client.rb, line 29
def make_request(verb, path, **params)
  puts (params[:host] || BASE_URL) + path
  handle_params(params)
  res = HTTParty.send(verb, (params.delete(:host) || BASE_URL) + path, query: params)
  check_for_error(res)
  res
end
post(path, **params) click to toggle source
# File lib/strava/client.rb, line 17
def post(path, **params)
  make_request(:post, path, **params)
end
put(path, **params) click to toggle source
# File lib/strava/client.rb, line 21
def put(path, **params)
  make_request(:put, path, **params)
end
segment_explorer(bounds = '37.821362,-122.505373,37.842038,-122.465977') click to toggle source
# File lib/strava/client.rb, line 60
def segment_explorer(bounds = '37.821362,-122.505373,37.842038,-122.465977')
  Segment.explorer(self, bounds)
end