Class: MailToHipChat::RackApp

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_to_hip_chat/rack_app.rb,
lib/mail_to_hip_chat/rack_app/builder.rb

Defined Under Namespace

Classes: Builder

Constant Summary collapse

SIGNATURE_PARAM_NAME =
"signature"

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) {|_self| ... } ⇒ RackApp

Returns a new instance of RackApp.

Yields:

  • (_self)

Yield Parameters:



11
12
13
14
15
16
# File 'lib/mail_to_hip_chat/rack_app.rb', line 11

def initialize(opts = {})
  @secret      = opts[:secret]
  @chute_chain = opts[:chute_chain] || ChuteChain.new

  yield(self) if block_given?
end

Instance Method Details

#call(rack_env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mail_to_hip_chat/rack_app.rb', line 18

def call(rack_env)
  request = Rack::Request.new(rack_env)
  return [400, {}, ['Bad Request.']] unless valid_request?(request)

  if @chute_chain.accept(request.params)
    [200, {}, ['OK']]
  else
    [404, {}, ['Not Found.']]
  end

rescue Exception => error
  error.extend(InternalError)
  raise error
end

#use_chute(chute) ⇒ Object



33
34
35
# File 'lib/mail_to_hip_chat/rack_app.rb', line 33

def use_chute(chute)
  @chute_chain.push(chute)
end