class Rubillow::Request
@private HTTP request manager
Public Class Methods
get(path, options = {})
click to toggle source
Makes the request to the web service.
@param [String] path Web service name. @param [Hash] options Request
options. @return [String, Boolean] XML on success, false if not.
# File lib/rubillow/request.rb, line 14 def self.get(path, options = {}) zwsid = Rubillow.configuration.zwsid unless zwsid.nil? options[:zws_id] ||= zwsid end response = request.get(uri(path, options)) case response.code.to_i when 200 response.body else false end end
hash_to_query_string(hash)
click to toggle source
Turns request options into query string.
@param [Hash] hash Request
options. @return [String] Formatted query string.
# File lib/rubillow/request.rb, line 55 def self.hash_to_query_string(hash) hash = hash.sort_by { |key, value| key.to_s }.delete_if { |key, value| value.to_s.empty? }.collect { |key, value| "#{CGI.escape(key.to_s).gsub(/\_/, '-')}=#{CGI.escape(value.to_s)}" } hash.join("&") end
request()
click to toggle source
gets the request object.
@return [Net::HTTP] HTTP object.
# File lib/rubillow/request.rb, line 34 def self.request http = Net::HTTP.new(Rubillow.configuration.host, Rubillow.configuration.port) http.open_timeout = Rubillow.configuration.http_open_timeout http.read_timeout = Rubillow.configuration.http_read_timeout http end
uri(path, options = {})
click to toggle source
Generate the url for the request.
@param [String] path Web service name. @param [Hash] options Request
options.
# File lib/rubillow/request.rb, line 46 def self.uri(path, options = {}) path = Rubillow.configuration.path + path "/#{path}.htm?#{hash_to_query_string(options)}" end