Class: Airports::GoogleMapApi
- Inherits:
-
Object
- Object
- Airports::GoogleMapApi
- Defined in:
- lib/movlog/googlemap_api.rb
Overview
Service to transform location to geocode
Constant Summary collapse
- GOOGLEMAP_URL =
'https://maps.googleapis.com'
- SEARCH_URL =
[GOOGLEMAP_URL, 'maps/api/geocode/json'].join('/')
Class Method Summary collapse
Class Method Details
.config ⇒ Object
15 16 17 18 19 20 |
# File 'lib/movlog/googlemap_api.rb', line 15 def self.config return @config if @config @config = { key: ENV['GOOGLEMAP_KEY'] } end |
.config=(credentials) ⇒ Object
10 11 12 13 |
# File 'lib/movlog/googlemap_api.rb', line 10 def self.config=(credentials) @config = {} unless @config @config.update(credentials) end |
.geocode(location) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/movlog/googlemap_api.rb', line 22 def self.geocode(location) search_response = HTTP.get( SEARCH_URL, params: { address: location, key: config[:key] } ) JSON.parse(search_response.to_s)['results'].first end |