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

24 lines
409 B
Ruby
Raw Normal View History

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