class Routemaster::Receiver
Public Class Methods
new(app, options = {})
click to toggle source
# File routemaster/receiver.rb, line 10 def initialize(app, options = {}) warn 'Routemaster::Receiver is deprecated, use Routemaster::Drain::Basic instead' warn "(at #{caller(2,1).first})" @app = app @path = options[:path] @uuid = options[:uuid] @handler = options[:handler] if options[:handler] end
Public Instance Methods
call(env)
click to toggle source
# File routemaster/receiver.rb, line 20 def call(env) catch :forward do throw :forward unless _intercept_endpoint?(env) return [401, {}, []] unless _has_auth?(env) return [403, {}, []] unless _valid_auth?(env) payload = _extract_payload(env) return [400, {}, []] unless payload @handler.on_events(payload) if @handler publish(:events_received, payload) return [204, {}, []] end @app.call(env) end
Private Instance Methods
_extract_payload(env)
click to toggle source
# File routemaster/receiver.rb, line 51 def _extract_payload(env) return unless env['CONTENT_TYPE'] == 'application/json' JSON.parse(env['rack.input'].read) end
_has_auth?(env)
click to toggle source
# File routemaster/receiver.rb, line 41 def _has_auth?(env) env.has_key?('HTTP_AUTHORIZATION') end
_intercept_endpoint?(env)
click to toggle source
# File routemaster/receiver.rb, line 37 def _intercept_endpoint?(env) env['PATH_INFO'] == @path && env['REQUEST_METHOD'] == 'POST' end
_valid_auth?(env)
click to toggle source
# File routemaster/receiver.rb, line 45 def _valid_auth?(env) Base64. decode64(env['HTTP_AUTHORIZATION'].gsub(/^Basic /, '')). split(':').first == @uuid end