module NextcallerClient::Utils

Public Class Methods

parse_error_response(resp) click to toggle source
# File lib/nextcaller_client/utils.rb, line 16
def self.parse_error_response(resp)
  if resp['Content-Type'].include? 'application/json'
    JSON.parse(resp.body)
  else
    resp.body
  end
end
parse_error_response_retry_after(resp) click to toggle source
# File lib/nextcaller_client/utils.rb, line 12
def self.parse_error_response_retry_after(resp)
  resp['Retry-After']
end
prepare_json_data(data) click to toggle source
# File lib/nextcaller_client/utils.rb, line 5
def self.prepare_json_data(data)
  unless data.is_a? Hash
    raise ArgumentError, 'Data should be a hash.'
  end
  data.to_json
end
prepare_url(path, sandbox, url_params={}) click to toggle source

Prepare url from path and params

# File lib/nextcaller_client/utils.rb, line 25
def self.prepare_url(path, sandbox, url_params={})
  url = '%s%s' % [sandbox ? FULL_SANDBOX_URL : FULL_URL, path]
  unless url.end_with?('/')
    url += '/'
  end
  unless url_params.empty?
    url_params_str = url_params.collect { |k, v| "#{CGI::escape(k.to_s)}=#{CGI::escape(v.to_s)}" }.join('&')
    url += "?#{url_params_str}"
  end
  url
end