Class: ActiveHook::App::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/activehook/app/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



4
5
6
# File 'lib/activehook/app/middleware.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/activehook/app/middleware.rb', line 8

def call(env)
  @env = env
  @req = Rack::Request.new(env)

  if validation_request? then response(Validation)
  #Not enabling webhook creation yet.
  #elsif creation_request? then response(Creation)
  else @app.call(@env)
  end
end

#creation_request?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/activehook/app/middleware.rb', line 23

def creation_request?
  @req.path == ActiveHook.config.creation_path && @req.post?
end

#response(klass) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/activehook/app/middleware.rb', line 27

def response(klass)
  response =
    if klass.new(@req).start then { code: 200, status: true }
    else { code: 400, status: false }
    end
  [response[:code], { "Content-Type" => "application/json" }, [{ status: response[:status] }.to_json]]
end

#validation_request?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/activehook/app/middleware.rb', line 19

def validation_request?
  @req.path == ActiveHook.config.validation_path && @req.get?
end