Class: Ubersicht::Ingestion::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ubersicht/ingestion/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
# File 'lib/ubersicht/ingestion/client.rb', line 17

def initialize(options = {}, &block)
  raise ArgumentError, 'Token cannot be blank' if empty?(token = options[:token])
  raise ArgumentError, 'Url cannot be blank' if empty?(url = options[:url])

  @debug = options[:debug] || false
  @conn = setup_conn(url, token, &block)
end

Class Method Details

.default(*args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ubersicht/ingestion/client.rb', line 4

def self.default(*args)
  require 'logger'

  new(*args) do |faraday|
    faraday.request :url_encoded
    # faraday.response :raise_error
    faraday.response :logger, ::Logger.new($stdout),
                     headers: { request: false, response: false },
                     bodies: { request: true, response: true }
    faraday.adapter  Faraday.default_adapter # make requests with Net::HTTP
  end
end

Instance Method Details

#ingest(source, type, payload = {}) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ubersicht/ingestion/client.rb', line 25

def ingest(source, type, payload = {})
  raise ArgumentError, 'Source cannot be blank' if empty?(source)
  raise ArgumentError, 'Transaction type cannot be blank' if empty?(type)

  body = {
    event: {
      source: source,
      type: type,
      payload: payload
    }
  }
  process { handle_response(@conn.post('api/v1/events', body.to_json)) }
end