module Soccerama::Client::Connection

Public Instance Methods

get(path, options = {}) click to toggle source
# File lib/soccerama/client/connection.rb, line 5
def get(path, options = {})
  req :get, path, options
end

Private Instance Methods

req(http_method, path, options = {}) click to toggle source
# File lib/soccerama/client/connection.rb, line 11
def req(http_method, path, options = {})
  normalizer = HTTParty::Request::NON_RAILS_QUERY_STRING_NORMALIZER
  options[:api_token] = @api_token
  response = self.class.send(http_method, path, query: normalizer[options])
  resp = JSON.parse(response.body)
  if resp['error']
    if resp['error']['code'] == 401
      raise Soccerama::Exceptions::UnpaidPlanException, resp['error']['message']
    elsif resp['error']['code'] == 500
      raise Soccerama::Exceptions::InvalidRequest, resp['error']['message']
    end
  else
    resp
  end
end