Class: SgPostcode::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/sg_postcode/response/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(raw_data, response_type: :json) ⇒ Response

Returns a new instance of Response.



5
6
7
8
# File 'lib/sg_postcode/response/response.rb', line 5

def initialize(raw_data, response_type: :json)
  @raw_data = JSON.parse(raw_data)
  @response_type = response_type
end

Instance Method Details

#dataObject

build the data hash may use Builder object to contruct the output data



13
14
15
16
17
18
19
20
# File 'lib/sg_postcode/response/response.rb', line 13

def data
  case @response_type
  when :json
    ResponseBuilder::JsonOutput.new(@raw_data).data
  else
    nil
  end
end