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



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
  parse_authority_response(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