class FaradayMiddleware::Auth
Request middleware that encodes the body as JSON.
Processes only requests with matching Content-type or those without a type. If a request doesn't have a type but has a body, it sets the Content-type to JSON MIME-type.
Doesn't try to encode bodies that already are in string form.
Constants
- AUTH_HEADER
Public Class Methods
new(app, token = nil, options = {})
click to toggle source
Calls superclass method
# File lib/appbaseio/auth_middleware.rb, line 12 def initialize(app, token = nil, options = {}) super(app) options, token = token, nil if token.is_a? Hash @token = token && token.to_s @auth_header = options.fetch(:auth_header, AUTH_HEADER).to_s raise ArgumentError, ":auth_header can't be blank" if @auth_header.empty? end
Public Instance Methods
call(env)
click to toggle source
# File lib/appbaseio/auth_middleware.rb, line 20 def call(env) env[:request_headers][@auth_header] ||= @token @app.call env end