Class: PostalCoder::GeocodingAPI::Query
- Inherits:
-
Object
- Object
- PostalCoder::GeocodingAPI::Query
- Defined in:
- lib/postalcoder/geocoding_api.rb
Instance Attribute Summary collapse
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(query, options = {}) ⇒ Query
constructor
A new instance of Query.
- #params ⇒ Object
- #to_hash ⇒ Object
- #to_params ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(query, options = {}) ⇒ Query
Returns a new instance of Query.
21 22 23 24 25 26 27 28 |
# File 'lib/postalcoder/geocoding_api.rb', line 21 def initialize(query, = {}) unless query.is_a?(String) raise ArgumentError, "query must be a String, not: #{query.class}" end @config = Config.merge() @query = query validate_state! end |
Instance Attribute Details
#query ⇒ Object (readonly)
Returns the value of attribute query.
15 16 17 |
# File 'lib/postalcoder/geocoding_api.rb', line 15 def query @query end |
Class Method Details
.get(query, options = {}) ⇒ Object
17 18 19 |
# File 'lib/postalcoder/geocoding_api.rb', line 17 def self.get(query, = {}) new(query, ).to_hash end |
Instance Method Details
#params ⇒ Object
35 36 37 |
# File 'lib/postalcoder/geocoding_api.rb', line 35 def params BASE_PARAMS.merge(:key => @config[:gmaps_api_key], :q => query) end |
#to_hash ⇒ Object
30 31 32 33 |
# File 'lib/postalcoder/geocoding_api.rb', line 30 def to_hash return tidy_response if @response parse_json_response(http_get) end |
#to_params ⇒ Object
39 40 41 42 43 |
# File 'lib/postalcoder/geocoding_api.rb', line 39 def to_params # No need to escape the keys and values because (so far) they do not # contain escapable characters. -- CKN params.inject([]) { |a, (k, v)| a << "#{k}=#{v}" }.join('&') end |
#uri ⇒ Object
45 46 47 |
# File 'lib/postalcoder/geocoding_api.rb', line 45 def uri [BASE_URI, '?', to_params].join end |