Class: GCoder::Geocoder::Request
- Inherits:
-
Object
- Object
- GCoder::Geocoder::Request
- Defined in:
- lib/gcoder/geocoder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(query, opts = {}) ⇒ Request
constructor
A new instance of Request.
- #params ⇒ Object
- #path ⇒ Object
- #uri ⇒ Object
Constructor Details
Class Method Details
.stub(uri, body) ⇒ Object
17 18 19 |
# File 'lib/gcoder/geocoder.rb', line 17 def self.stub(uri, body) stubs[uri] = body end |
.stubs ⇒ Object
13 14 15 |
# File 'lib/gcoder/geocoder.rb', line 13 def self.stubs @stubs ||= {} end |
.to_query(params) ⇒ Object
9 10 11 |
# File 'lib/gcoder/geocoder.rb', line 9 def self.to_query(params) URI.escape(params.map { |key, val| "#{key}=#{val}" }.join('&')) end |
Instance Method Details
#get ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/gcoder/geocoder.rb', line 45 def get Timeout.timeout(@config[:timeout]) do Response.new(uri, http_get) end rescue Timeout::Error raise TimeoutError, "Query timeout after #{@config[:timeout]} second(s)" end |
#params ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gcoder/geocoder.rb', line 26 def params p = { :sensor => 'false' } p[:address] = address if @address p[:latlng] = latlng if @latlng p[:language] = @config[:language] if @config[:language] p[:region] = @config[:region] if @config[:region] p[:bounds] = bounds if @config[:bounds] p[:client] = @config[:client] if @config[:client] p end |
#path ⇒ Object
37 38 39 |
# File 'lib/gcoder/geocoder.rb', line 37 def path "#{PATH}?#{self.class.to_query(params)}#{"&signature=#{sign_key(@config[:key])}" if @config[:key]}" end |
#uri ⇒ Object
41 42 43 |
# File 'lib/gcoder/geocoder.rb', line 41 def uri "http://#{HOST}#{path}" end |