Class: ZipFinder::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/zipfinder/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_adapter = RestClientAdapter, response_handler = ResponseHandler.new) ⇒ Client

Returns a new instance of Client.



10
11
12
13
# File 'lib/zipfinder/client.rb', line 10

def initialize(http_adapter = RestClientAdapter, response_handler = ResponseHandler.new)
  @http_adapter = http_adapter
  @response_handler = response_handler
end

Instance Attribute Details

#http_adapterObject

Returns the value of attribute http_adapter.



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

def http_adapter
  @http_adapter
end

#response_handlerObject

Returns the value of attribute response_handler.



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

def response_handler
  @response_handler
end

Class Method Details

.get(zipcode) ⇒ Object



6
7
8
# File 'lib/zipfinder/client.rb', line 6

def self.get(zipcode)
  ZipFinder::Client.new.get(zipcode)
end

Instance Method Details

#get(zipcode) ⇒ Object



15
16
17
18
19
# File 'lib/zipfinder/client.rb', line 15

def get(zipcode)
  url = build_url(zipcode)
  response = http_adapter.http_get(url)
  response_handler.process(response)
end