Module: Qa::Authorities::WebServiceBase
- Included in:
- AssignFast::GenericAuthority, Crossref::GenericAuthority, Geonames, Getty::AAT, Getty::TGN, Getty::Ulan, LinkedData::GenericAuthority, 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
-
#get_json(url) ⇒ Object
deprecated
Deprecated.
Use #json instead
-
#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
#get_json(url) ⇒ Object
Deprecated.
Use #json instead
23 24 25 26 27 |
# File 'lib/qa/authorities/web_service_base.rb', line 23 def get_json(url) warn '[DEPRECATED] #get_json is deprecated; use #json instead.' \ "Called from #{Gem.location_of_caller.join(':')}." json(url) end |
#json(url) ⇒ Hash
Make a web request & retieve a JSON response for a given URL.
16 17 18 19 |
# File 'lib/qa/authorities/web_service_base.rb', line 16 def json(url) r = response(url).body JSON.parse(r) end |
#response(url) ⇒ Faraday::Response
Make a web request and retrieve the response.
34 35 36 |
# File 'lib/qa/authorities/web_service_base.rb', line 34 def response(url) Faraday.get(url) { |req| req.headers['Accept'] = 'application/json' } end |