Class: Qa::Authorities::Geonames

Inherits:
Base
  • Object
show all
Includes:
WebServiceBase
Defined in:
lib/qa/authorities/geonames.rb

Instance Attribute Summary

Attributes included from WebServiceBase

#raw_response

Instance Method Summary collapse

Methods included from WebServiceBase

#json, #response

Methods inherited from Base

#all

Instance Method Details

#build_query_url(q) ⇒ Object



45
46
47
48
# 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) ⇒ Object



54
55
56
# File 'lib/qa/authorities/geonames.rb', line 54

def find(id)
  json(find_url(id))
end

#find_url(id) ⇒ Object



58
59
60
# File 'lib/qa/authorities/geonames.rb', line 58

def find_url(id)
  File.join(find_url_host, "getJSON?geonameId=#{id}&username=#{username}")
end

#search(q) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/qa/authorities/geonames.rb', line 37

def search(q)
  unless username
    Rails.logger.error "Questioning Authority tried to call geonames, but no username was set"
    return []
  end
  parse_authority_response(json(build_query_url(q)))
end

#untaint(q) ⇒ Object



50
51
52
# File 'lib/qa/authorities/geonames.rb', line 50

def untaint(q)
  q.gsub(/[^\w\s-]/, '')
end