Class: BWAPI::Response::Performance

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/bwapi/response/performance.rb

Overview

Brandwatch response middleware to monitor performance

Instance Method Summary collapse

Constructor Details

#initialize(app, client) ⇒ Performance

Returns a new instance of Performance.



8
9
10
11
# File 'lib/bwapi/response/performance.rb', line 8

def initialize(app, client)
  super(app)
  @client = client
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
# File 'lib/bwapi/response/performance.rb', line 20

def call(env)
  @recording = ("#{env.method}#{env.url.path}").gsub!('/', '_')
  Allotment.start(@recording)
  super
end

#loggerObject



13
14
15
16
17
18
# File 'lib/bwapi/response/performance.rb', line 13

def logger
  @logger = @client.logger || begin
    require 'logger'
    ::Logger.new(STDOUT)
  end
end

#on_complete(_env) ⇒ Object



26
27
28
# File 'lib/bwapi/response/performance.rb', line 26

def on_complete(_env)
  logger.info "Response time: #{Allotment.stop(@recording)} seconds"
end