class AddressFinder::LocationSearch
Attributes
Public Class Methods
Source
# File lib/addressfinder/location_search.rb, line 8 def initialize(params:, http:) @http = http @country = params.delete(:country) || config.default_country @params = params @params['domain'] = params['domain'] || config.domain if (params['domain'] || config.domain) @params[:key] ||= config.api_key @params[:secret] ||= config.api_secret end
Public Instance Methods
Source
# File lib/addressfinder/location_search.rb, line 18 def perform build_request execute_request build_result self end
Private Instance Methods
Source
# File lib/addressfinder/location_search.rb, line 32 def build_request @request_uri = "/api/#{country}/location.json?#{encoded_params}" end
Source
# File lib/addressfinder/location_search.rb, line 47 def build_result case response_status when '200' self.results = response_hash['completions'].map do |result_hash| Result.new(result_hash) end else raise AddressFinder::RequestRejectedError.new(@response_status, @response_body) end end
Source
# File lib/addressfinder/location_search.rb, line 62 def config @_config ||= AddressFinder.configuration end
Source
# File lib/addressfinder/location_search.rb, line 36 def encoded_params Util.encode_and_join_params(params) end
Source
# File lib/addressfinder/location_search.rb, line 40 def execute_request response = http.request(request_uri) self.response_body = response.body self.response_status = response.code end
Source
# File lib/addressfinder/location_search.rb, line 58 def response_hash @_response_hash ||= MultiJson.load(response_body) end