Class: MapsApi::Google::Requester
- Inherits:
-
AddressGeocoder::Requester
- Object
- AddressGeocoder::Requester
- MapsApi::Google::Requester
- Defined in:
- lib/maps_api/google/requester.rb
Overview
Class for making requests to Google Maps API
Instance Attribute Summary
Attributes inherited from AddressGeocoder::Requester
#address, #api_key, #language, #parser, #result
Instance Method Summary collapse
-
#array_result ⇒ Array<Hash>
Return a compacted, flattened array of different address responses.
-
#certain? ⇒ Boolean
Check if the certainty level of the response.
-
#make_call ⇒ void
Make a call to Google Maps’ Geocoding API.
-
#success? ⇒ Boolean
Determines whether the request to Google Maps’ Geocoding API was a success.
Methods inherited from AddressGeocoder::Requester
#connection_error, #initialize
Constructor Details
This class inherits a constructor from AddressGeocoder::Requester
Instance Method Details
#array_result ⇒ Array<Hash>
Return a compacted, flattened array of different address responses.
51 52 53 |
# File 'lib/maps_api/google/requester.rb', line 51 def array_result [@result['results']].flatten end |
#certain? ⇒ Boolean
certainty is determined in two ways: first, by ensuring that the country was not the only field returned and that it was the correct country; second, that the city, state, and postal code were all present in the response if they were included in the level of call.
Check if the certainty level of the response
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/maps_api/google/requester.rb', line 36 def certain? level = @url_generator.level if @parser.just_country?(@result) || @parser.not_correct_country?(@result) false elsif @parser.city_present?(level) || @parser.state_present?(level) || @parser.pc_present?(level) false else true end end |
#make_call ⇒ void
This method returns an undefined value.
Make a call to Google Maps’ Geocoding API
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/maps_api/google/requester.rb', line 11 def make_call @url_generator = UrlGenerator.new(address: @address.dup, api_key: @api_key, language: @language) @url_generator.levels.each do |level_of_search| @url_generator.level = level_of_search call break if success? end end |
#success? ⇒ Boolean
Determines whether the request to Google Maps’ Geocoding API was a success
25 26 27 28 29 |
# File 'lib/maps_api/google/requester.rb', line 25 def success? return false unless @result['status'] == 'OK' return false unless @result['results'][0]['address_components'].length > 1 true end |