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

#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.

Parameters:

  • url (String)

Returns:

  • (Hash)

    a parsed JSON response



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.

Parameters:

  • url (String)

Returns:

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