Last active
April 12, 2019 00:16
-
-
Save seanupton/1071a13bf3dbccf865f49154cb457271 to your computer and use it in GitHub Desktop.
Geonames snippet for use in ingest?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'faraday' | |
require 'nokogiri' | |
require 'uri' | |
def geonames_place_uri(placename) | |
query = URI::encode(placename) | |
geo_qs = "q=#{query}&username=#{Qa::Authorities::Geonames.username}" | |
url = "http://api.geonames.org/search?#{geo_qs}" | |
resp = Faraday.get url | |
doc = Nokogiri.XML(resp.body) | |
geonames_id = doc.xpath('//geonames/geoname[1]/geonameId').first.text | |
"http://www.geonames.org/#{geonames_id}/about.rdf" | |
end | |
# Example use: | |
# SET Qa::Authorities::Geonames.username via Hyrax config setter: | |
Hyrax.config.geonames_username = 'demo' # REPLACE WITH REAL USERNAME | |
place_uri = geonames_place_uri("Park City, Utah") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment