class BearerRails::Webhooks
Constants
- BEARER_INTEGRATION_HANDLER
- BEARER_ORIGIN
- BEARER_SHA
Public Instance Methods
call(env)
click to toggle source
# File lib/bearer-rails/webhooks.rb, line 17 def call(env) req = Rack::Request.new(env) buid = get_bearer_header(req, BEARER_INTEGRATION_HANDLER) origin = get_origin(req) sha = get_sha(req) result = self.class.invoke( buid: buid, origin: origin, sha: sha, body: req.body.string ) return [200, { "Content-Type" => "application/json" }, ["{\"ack\":\"ok\"}"]] if result [422, { "Content-Type" => "application/json" }, [""]] rescue StandardError => e [500, { "Content-Type" => "application/json" }, ["{\"error\":#{e.to_json}}"]] end
Private Instance Methods
get_bearer_header(req, header)
click to toggle source
# File lib/bearer-rails/webhooks.rb, line 39 def get_bearer_header(req, header) rack_header = "HTTP_#{header.tr('-', '_')}" header_value = req.env[rack_header] raise "Missing #{header} header" unless header_value header_value end
get_origin(req)
click to toggle source
# File lib/bearer-rails/webhooks.rb, line 51 def get_origin(req) get_bearer_header(req, BEARER_ORIGIN) end
get_sha(req)
click to toggle source
# File lib/bearer-rails/webhooks.rb, line 47 def get_sha(req) get_bearer_header(req, BEARER_SHA) end