class Airports::GeonamesApi

Service for transformation of location and find near airport

Constants

FIND_NEARBY_URL
GEONAMES_URL
SEARCH_URL

Public Class Methods

config() click to toggle source
# File lib/movlog/geonames_api.rb, line 16
def self.config
  return @config if @config
  @config = {
    username: ENV['GEONAMES_USERNAME']
  }
end
config=(credentials) click to toggle source
# File lib/movlog/geonames_api.rb, line 11
def self.config=(credentials)
  @config = {} unless @config
  @config.update(credentials)
end
geo_info(location) click to toggle source
# File lib/movlog/geonames_api.rb, line 23
def self.geo_info(location)
  search_response = HTTP.get(
    SEARCH_URL,
    params: {
      username: config[:username],
      q: location,
      fuzzy: 0.5,
      maxRows: 1
    }
  )
  JSON.parse(search_response.to_s)['geonames'].first
end
near_airports(lat:, lng:) click to toggle source
# File lib/movlog/geonames_api.rb, line 36
def self.near_airports(lat:, lng:)
  findnearby_response = HTTP.get(
    FIND_NEARBY_URL,
    params: {
      username: config[:username],
      fcode: 'AIRP',
      lat: lat, lng: lng,
      radius: 200, maxRows: 50
    }
  )
  JSON.parse(findnearby_response.to_s)['geonames']
end