Module: VORuby::Simple::HTTPGetQuery
- Included in:
- ConeSearch, ImageAccess, SpectralAccess
- Defined in:
- lib/voruby/simple/sap.rb
Overview
Mixin a generic GET-type HTTP query. Requires that the main object has a query_uri() method defined that returns a valid URI as a string.
Instance Method Summary collapse
-
#fetch ⇒ Object
Using an HTTP get, fetch the response that corresponds to the query parameters.
-
#query_uri ⇒ Object
Convert to a form suitable for use in a URL.
Instance Method Details
#fetch ⇒ Object
Using an HTTP get, fetch the response that corresponds to the query parameters.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/voruby/simple/sap.rb', line 91 def fetch uri = URI.parse(query_uri()) http = Net::HTTP.new(uri.host, uri.port) http.read_timeout = query_timeout() uri_params = required_parameters() # Other parameters parameters().each do |param, value| uri_params.push(URI.escape("#{param.to_s().upcase()}=#{value}")) end res = http.start {|http| http.get(uri.path + '?' + uri_params.join('&')) } self.response = res.body end |
#query_uri ⇒ Object
Convert to a form suitable for use in a URL. The required_parameters and parameters methods must exist.
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/voruby/simple/sap.rb', line 111 def query_uri uri_params = required_parameters() # Other parameters parameters().each do |param, value| uri_params.push(URI.escape("#{param.to_s().upcase()}=#{value}")) end "#{uri()}?" + uri_params.join('&') end |