class Qa::Authorities::Geonames

Public Instance Methods

build_query_url(q) click to toggle source
# File lib/qa/authorities/geonames.rb, line 45
def build_query_url(q)
  query = ERB::Util.url_encode(untaint(q))
  File.join(query_url_host, "searchJSON?q=#{query}&username=#{username}&maxRows=10")
end
find(id) click to toggle source
# File lib/qa/authorities/geonames.rb, line 54
def find(id)
  json(find_url(id))
end
find_url(id) click to toggle source
# File lib/qa/authorities/geonames.rb, line 58
def find_url(id)
  File.join(find_url_host, "getJSON?geonameId=#{id}&username=#{username}")
end
untaint(q) click to toggle source
# File lib/qa/authorities/geonames.rb, line 50
def untaint(q)
  q.gsub(/[^\w\s-]/, '')
end

Private Instance Methods

parse_authority_response(response) click to toggle source

Reformats the data received from the service

# File lib/qa/authorities/geonames.rb, line 65
def parse_authority_response(response)
  response['geonames'].map do |result|
    # NOTE: the trailing slash is meaningful.
    { 'id' => "https://sws.geonames.org/#{result['geonameId']}/",
      'label' => label.call(result) }
  end
end