lib/flexmls_api/request.rb in flexmls_api-0.3.3 vs lib/flexmls_api/request.rb in flexmls_api-0.3.6

- old
+ new

@@ -1,5 +1,6 @@ +require 'cgi' module FlexmlsApi # HTTP request wrapper. Performs all the api session mumbo jumbo so that the models don't have to. module Request include PaginateResponse @@ -63,10 +64,13 @@ attempts = 0 begin request_opts = { "AuthToken" => @session.auth_token } + unless self.api_user.nil? + request_opts.merge!(:ApiUser => "#{api_user}") + end request_opts.merge!(options) post_data = body.nil? ? nil : {"D" => body }.to_json sig = sign_token(path, request_opts, post_data) request_path = "/#{version}#{path}?ApiSig=#{sig}#{build_url_parameters(request_opts)}" FlexmlsApi.logger.debug("Request: #{request_path}") @@ -76,11 +80,11 @@ else FlexmlsApi.logger.debug("Data: #{post_data}") response = connection.send(method, request_path, post_data) end request_time = Time.now - start_time - FlexmlsApi.logger.info("[#{request_time}s] Api: #{method.to_s.upcase} #{request_path}") + FlexmlsApi.logger.info("[#{(request_time * 1000).to_i}ms] Api: #{method.to_s.upcase} #{request_path}") rescue PermissionDenied => e if(ResponseCodes::SESSION_TOKEN_EXPIRED == e.code) unless (attempts +=1) > 1 FlexmlsApi.logger.debug("Retrying authentication") authenticate @@ -104,10 +108,11 @@ # :returns: # Stringized form of the parameters as needed for the http request def build_url_parameters(parameters={}) str = "" parameters.map do |key,value| - str << "&#{key}=#{value}" + escaped_value = CGI.escape("#{value}") + str << "&#{key}=#{escaped_value}" end str end end