Sha256: 55f3a9916add1ebc5976c2feae5bd5258791c58ed3638ddad0ce2c9763ea1246

Contents?: true

Size: 746 Bytes

Versions: 31

Compression:

Stored size: 746 Bytes

Contents

require 'faraday'

module Qa::Authorities
  ##
  # Mix-in to retreive and parse JSON content from the web with Faraday.
  module WebServiceBase
    ##
    # @!attribute [rw] raw_response
    attr_accessor :raw_response

    ##
    # Make a web request & retieve a JSON response for a given URL.
    #
    # @param url [String]
    # @return [Hash] a parsed JSON response
    def json(url)
      Rails.logger.info "Retrieving json for url: #{url}"
      r = response(url).body
      JSON.parse(r)
    end

    ##
    # Make a web request and retrieve the response.
    #
    # @param url [String]
    # @return [Faraday::Response]
    def response(url)
      Faraday.get(url) { |req| req.headers['Accept'] = 'application/json' }
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
qa-5.14.0 lib/qa/authorities/web_service_base.rb
qa-5.13.0 lib/qa/authorities/web_service_base.rb
qa-5.12.0 lib/qa/authorities/web_service_base.rb
qa-5.11.0 lib/qa/authorities/web_service_base.rb
qa-5.10.0 lib/qa/authorities/web_service_base.rb
qa-5.9.0 lib/qa/authorities/web_service_base.rb
qa-5.8.1 lib/qa/authorities/web_service_base.rb
qa-5.8.0 lib/qa/authorities/web_service_base.rb
qa-5.7.0 lib/qa/authorities/web_service_base.rb
qa-5.6.0 lib/qa/authorities/web_service_base.rb
qa-5.5.2 lib/qa/authorities/web_service_base.rb
qa-4.3.0 lib/qa/authorities/web_service_base.rb
qa-5.5.1 lib/qa/authorities/web_service_base.rb
qa-5.5.0 lib/qa/authorities/web_service_base.rb
qa-5.4.0 lib/qa/authorities/web_service_base.rb
qa-5.3.1 lib/qa/authorities/web_service_base.rb
qa-5.3.0 lib/qa/authorities/web_service_base.rb
qa-5.2.0 lib/qa/authorities/web_service_base.rb
qa-5.1.0 lib/qa/authorities/web_service_base.rb
qa-5.0.0 lib/qa/authorities/web_service_base.rb