Class: ApiHammer::FaradayOutputter
- Defined in:
- lib/api_hammer/faraday/outputter.rb
Overview
outputs the response body to the given logger or output device (defaulting to STDOUT)
Direct Known Subclasses
Instance Method Summary collapse
- #call(request_env) ⇒ Object
-
#initialize(app, options = {}) ⇒ FaradayOutputter
constructor
A new instance of FaradayOutputter.
- #puts(str) ⇒ Object
Constructor Details
#initialize(app, options = {}) ⇒ FaradayOutputter
Returns a new instance of FaradayOutputter.
8 9 10 11 12 |
# File 'lib/api_hammer/faraday/outputter.rb', line 8 def initialize(app, ={}) @app=app @options = @outdev = @options[:outdev] || STDOUT end |
Instance Method Details
#call(request_env) ⇒ Object
14 15 16 17 18 |
# File 'lib/api_hammer/faraday/outputter.rb', line 14 def call(request_env) @app.call(request_env).on_complete do |response_env| puts(response_env[:body] || '') end end |
#puts(str) ⇒ Object
20 21 22 23 |
# File 'lib/api_hammer/faraday/outputter.rb', line 20 def puts(str) meth = @options[:logger] ? @options[:logger].method(:info) : (@options[:outdev] || STDOUT).method(:puts) meth.call(str) end |