Class: RestClient::Jogger::Action

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/rest_client/jogger/action.rb

Direct Known Subclasses

Request, Response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Action

Returns a new instance of Action.



7
8
9
10
# File 'lib/rest_client/jogger/action.rb', line 7

def initialize(args = {})
  self.logger = args.fetch :logger
  super
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/rest_client/jogger/action.rb', line 5

def logger
  @logger
end

#notifierObject

Returns the value of attribute notifier.



5
6
7
# File 'lib/rest_client/jogger/action.rb', line 5

def notifier
  @notifier
end

Instance Method Details

#call(name, start, finish, id, payload) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rest_client/jogger/action.rb', line 16

def call(name, start, finish, id, payload)
  start_time = payload.fetch(:start_time)
  render_params = {
    args: payload,
    payload: filter(payload),
    verify_ssl: payload[:verify_ssl],
    read_timeout: payload.fetch(:timeout) { payload[:read_timeout] },
    open_timeout: payload.fetch(:timeout) { payload[:open_timeout] },
    event_id: id,
    timestamp: start,
    time_elapsed: (finish - start_time).round(10),
    ip_address: ip_address
  }
  json = template.render nil, render_params
  name =~ /error/ ? logger.error(json) : logger.debug(json)
rescue StandardError => e
  notifier.error e, payload: payload
end

#templateObject

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/rest_client/jogger/action.rb', line 35

def template
  raise NotImplementedError, 'define a #template method in a subclass'
end