Class: BrasilAPI::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/brasil_api/base.rb

Direct Known Subclasses

Bank, Company

Constant Summary collapse

BASE_URL =
"https://brasilapi.com.br/api"

Class Method Summary collapse

Class Method Details

.get(path) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/brasil_api/base.rb', line 11

def get(path)
  uri = URI("#{BASE_URL}#{path}")

  response = Net::HTTP.get_response(uri)

  case status_for(response)
  when 200
    parsed_body(response)
  when 404
    raise BrasilAPI::NotFound
  else
    raise BrasilAPI::Error
  end
end