Module: Qa::Authorities::WebServiceBase

Overview

Mix-in to retreive and parse JSON content from the web with Faraday.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#raw_responseObject



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.

Parameters:

  • url (String)

Returns:

  • (Hash)

    a parsed JSON response



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.

Parameters:

  • url (String)

Returns:

  • (Faraday::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