From c676e70a49f2cb2ad74657af54fcc926bdc785e4 Mon Sep 17 00:00:00 2001 From: Clarissa Borges Date: Sat, 6 Feb 2021 22:51:15 -0300 Subject: [PATCH] Adds a Webhook adapter and includes OpenFn support --- Gemfile.lock | 1 + gems/bess/bess.gemspec | 1 + gems/bess/lib/houdini.rb | 3 +++ gems/bess/lib/houdini/webhook_adapter.rb | 22 +++++++++++++++++++ .../lib/houdini/webhook_adapter/open_fn.rb | 4 ++++ 5 files changed, 31 insertions(+) create mode 100644 gems/bess/lib/houdini/webhook_adapter.rb create mode 100644 gems/bess/lib/houdini/webhook_adapter/open_fn.rb diff --git a/Gemfile.lock b/Gemfile.lock index b1502616..1e7ff0d7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -21,6 +21,7 @@ PATH specs: bess (0.1.0) rails (~> 6.0) + rest-client wisper (~> 2.0) wisper-activejob (~> 1.0.0) diff --git a/gems/bess/bess.gemspec b/gems/bess/bess.gemspec index 23454530..d21b90d2 100644 --- a/gems/bess/bess.gemspec +++ b/gems/bess/bess.gemspec @@ -18,6 +18,7 @@ Gem::Specification.new do |spec| spec.add_dependency "rails", "~> 6.0" spec.add_dependency 'wisper', '~> 2.0' spec.add_dependency 'wisper-activejob', '~> 1.0.0' + spec.add_dependency 'rest-client' spec.add_development_dependency 'rspec', '~> 3.9.0' spec.add_development_dependency 'rspec-rails', '~> 4.0.0' diff --git a/gems/bess/lib/houdini.rb b/gems/bess/lib/houdini.rb index aaf6f88b..65098f71 100644 --- a/gems/bess/lib/houdini.rb +++ b/gems/bess/lib/houdini.rb @@ -12,6 +12,7 @@ module Houdini autoload :Intl autoload :PaymentProvider autoload :EventPublisher + autoload :WebhookAdapter mattr_accessor :intl, :maintenance, :ccs @@ -38,4 +39,6 @@ module Houdini mattr_accessor :core_classes, default: {supporter: 'Supporter', nonprofit: 'Nonprofit'} mattr_accessor :event_publisher, default: Houdini::EventPublisher.new + + mattr_accessor :webhook_adapter end diff --git a/gems/bess/lib/houdini/webhook_adapter.rb b/gems/bess/lib/houdini/webhook_adapter.rb new file mode 100644 index 00000000..1dfbd95b --- /dev/null +++ b/gems/bess/lib/houdini/webhook_adapter.rb @@ -0,0 +1,22 @@ +# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later +# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE +class Houdini::WebhookAdapter + extend ActiveSupport::Autoload + include ActiveModel::AttributeAssignment + + autoload :OpenFn + + attr_accessor :url, :auth_headers + def initialize(attributes={}) + assign_attributes(attributes) if attributes + end + + def post(payload) + RestClient::Request.execute( + method: :post, + url: url, + payload: payload, + headers: auth_headers + ) + end +end diff --git a/gems/bess/lib/houdini/webhook_adapter/open_fn.rb b/gems/bess/lib/houdini/webhook_adapter/open_fn.rb new file mode 100644 index 00000000..d40618e5 --- /dev/null +++ b/gems/bess/lib/houdini/webhook_adapter/open_fn.rb @@ -0,0 +1,4 @@ +# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later +# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE +class Houdini::WebhookAdapter::OpenFn < Houdini::WebhookAdapter +end