Class: Brapi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/brapi/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(access_token, user_agent) ⇒ Client

Returns a new instance of Client.



4
5
6
7
# File 'lib/brapi/client.rb', line 4

def initialize(access_token, user_agent)
  @access_token = access_token
  @user_agent = user_agent
end

Instance Method Details

#zipcode(zipcode) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/brapi/client.rb', line 9

def zipcode(zipcode)
  endpoint = "#{base_uri}/zipcodes/#{zipcode}.json"
  RestClient.get(endpoint, { accept: :json, content_type: :json, 'User-Agent' => user_agent }) do |response|
    case response.code
    when 200
      Brapi::Zipcode.new(JSON.parse(response))
    else
      raise Brapi::Error, response
    end
  end
end