Class: Qa::Authorities::Geonames
- Includes:
- WebServiceBase
- Defined in:
- lib/qa/authorities/geonames.rb
Instance Attribute Summary
Attributes included from WebServiceBase
Instance Method Summary collapse
- #build_query_url(q) ⇒ Object
- #find(id) ⇒ Object
- #find_url(id) ⇒ Object
- #search(q) ⇒ Object
- #untaint(q) ⇒ Object
Methods included from WebServiceBase
Methods inherited from Base
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 (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 |