Module: Foederati

Defined in:
lib/foederati.rb,
lib/foederati/engine.rb,
lib/foederati/version.rb,
lib/foederati/provider.rb,
lib/foederati/providers.rb,
lib/foederati/provider/request.rb,
lib/foederati/provider/response.rb,
lib/foederati/faraday_middleware.rb

Overview

TODO add logger

Defined Under Namespace

Modules: FaradayMiddleware Classes: Defaults, Engine, Provider, Providers

Constant Summary collapse

VERSION =
'0.1.0'

Class Method Summary collapse

Class Method Details

.api_keysObject



27
28
29
# File 'lib/foederati.rb', line 27

def api_keys
  @api_keys ||= OpenStruct.new
end

.configure(&block) ⇒ Object



22
23
24
25
# File 'lib/foederati.rb', line 22

def configure(&block)
  instance_eval(&block)
  self
end

.connectionFaraday::Connection

‘Faraday` connection for executing HTTP requests

Returns:

  • (Faraday::Connection)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/foederati.rb', line 52

def connection
  @connection ||= begin
    Faraday.new do |conn|
      # TODO are max: 5 and interval: 3 sensible values? should they be
      #   made configurable?
      conn.request :retry, max: 5, interval: 3,
                           exceptions: [Errno::ECONNREFUSED, Errno::ETIMEDOUT, 'Timeout::Error',
                                        Faraday::Error::TimeoutError, EOFError]

      conn.response :unsupported #, content_type: /\bjson$/
      conn.response :json, content_type: /\bjson$/

      conn.adapter :typhoeus
    end
  end
end

.defaultsObject



31
32
33
# File 'lib/foederati.rb', line 31

def defaults
  @defaults ||= Defaults.new
end

.search(*ids, **params) ⇒ Hash

Search registered providers

TODO run multiple searches in parallel

Parameters:

  • ids (Symbol)

    ID(s) of one or more provider to search

  • params (Hash)

    search query parameters

Returns:

  • (Hash)

    combined results of all providers



42
43
44
45
46
# File 'lib/foederati.rb', line 42

def search(*ids, **params)
  ids.map do |id|
    Providers.get(id).search(params)
  end.reduce(&:merge)
end