Class: Gillbus::FaradayResponseFileLogger

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/gillbus/drivers/faraday_response_file_logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, dir = '.') ⇒ FaradayResponseFileLogger

Returns a new instance of FaradayResponseFileLogger.



3
4
5
6
# File 'lib/gillbus/drivers/faraday_response_file_logger.rb', line 3

def initialize(app, dir = '.')
  @dir = dir
  super(app)
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/gillbus/drivers/faraday_response_file_logger.rb', line 8

def call(env)
  path = env.url.path
  @app.call(env).on_complete do |_environment|
    sanitized_path = path.gsub(/[^A-Za-z0-9_-]+/, '_').gsub(/^_|_$/, '')
    sanitized_path = '_' if sanitized_path == ''
    File.write(@dir + '/' + sanitized_path, env.body) if env.body != ''
  end
end