Class: GoogleMaps::Services::Geolocation
- Inherits:
-
Object
- Object
- GoogleMaps::Services::Geolocation
- Includes:
- Exceptions
- Defined in:
- lib/googlemaps/services/geolocation.rb
Overview
Performs requests to the Google Geolocation API.
Instance Attribute Summary collapse
-
#client ⇒ Symbol
The HTTP client.
Instance Method Summary collapse
-
#initialize(client) ⇒ Geolocation
constructor
A new instance of Geolocation.
-
#query(home_mobile_country_code: nil, home_mobile_network_code: nil, radio_type: nil, carrier: nil, consider_ip: true, cell_towers: nil, wifi_access_points: nil) ⇒ HashMap
The Google Maps Geolocation API returns a location and accuracy radius based on information about cell towers and given WiFi nodes.
Constructor Details
#initialize(client) ⇒ Geolocation
Returns a new instance of Geolocation.
24 25 26 |
# File 'lib/googlemaps/services/geolocation.rb', line 24 def initialize(client) self.client = client end |
Instance Attribute Details
#client ⇒ Symbol
Returns The HTTP client.
22 23 24 |
# File 'lib/googlemaps/services/geolocation.rb', line 22 def client @client end |
Instance Method Details
#query(home_mobile_country_code: nil, home_mobile_network_code: nil, radio_type: nil, carrier: nil, consider_ip: true, cell_towers: nil, wifi_access_points: nil) ⇒ HashMap
The Google Maps Geolocation API returns a location and accuracy radius based on information about cell towers and given WiFi nodes.
For more information, see: developers.google.com/maps/documentation/geolocation/intro
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/googlemaps/services/geolocation.rb', line 47 def query(home_mobile_country_code: nil, home_mobile_network_code: nil, radio_type: nil, carrier: nil, consider_ip: true, cell_towers: nil, wifi_access_points: nil) params = {} if home_mobile_country_code params["homeMobileCountryCode"] = home_mobile_country_code end if home_mobile_network_code params["homeMobileNetworkCode"] = home_mobile_network_code end if radio_type raise StandardError, "invalid radio type value." unless Constants::SUPPORTED_RADIO_TYPES.include? radio_type params["radioType"] = radio_type end if carrier params["carrier"] = carrier end params["considerIp"] = consider_ip unless consider_ip if cell_towers params["cellTowers"] = cell_towers end if wifi_access_points params["wifiAccessPoints"] = wifi_access_points end self.client.request(url: '/geolocation/v1/geolocate', params: {}, base_url: Constants::GOOGLEAPIS_BASE_URL, extract_body: lambda(&method(:_geolocation_extract)), post_json: params) end |