Class: Probasketball::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/probasketball/api.rb

Defined Under Namespace

Modules: Response

Constant Summary collapse

BASE_URLS =
{
  :v1 => 'https://probasketballapi.com/',
  :v2 => 'http://api.probasketballapi.com/'
}

Instance Method Summary collapse

Constructor Details

#initialize(api_key, options = {}) ⇒ Api

Returns a new instance of Api.



5
6
7
8
# File 'lib/probasketball/api.rb', line 5

def initialize(api_key, options = {})
  @api_key = api_key
  @options = options
end

Instance Method Details

#post(url, params = {}) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/probasketball/api.rb', line 15

def post(url, params = {})
  response = RestClient.post build_url(url), build_params(params), headers
  Response::Success.new(JSON.parse(response), response.code)
rescue RestClient::ExceptionWithResponse => e
  Response::Error.new(e.message)
rescue JSON::ParserError => e
  Response::Error.new(response.body)
end