class AddressFinder::V1::Base
Attributes
Public Class Methods
Source
# File lib/addressfinder/v1/base.rb, line 8 def initialize(params:, path:, http:) @params = params @params[:domain] ||= config.domain if config.domain @params[:key] ||= config.api_key @params[:secret] ||= config.api_secret @params[:format] ||= 'json' @path = path @http = http end
Public Instance Methods
Source
# File lib/addressfinder/v1/base.rb, line 19 def perform build_request execute_request build_result self end
Private Instance Methods
Source
# File lib/addressfinder/v1/base.rb, line 33 def build_request @request_uri = "#{path}?#{encoded_params}" end
Source
# File lib/addressfinder/v1/base.rb, line 48 def build_result case response_status when '200' self.result = Result.new(response_hash) else raise AddressFinder::RequestRejectedError.new(response_status, response_body) end end
Source
# File lib/addressfinder/v1/base.rb, line 61 def config @_config ||= AddressFinder.configuration end
Source
# File lib/addressfinder/v1/base.rb, line 37 def encoded_params Util.encode_and_join_params(params) end
Source
# File lib/addressfinder/v1/base.rb, line 41 def execute_request response = http.request(request_uri) self.response_body = response.body self.response_status = response.code end
Source
# File lib/addressfinder/v1/base.rb, line 57 def response_hash @_response_hash ||= MultiJson.load(response_body) end