Class: Qa::Authorities::Loc::GenericAuthority
- Includes:
- WebServiceBase
- Defined in:
- lib/qa/authorities/loc/generic_authority.rb
Instance Attribute Summary collapse
-
#subauthority ⇒ Object
readonly
Returns the value of attribute subauthority.
Attributes included from WebServiceBase
Instance Method Summary collapse
- #build_query_url(q) ⇒ Object
- #find(id) ⇒ Object
- #find_url(id) ⇒ Object
-
#initialize(subauthority) ⇒ GenericAuthority
constructor
A new instance of GenericAuthority.
- #response(url) ⇒ Object
- #search(q) ⇒ Object
Methods included from WebServiceBase
Methods inherited from Base
Constructor Details
#initialize(subauthority) ⇒ GenericAuthority
Returns a new instance of GenericAuthority.
4 5 6 |
# File 'lib/qa/authorities/loc/generic_authority.rb', line 4 def initialize() @subauthority = end |
Instance Attribute Details
#subauthority ⇒ Object (readonly)
Returns the value of attribute subauthority.
3 4 5 |
# File 'lib/qa/authorities/loc/generic_authority.rb', line 3 def @subauthority end |
Instance Method Details
#build_query_url(q) ⇒ Object
26 27 28 29 30 |
# File 'lib/qa/authorities/loc/generic_authority.rb', line 26 def build_query_url(q) escaped_query = URI.escape(q) = Loc.() + URI.escape() "http://id.loc.gov/search/?q=#{escaped_query}&q=#{}&format=json" end |
#find(id) ⇒ Object
32 33 34 |
# File 'lib/qa/authorities/loc/generic_authority.rb', line 32 def find(id) json(find_url(id)) end |
#find_url(id) ⇒ Object
36 37 38 |
# File 'lib/qa/authorities/loc/generic_authority.rb', line 36 def find_url(id) "http://id.loc.gov/authorities/#{@subauthority}/#{id}.json" end |
#response(url) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/qa/authorities/loc/generic_authority.rb', line 10 def response(url) uri = URI(url) conn = Faraday.new "#{uri.scheme}://#{uri.host}" conn..params_encoder = Faraday::FlatParamsEncoder conn.get do |req| req.headers['Accept'] = 'application/json' req.url uri.path req.params = Rack::Utils.parse_query(uri.query) end end |
#search(q) ⇒ Object
21 22 23 24 |
# File 'lib/qa/authorities/loc/generic_authority.rb', line 21 def search(q) @raw_response = json(build_query_url(q)) end |