Module: Query
- Includes:
- ConfigParams
- Defined in:
- lib/api_object/query.rb
Constant Summary
Constants included from ConfigParams
ConfigParams::FALLBACK_TIMEOUT, ConfigParams::IPV4_REGEXP, ConfigParams::TIMEOUT
Instance Method Summary collapse
- #get_url(url, action = nil, mode = nil, url_options = {}) ⇒ Object
- #query_api(url, action = nil, mode = nil, url_options = {}, options = {}) ⇒ Object
Methods included from ConfigParams
#fallback_timeout, #fallback_timeout=, #timeout, #timeout=
Instance Method Details
#get_url(url, action = nil, mode = nil, url_options = {}) ⇒ Object
19 20 21 22 |
# File 'lib/api_object/query.rb', line 19 def get_url url, action = nil, mode = nil, = {} cmd_url = url.chomp("/") + "/" + (action.nil? ? '':"#{action}?") # url + action cmd_url + (mode.nil? ? '' : "#{mode}&") + .to_a.map{|opt| opt[0].to_s + "=" + opt[1]}.join("&") # add parameters end |
#query_api(url, action = nil, mode = nil, url_options = {}, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/api_object/query.rb', line 9 def query_api url, action = nil, mode = nil, = {}, = {} result = nil request_url = get_url(url, action, mode, ) Timeout.timeout(self.fallback_timeout) do result_raw = RestClient::Request.execute(:method => :get, :url => request_url, :timeout => self.timeout) result = result_raw.start_with?('<?xml') ? Nori.parse(result_raw) : JSON.parse(result_raw) end {:result => result, :success => !result.nil?, :url => request_url} end |