class Europeana::API::Client

The API client responsible for handling requests and responses

Attributes

queue[R]

Public Class Methods

new() click to toggle source
# File lib/europeana/api/client.rb, line 14
def initialize
  @queue = Queue.new(self)
end

Public Instance Methods

connection() click to toggle source

`Faraday` connection to the API

  • Requests are retried 5 times at an interval of 3 seconds

  • Requests are instrumented

  • JSON responses are parsed

@return [Faraday::Connection]

# File lib/europeana/api/client.rb, line 30
def connection
  @connection ||= begin
    Faraday.new do |conn|
      conn.request :instrumentation
      conn.request :parameter_repetition
      conn.request :authenticated_request
      conn.request :retry, max: 5, interval: 3, exceptions: [Errno::ECONNREFUSED, EOFError]

      conn.options.open_timeout = 5
      conn.options.timeout = 45

      conn.response :json_various, content_type: /\bjson$/
      conn.response :text, content_type: %r{^text(\b[^/]+)?/(plain|html)$}

      conn.adapter :typhoeus
      conn.url_prefix = Europeana::API.url
    end
  end
end
in_parallel?() click to toggle source
# File lib/europeana/api/client.rb, line 18
def in_parallel?
  @queue.present?
end