Class: Mailjet::Rack::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/mailjet/rack/endpoint.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, path, &block) ⇒ Endpoint

Returns a new instance of Endpoint.



7
8
9
10
11
# File 'lib/mailjet/rack/endpoint.rb', line 7

def initialize(app, path, &block)
  @app = app
  @path = path
  @block = block
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/mailjet/rack/endpoint.rb', line 13

def call(env)
  if env['PATH_INFO'] == @path && (content = env['rack.input'].read)
    @block.call(Yajl::Parser.parse(content))
    [200, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, []]
  else
    @app.call(env)
  end
end