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
-
#json(*args) ⇒ Object
get_json is not ideomatic, so we’ll make an alias.
- #search(q) ⇒ Object
- #untaint(q) ⇒ Object
Methods included from WebServiceBase
Methods inherited from Base
Instance Method Details
#build_query_url(q) ⇒ Object
24 25 26 27 |
# File 'lib/qa/authorities/geonames.rb', line 24 def build_query_url q query = URI.escape(untaint(q)) "http://api.geonames.org/searchJSON?q=#{query}&username=#{username}&maxRows=10" end |
#find(id) ⇒ Object
33 34 35 |
# File 'lib/qa/authorities/geonames.rb', line 33 def find id json(find_url(id)) end |
#find_url(id) ⇒ Object
37 38 39 |
# File 'lib/qa/authorities/geonames.rb', line 37 def find_url id "http://www.geonames.org/getJSON?geonameId=#{id}&username=#{username}" end |
#json(*args) ⇒ Object
get_json is not ideomatic, so we’ll make an alias
20 21 22 |
# File 'lib/qa/authorities/geonames.rb', line 20 def json(*args) get_json(*args) 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
29 30 31 |
# File 'lib/qa/authorities/geonames.rb', line 29 def untaint(q) q.gsub(/[^\w\s-]/, '') end |