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
# File 'lib/qa/authorities/crossref/generic_authority.rb', line 7

def initialize(subauthority)
  @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



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

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

#find(id) ⇒ Object



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

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

#find_url(id) ⇒ Object



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

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

#search(q) ⇒ Object



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

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

#untaint(q) ⇒ Object



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

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