Class: ZipFinder::ResponseHandler

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/zipfinder/response_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json_adapter = JSON) ⇒ ResponseHandler

Returns a new instance of ResponseHandler.



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

def initialize(json_adapter = JSON)
  @json_adapter = json_adapter
end

Instance Attribute Details

#json_adapterObject

Returns the value of attribute json_adapter.



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

def json_adapter
  @json_adapter
end

Instance Method Details

#process(response) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/zipfinder/response_handler.rb', line 10

def process(response)
  if response.status == 200
    json_adapter.parse response.body
  else
    log "ZipFinder::RequestFailedError : #{response.message}"
    raise RequestFailedError, response.message
  end
end