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

#get_json, #response

Methods inherited from Base

#all, #full_record

Instance Method Details

#build_query_url(q) ⇒ Object



16
17
18
19
# File 'lib/qa/authorities/geonames.rb', line 16

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



25
26
27
# File 'lib/qa/authorities/geonames.rb', line 25

def find id
  json(find_url(id))
end

#find_url(id) ⇒ Object



29
30
31
# File 'lib/qa/authorities/geonames.rb', line 29

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



12
13
14
# File 'lib/qa/authorities/geonames.rb', line 12

def json(*args)
  get_json(*args)
end

#search(q) ⇒ Object



7
8
9
# File 'lib/qa/authorities/geonames.rb', line 7

def search q
  parse_authority_response(json(build_query_url(q)))
end

#untaint(q) ⇒ Object



21
22
23
# File 'lib/qa/authorities/geonames.rb', line 21

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