Class: Qa::Authorities::Crossref::GenericAuthority

Inherits:
Base
  • Object
show all
Includes:
WebServiceBase
Defined in:
lib/qa/authorities/crossref/generic_authority.rb

Instance Attribute Summary collapse

Attributes included from WebServiceBase

#raw_response

Instance Method Summary collapse

Methods included from WebServiceBase

#json, #response

Methods inherited from Base

#all

Constructor Details

#initialize(subauthority) ⇒ GenericAuthority

Returns a new instance of GenericAuthority.



7
8
9
10
# File 'lib/qa/authorities/crossref/generic_authority.rb', line 7

def initialize(subauthority)
  super()
  @subauthority = subauthority
end

Instance Attribute Details

#subauthorityObject (readonly)

Returns the value of attribute subauthority.



5
6
7
# File 'lib/qa/authorities/crossref/generic_authority.rb', line 5

def subauthority
  @subauthority
end

Instance Method Details

#build_query_url(q) ⇒ Object



26
27
28
29
# File 'lib/qa/authorities/crossref/generic_authority.rb', line 26

def build_query_url(q)
  query = ERB::Util.url_encode(untaint(q))
  "http://api.crossref.org/#{subauthority}?query=#{query}"
end

#find(id) ⇒ Object



35
36
37
# File 'lib/qa/authorities/crossref/generic_authority.rb', line 35

def find(id)
  json(find_url(id))
end

#find_url(id) ⇒ Object



39
40
41
# File 'lib/qa/authorities/crossref/generic_authority.rb', line 39

def find_url(id)
  "http://api.crossref.org/#{subauthority}/#{id}"
end

#search(q) ⇒ Object



22
23
24
# File 'lib/qa/authorities/crossref/generic_authority.rb', line 22

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

#untaint(q) ⇒ Object



31
32
33
# File 'lib/qa/authorities/crossref/generic_authority.rb', line 31

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