Class: GoogleAssistant

Inherits:
Envoy
  • Object
show all
Defined in:
lib/botanalytics/google.rb

Overview

GoogleAsistant Logger

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ GoogleAssistant

Returns a new instance of GoogleAssistant.

Parameters:

  • params (defaults to: {})

    Hash

Raises:

  • ArgumentError When token is nil



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/botanalytics/google.rb', line 7

def initialize(params = {})
  super(params)
  @path = 'messages/google-assistant/'
  @async = params.fetch(:async, false)
  informs("Logging enabled for #{self.class.name}...")
  if @async
      require 'concurrent'
      @executor_service = Concurrent::ThreadPoolExecutor.new(
        min_threads: 1,
        max_threads: Concurrent.processor_count,
        max_queue: 100,
        fallback_policy: :caller_runs
      )
      informs("Mode: Async...")
  end
end

Instance Method Details

#log(req, res) ⇒ Object

Parameters:

  • req

    Hash

  • res

    Hash



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/botanalytics/google.rb', line 26

def log(req, res)
  validation = validate(req, res)
  if validation[:ok]
    payload = {:request => req, :response => res}
    informs("Logging messages...")
    informs(payload)
    if @async
      @executor_service.post do
          submits(payload, @path)
      end
    else
      submits(payload, @path)
    end
  else
    fails(validation[:err], validation[:reason], {:request => req, :response => res})
  end
end