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
19 20 21 22 |
# File 'lib/qa/authorities/geonames.rb', line 19 def build_query_url(q) query = ERB::Util.url_encode(untaint(q)) "http://api.geonames.org/searchJSON?q=#{query}&username=#{username}&maxRows=10" end |
#find(id) ⇒ Object
28 29 30 |
# File 'lib/qa/authorities/geonames.rb', line 28 def find(id) json(find_url(id)) end |
#find_url(id) ⇒ Object
32 33 34 |
# File 'lib/qa/authorities/geonames.rb', line 32 def find_url(id) "http://www.geonames.org/getJSON?geonameId=#{id}&username=#{username}" end |
#search(q) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/qa/authorities/geonames.rb', line 11 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
24 25 26 |
# File 'lib/qa/authorities/geonames.rb', line 24 def untaint(q) q.gsub(/[^\w\s-]/, '') end |