Module: Qa::Authorities::WebServiceBase
- Included in:
- AssignFast::GenericAuthority, Crossref::GenericAuthority, Discogs::GenericAuthority, Geonames, Getty::AAT, Getty::AAT2, Getty::TGN, Getty::Ulan, Loc::GenericAuthority, Oclcts::GenericOclcAuthority
- Defined in:
- lib/qa/authorities/web_service_base.rb
Overview
Mix-in to retreive and parse JSON content from the web with Faraday.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#json(url) ⇒ Hash
Make a web request & retieve a JSON response for a given URL.
-
#response(url) ⇒ Faraday::Response
Make a web request and retrieve the response.
Instance Attribute Details
#raw_response ⇒ Object
9 10 11 |
# File 'lib/qa/authorities/web_service_base.rb', line 9 def raw_response @raw_response end |
Instance Method Details
#json(url) ⇒ Hash
Make a web request & retieve a JSON response for a given URL.
16 17 18 19 20 |
# File 'lib/qa/authorities/web_service_base.rb', line 16 def json(url) Rails.logger.info "Retrieving json for url: #{url}" r = response(url).body JSON.parse(r) end |
#response(url) ⇒ Faraday::Response
Make a web request and retrieve the response.
27 28 29 |
# File 'lib/qa/authorities/web_service_base.rb', line 27 def response(url) Faraday.get(url) { |req| req.headers['Accept'] = 'application/json' } end |