Skip to content

Instantly share code, notes, and snippets.

@seanupton
Last active April 12, 2019 00:16
Show Gist options
  • Save seanupton/1071a13bf3dbccf865f49154cb457271 to your computer and use it in GitHub Desktop.
Save seanupton/1071a13bf3dbccf865f49154cb457271 to your computer and use it in GitHub Desktop.
Geonames snippet for use in ingest?
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