lib/webhook_handler.rb in webhook_handler-0.3.1 vs lib/webhook_handler.rb in webhook_handler-0.4.0
- old
+ new
@@ -1,25 +1,40 @@
require 'webhook_handler/version'
require 'sidekiq'
-require 'sinatra'
+require 'rack'
module WebhookHandler
+ attr_reader :request
+ attr_reader :response
+
def self.included(klass)
- klass.extend self
+ klass.extend ClassMethods
klass.send(:include, Sidekiq::Worker)
- klass.extend Sinatra::Delegator
- klass.instance_eval do
- get '/' do
- 'Send a POST request to this URL to trigger the webhook'
- end
+ end
- post '/' do
- klass.perform_async
- 'ok'
+ module ClassMethods
+ def call(env)
+ new.call(env)
+ end
+ end
+
+ def call(env)
+ @request = Rack::Request.new(env)
+ @response = Rack::Response.new
+
+ if request.get?
+ response.write('Send a POST request to this URL to trigger the webhook')
+ elsif request.post?
+ if respond_to?(:handle_webhook)
+ send(:handle_webhook)
+ else
+ _handle_webhook
end
end
+
+ response.finish
end
- def call(*args)
- Sinatra::Application.call(*args)
+ def _handle_webhook
+ response.write(self.class.perform_async)
end
end