demarches-normaliennes/app/lib/api_geo/driver.rb

26 lines
468 B
Ruby
Raw Normal View History

2018-10-15 16:30:27 +02:00
module ApiGeo
class Driver
def self.regions
url = [API_GEO_URL, "regions"].join("/")
call(url)
end
def self.departements
url = [API_GEO_URL, "departements"].join("/")
call(url)
end
def self.pays
File.open('app/lib/api_geo/pays.json').read
end
private
def self.call(api_url)
2018-10-15 18:18:13 +02:00
RestClient.get(api_url, params: { fields: :nom })
2018-10-15 16:30:27 +02:00
rescue RestClient::ServiceUnavailable
nil
end
end
end