Class: Rack::GithubWebhooks

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/github_webhooks.rb,
lib/rack/github_webhooks/version.rb

Defined Under Namespace

Classes: Signature

Constant Summary collapse

VERSION =
'0.5.0'

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = {}) ⇒ GithubWebhooks

Returns a new instance of GithubWebhooks.



23
24
25
26
# File 'lib/rack/github_webhooks.rb', line 23

def initialize(app, opts = {})
  @app = app
  @secret = opts[:secret]
end

Instance Method Details

#call(env) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rack/github_webhooks.rb', line 28

def call(env)
  rewind_body(env)
  signature = Signature.new(
    @secret,
    env['HTTP_X_HUB_SIGNATURE_256'],
    env['rack.input'].read
  )
  return [400, {}, ["Signatures didn't match!"]] unless signature.valid?

  rewind_body(env)
  @app.call(env)
end