From fa27ed74e1c722b4bdadff421331998f107e7646 Mon Sep 17 00:00:00 2001
From: FelipeGuzmanSierra
<97761783+FelipeGuzmanSierra@users.noreply.github.com>
Date: Fri, 12 Apr 2024 16:28:14 -0500
Subject: [PATCH 1/5] Rename Dispatcher component to Process
---
lib/bas/{dispatcher => process}/base.rb | 10 +++++-----
.../exceptions/invalid_webhook_token.rb | 2 +-
.../discord/implementation.rb | 16 ++++++++--------
.../discord/types/response.rb | 2 +-
.../slack/exceptions/invalid_webhook_token.rb | 2 +-
.../slack/implementation.rb | 18 +++++++++---------
.../slack/types/response.rb | 2 +-
7 files changed, 26 insertions(+), 26 deletions(-)
rename lib/bas/{dispatcher => process}/base.rb (77%)
rename lib/bas/{dispatcher => process}/discord/exceptions/invalid_webhook_token.rb (95%)
rename lib/bas/{dispatcher => process}/discord/implementation.rb (66%)
rename lib/bas/{dispatcher => process}/discord/types/response.rb (96%)
rename lib/bas/{dispatcher => process}/slack/exceptions/invalid_webhook_token.rb (95%)
rename lib/bas/{dispatcher => process}/slack/implementation.rb (60%)
rename lib/bas/{dispatcher => process}/slack/types/response.rb (96%)
diff --git a/lib/bas/dispatcher/base.rb b/lib/bas/process/base.rb
similarity index 77%
rename from lib/bas/dispatcher/base.rb
rename to lib/bas/process/base.rb
index 647bf76..cd66637 100644
--- a/lib/bas/dispatcher/base.rb
+++ b/lib/bas/process/base.rb
@@ -2,16 +2,16 @@
require_relative "../domain/exceptions/function_not_implemented"
-module Dispatcher
+module Process
##
- # Serves as a foundational structure for implementing specific dispatchers. Acting as an interface,
+ # Serves as a foundational structure for implementing specific process. Acting as an interface,
# this class defines essential attributes and methods, providing a blueprint for creating custom
- # dispatchers tailored to different platforms or services.
+ # process tailored to different platforms or services.
#
class Base
attr_reader :webhook, :name
- # Initializes the dispatcher with essential configuration parameters.
+ # Initializes the processor with essential configuration parameters.
#
def initialize(config)
@webhook = config[:webhook]
@@ -24,7 +24,7 @@ def initialize(config)
#
# returns a Discord::Response
#
- def dispatch(_payload)
+ def execute(_payload)
raise Domain::Exceptions::FunctionNotImplemented
end
end
diff --git a/lib/bas/dispatcher/discord/exceptions/invalid_webhook_token.rb b/lib/bas/process/discord/exceptions/invalid_webhook_token.rb
similarity index 95%
rename from lib/bas/dispatcher/discord/exceptions/invalid_webhook_token.rb
rename to lib/bas/process/discord/exceptions/invalid_webhook_token.rb
index 229cb1a..5062868 100644
--- a/lib/bas/dispatcher/discord/exceptions/invalid_webhook_token.rb
+++ b/lib/bas/process/discord/exceptions/invalid_webhook_token.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-module Dispatcher
+module Process
module Discord
module Exceptions
##
diff --git a/lib/bas/dispatcher/discord/implementation.rb b/lib/bas/process/discord/implementation.rb
similarity index 66%
rename from lib/bas/dispatcher/discord/implementation.rb
rename to lib/bas/process/discord/implementation.rb
index 305ab39..d8b608e 100644
--- a/lib/bas/dispatcher/discord/implementation.rb
+++ b/lib/bas/process/discord/implementation.rb
@@ -4,26 +4,26 @@
require_relative "./exceptions/invalid_webhook_token"
require_relative "./types/response"
-module Dispatcher
+module Process
module Discord
##
- # This class is an implementation of the Dispatcher::Base interface, specifically designed
- # for dispatching messages to Discord.
+ # This class is an implementation of the Process::Base interface, specifically designed
+ # for sending messages to Discord.
#
class Implementation < Base
- # Implements the dispatching logic for the Discord use case. It sends a POST request to
+ # Implements the sending process logic for the Discord use case. It sends a POST request to
# the Discord webhook with the specified payload.
#
#
# Params:
- # * String payload: Payload to be dispatched to discord.
+ # * String payload: Payload to be send to discord.
#
# raises Exceptions::Discord::InvalidWebookToken if the provided webhook token is invalid.
#
#
- # returns Dispatcher::Discord::Types::Response
+ # returns Process::Discord::Types::Response
#
- def dispatch(payload)
+ def execute(payload)
body = {
username: name,
avatar_url: "",
@@ -31,7 +31,7 @@ def dispatch(payload)
}.to_json
response = HTTParty.post(webhook, { body: body, headers: { "Content-Type" => "application/json" } })
- discord_response = Dispatcher::Discord::Types::Response.new(response)
+ discord_response = Process::Discord::Types::Response.new(response)
validate_response(discord_response)
end
diff --git a/lib/bas/dispatcher/discord/types/response.rb b/lib/bas/process/discord/types/response.rb
similarity index 96%
rename from lib/bas/dispatcher/discord/types/response.rb
rename to lib/bas/process/discord/types/response.rb
index ad04a59..3eba088 100644
--- a/lib/bas/dispatcher/discord/types/response.rb
+++ b/lib/bas/process/discord/types/response.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-module Dispatcher
+module Process
module Discord
module Types
##
diff --git a/lib/bas/dispatcher/slack/exceptions/invalid_webhook_token.rb b/lib/bas/process/slack/exceptions/invalid_webhook_token.rb
similarity index 95%
rename from lib/bas/dispatcher/slack/exceptions/invalid_webhook_token.rb
rename to lib/bas/process/slack/exceptions/invalid_webhook_token.rb
index 54ccd9a..ae61270 100644
--- a/lib/bas/dispatcher/slack/exceptions/invalid_webhook_token.rb
+++ b/lib/bas/process/slack/exceptions/invalid_webhook_token.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-module Dispatcher
+module Process
module Slack
module Exceptions
##
diff --git a/lib/bas/dispatcher/slack/implementation.rb b/lib/bas/process/slack/implementation.rb
similarity index 60%
rename from lib/bas/dispatcher/slack/implementation.rb
rename to lib/bas/process/slack/implementation.rb
index 6299fe2..4f872a0 100644
--- a/lib/bas/dispatcher/slack/implementation.rb
+++ b/lib/bas/process/slack/implementation.rb
@@ -4,26 +4,26 @@
require_relative "./exceptions/invalid_webhook_token"
require_relative "./types/response"
-module Dispatcher
+module Process
module Slack
##
- # This class is an implementation of the Dispatcher::Base interface, specifically designed
- # for dispatching messages to Slack.
+ # This class is an implementation of the Process::Base interface, specifically designed
+ # for sending messages to Slack.
#
class Implementation < Base
- # Implements the dispatching logic for the Slack use case. It sends a POST request to
+ # Implements the sending process logic for the Slack use case. It sends a POST request to
# the Slack webhook with the specified payload.
#
#
# Params:
- # * String payload: Payload to be dispatched to slack.
+ # * String payload: Payload to be send to slack.
#
# raises Exceptions::Slack::InvalidWebookToken if the provided webhook token is invalid.
#
#
- # returns Dispatcher::Slack::Types::Response
+ # returns Process::Slack::Types::Response
#
- def dispatch(payload)
+ def execute(payload)
body = {
username: name,
text: payload
@@ -31,7 +31,7 @@ def dispatch(payload)
response = HTTParty.post(webhook, { body: body, headers: { "Content-Type" => "application/json" } })
- slack_response = Dispatcher::Discord::Types::Response.new(response)
+ slack_response = Process::Discord::Types::Response.new(response)
validate_response(slack_response)
end
@@ -41,7 +41,7 @@ def dispatch(payload)
def validate_response(response)
case response.http_code
when 403
- raise Dispatcher::Slack::Exceptions::InvalidWebookToken, response.message
+ raise Process::Slack::Exceptions::InvalidWebookToken, response.message
else
response
end
diff --git a/lib/bas/dispatcher/slack/types/response.rb b/lib/bas/process/slack/types/response.rb
similarity index 96%
rename from lib/bas/dispatcher/slack/types/response.rb
rename to lib/bas/process/slack/types/response.rb
index c018245..422f038 100644
--- a/lib/bas/dispatcher/slack/types/response.rb
+++ b/lib/bas/process/slack/types/response.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-module Dispatcher
+module Process
module Slack
module Types
##
From fa1800d1b8145310d0ffa7e9670e05b3f3219533 Mon Sep 17 00:00:00 2001
From: FelipeGuzmanSierra
<97761783+FelipeGuzmanSierra@users.noreply.github.com>
Date: Fri, 12 Apr 2024 16:28:51 -0500
Subject: [PATCH 2/5] Rename Dispatcher component test to Process
---
spec/bas/dispatcher/base_spec.rb | 23 --------
spec/bas/dispatcher/discord_spec.rb | 56 ------------------
spec/bas/dispatcher/slack_spec.rb | 58 -------------------
spec/bas/process/base_spec.rb | 23 ++++++++
spec/bas/process/discord_spec.rb | 56 ++++++++++++++++++
spec/bas/process/slack_spec.rb | 58 +++++++++++++++++++
...yml => failed_process_invalid_webhook.yml} | 0
...ccess_dispatch.yml => success_process.yml} | 0
...ame.yml => success_process_empty_name.yml} | 0
...d.yml => failed_process_empty_payload.yml} | 0
...yml => failed_process_invalid_webhook.yml} | 0
...ccess_dispatch.yml => success_process.yml} | 0
...ame.yml => success_process_empty_name.yml} | 0
13 files changed, 137 insertions(+), 137 deletions(-)
delete mode 100644 spec/bas/dispatcher/base_spec.rb
delete mode 100644 spec/bas/dispatcher/discord_spec.rb
delete mode 100644 spec/bas/dispatcher/slack_spec.rb
create mode 100644 spec/bas/process/base_spec.rb
create mode 100644 spec/bas/process/discord_spec.rb
create mode 100644 spec/bas/process/slack_spec.rb
rename spec/fixtures/vcr_cassettes/discord/{failed_dispatch_invalid_webhook.yml => failed_process_invalid_webhook.yml} (100%)
rename spec/fixtures/vcr_cassettes/discord/{success_dispatch.yml => success_process.yml} (100%)
rename spec/fixtures/vcr_cassettes/discord/{success_dispatch_empty_name.yml => success_process_empty_name.yml} (100%)
rename spec/fixtures/vcr_cassettes/slack/{failed_dispatch_empty_payload.yml => failed_process_empty_payload.yml} (100%)
rename spec/fixtures/vcr_cassettes/slack/{failed_dispatch_invalid_webhook.yml => failed_process_invalid_webhook.yml} (100%)
rename spec/fixtures/vcr_cassettes/slack/{success_dispatch.yml => success_process.yml} (100%)
rename spec/fixtures/vcr_cassettes/slack/{success_dispatch_empty_name.yml => success_process_empty_name.yml} (100%)
diff --git a/spec/bas/dispatcher/base_spec.rb b/spec/bas/dispatcher/base_spec.rb
deleted file mode 100644
index 1d6cc80..0000000
--- a/spec/bas/dispatcher/base_spec.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-RSpec.describe Dispatcher::Base do
- before do
- @config = { webhook: "https://example.com/webhook", name: "Example Name" }
- @dispatcher = described_class.new(@config)
- end
-
- describe "Arguments and methods" do
- it { expect(@dispatcher).to respond_to(:webhook) }
- it { expect(@dispatcher).to respond_to(:name) }
-
- it { expect(described_class).to respond_to(:new).with(1).arguments }
- it { expect(@dispatcher).to respond_to(:dispatch).with(1).arguments }
- end
-
- describe ".dispatch" do
- it "provides no implementation for the method" do
- payload = ""
- expect { @dispatcher.dispatch(payload) }.to raise_exception(Domain::Exceptions::FunctionNotImplemented)
- end
- end
-end
diff --git a/spec/bas/dispatcher/discord_spec.rb b/spec/bas/dispatcher/discord_spec.rb
deleted file mode 100644
index bce6a5e..0000000
--- a/spec/bas/dispatcher/discord_spec.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-# frozen_string_literal: true
-
-RSpec.describe Dispatcher::Discord::Implementation do
- before do
- @config = {
- webhook: "https://discord.com/api/webhooks/1196541734138691615/lFFCvFdMVEvfKWtFID2TSBjNjjBvEwqRbG2czOz3X_HfHfIgmXh6SDlFRXaXLOignsOj",
- name: "Test Birthday Bot"
- }
-
- @payload = "John Doe, Wishing you a very happy birthday! Enjoy your special day! :birthday: :gift:"
-
- @dispatcher = described_class.new(@config)
- end
-
- describe "attributes and arguments" do
- it { expect(@dispatcher).to respond_to(:webhook) }
- it { expect(@dispatcher).to respond_to(:name) }
-
- it { expect(described_class).to respond_to(:new).with(1).arguments }
- it { expect(@dispatcher).to respond_to(:dispatch).with(1).arguments }
- end
-
- describe ".dispatch" do
- it "dispatch a notification message to discord" do
- VCR.use_cassette("/discord/success_dispatch") do
- discords_dispatcher = described_class.new(@config)
-
- response = discords_dispatcher.dispatch(@payload)
-
- expect(response.http_code).to eq(204)
- end
- end
-
- it "doesn't dispatch a notification message to discord" do
- VCR.use_cassette("/discord/success_dispatch_empty_name") do
- discords_dispatcher = described_class.new(@config)
-
- response = discords_dispatcher.dispatch(@payload)
- expect(response.http_code).to eq(204)
- end
- end
-
- it "raises an exception caused by incorrect webhook provided" do
- VCR.use_cassette("/discord/failed_dispatch_invalid_webhook") do
- config = @config
- config[:webhook] = "https://discord.com/api/webhooks/1196541734138691615/lFFCvFdMVEvfKWtFID2TSBjNjjBvEwqRbG2czOz3X_JfHfIgmXh6SDlFRXaXLOignsIP"
-
- discords_dispatcher = described_class.new(config)
-
- expect do
- discords_dispatcher.dispatch(@payload)
- end.to raise_exception(Dispatcher::Discord::Exceptions::InvalidWebookToken)
- end
- end
- end
-end
diff --git a/spec/bas/dispatcher/slack_spec.rb b/spec/bas/dispatcher/slack_spec.rb
deleted file mode 100644
index 3f6412f..0000000
--- a/spec/bas/dispatcher/slack_spec.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-# frozen_string_literal: true
-
-RSpec.describe Dispatcher::Slack::Implementation do
- before do
- @config = {
- webhook: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
- name: "Test Bot"
- }
-
- @payload = "Some payload, to be sent, including icons :grinning:"
-
- @dispatcher = described_class.new(@config)
- end
-
- describe "attributes and arguments" do
- it { expect(@dispatcher).to respond_to(:webhook) }
- it { expect(@dispatcher).to respond_to(:name) }
-
- it { expect(described_class).to respond_to(:new).with(1).arguments }
- it { expect(@dispatcher).to respond_to(:dispatch).with(1).arguments }
- end
-
- describe ".dispatch" do
- it "dispatch a notification message to slack" do
- VCR.use_cassette("/slack/success_dispatch") do
- discords_dispatcher = described_class.new(@config)
-
- response = discords_dispatcher.dispatch(@payload)
-
- expect(response).to be_an_instance_of(Dispatcher::Discord::Types::Response)
- expect(response.http_code).to eq(200)
- end
- end
-
- it "doesn't dispatch a notification message to slack caused by empty payload" do
- VCR.use_cassette("/slack/failed_dispatch_empty_payload") do
- discords_dispatcher = described_class.new(@config)
-
- response = discords_dispatcher.dispatch("")
- expect(response).to be_an_instance_of(Dispatcher::Discord::Types::Response)
- expect(response.http_code).to eq(400)
- end
- end
-
- it "raises an exception caused by incorrect webhook provided" do
- VCR.use_cassette("/slack/failed_dispatch_invalid_webhook") do
- config = @config
- config[:webhook] = "https://hooks.slack.com/services/T00000011/B00000011/XXXXXXXXXXXXXXXXXXXXXXWW"
-
- discords_dispatcher = described_class.new(config)
-
- expect do
- discords_dispatcher.dispatch(@payload)
- end.to raise_exception(Dispatcher::Slack::Exceptions::InvalidWebookToken)
- end
- end
- end
-end
diff --git a/spec/bas/process/base_spec.rb b/spec/bas/process/base_spec.rb
new file mode 100644
index 0000000..30ce9c0
--- /dev/null
+++ b/spec/bas/process/base_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+RSpec.describe Process::Base do
+ before do
+ @config = { webhook: "https://example.com/webhook", name: "Example Name" }
+ @process = described_class.new(@config)
+ end
+
+ describe "Arguments and methods" do
+ it { expect(@process).to respond_to(:webhook) }
+ it { expect(@process).to respond_to(:name) }
+
+ it { expect(described_class).to respond_to(:new).with(1).arguments }
+ it { expect(@process).to respond_to(:execute).with(1).arguments }
+ end
+
+ describe ".execute" do
+ it "provides no implementation for the method" do
+ payload = ""
+ expect { @process.execute(payload) }.to raise_exception(Domain::Exceptions::FunctionNotImplemented)
+ end
+ end
+end
diff --git a/spec/bas/process/discord_spec.rb b/spec/bas/process/discord_spec.rb
new file mode 100644
index 0000000..4cfc974
--- /dev/null
+++ b/spec/bas/process/discord_spec.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+RSpec.describe Process::Discord::Implementation do
+ before do
+ @config = {
+ webhook: "https://discord.com/api/webhooks/1196541734138691615/lFFCvFdMVEvfKWtFID2TSBjNjjBvEwqRbG2czOz3X_HfHfIgmXh6SDlFRXaXLOignsOj",
+ name: "Test Birthday Bot"
+ }
+
+ @payload = "John Doe, Wishing you a very happy birthday! Enjoy your special day! :birthday: :gift:"
+
+ @process = described_class.new(@config)
+ end
+
+ describe "attributes and arguments" do
+ it { expect(@process).to respond_to(:webhook) }
+ it { expect(@process).to respond_to(:name) }
+
+ it { expect(described_class).to respond_to(:new).with(1).arguments }
+ it { expect(@process).to respond_to(:execute).with(1).arguments }
+ end
+
+ describe ".execute" do
+ it "send a notification message to discord" do
+ VCR.use_cassette("/discord/success_process") do
+ discords_process = described_class.new(@config)
+
+ response = discords_process.execute(@payload)
+
+ expect(response.http_code).to eq(204)
+ end
+ end
+
+ it "doesn't send a notification message to discord" do
+ VCR.use_cassette("/discord/success_process_empty_name") do
+ discords_process = described_class.new(@config)
+
+ response = discords_process.execute(@payload)
+ expect(response.http_code).to eq(204)
+ end
+ end
+
+ it "raises an exception caused by incorrect webhook provided" do
+ VCR.use_cassette("/discord/failed_process_invalid_webhook") do
+ config = @config
+ config[:webhook] = "https://discord.com/api/webhooks/1196541734138691615/lFFCvFdMVEvfKWtFID2TSBjNjjBvEwqRbG2czOz3X_JfHfIgmXh6SDlFRXaXLOignsIP"
+
+ discords_process = described_class.new(config)
+
+ expect do
+ discords_process.execute(@payload)
+ end.to raise_exception(Process::Discord::Exceptions::InvalidWebookToken)
+ end
+ end
+ end
+end
diff --git a/spec/bas/process/slack_spec.rb b/spec/bas/process/slack_spec.rb
new file mode 100644
index 0000000..207b0d9
--- /dev/null
+++ b/spec/bas/process/slack_spec.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+RSpec.describe Process::Slack::Implementation do
+ before do
+ @config = {
+ webhook: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
+ name: "Test Bot"
+ }
+
+ @payload = "Some payload, to be sent, including icons :grinning:"
+
+ @process = described_class.new(@config)
+ end
+
+ describe "attributes and arguments" do
+ it { expect(@process).to respond_to(:webhook) }
+ it { expect(@process).to respond_to(:name) }
+
+ it { expect(described_class).to respond_to(:new).with(1).arguments }
+ it { expect(@process).to respond_to(:execute).with(1).arguments }
+ end
+
+ describe ".execute" do
+ it "send a notification message to slack" do
+ VCR.use_cassette("/slack/success_process") do
+ discords_process = described_class.new(@config)
+
+ response = discords_process.execute(@payload)
+
+ expect(response).to be_an_instance_of(Process::Discord::Types::Response)
+ expect(response.http_code).to eq(200)
+ end
+ end
+
+ it "doesn't send a notification message to slack caused by empty payload" do
+ VCR.use_cassette("/slack/failed_process_empty_payload") do
+ discords_process = described_class.new(@config)
+
+ response = discords_process.execute("")
+ expect(response).to be_an_instance_of(Process::Discord::Types::Response)
+ expect(response.http_code).to eq(400)
+ end
+ end
+
+ it "raises an exception caused by incorrect webhook provided" do
+ VCR.use_cassette("/slack/failed_process_invalid_webhook") do
+ config = @config
+ config[:webhook] = "https://hooks.slack.com/services/T00000011/B00000011/XXXXXXXXXXXXXXXXXXXXXXWW"
+
+ discords_process = described_class.new(config)
+
+ expect do
+ discords_process.execute(@payload)
+ end.to raise_exception(Process::Slack::Exceptions::InvalidWebookToken)
+ end
+ end
+ end
+end
diff --git a/spec/fixtures/vcr_cassettes/discord/failed_dispatch_invalid_webhook.yml b/spec/fixtures/vcr_cassettes/discord/failed_process_invalid_webhook.yml
similarity index 100%
rename from spec/fixtures/vcr_cassettes/discord/failed_dispatch_invalid_webhook.yml
rename to spec/fixtures/vcr_cassettes/discord/failed_process_invalid_webhook.yml
diff --git a/spec/fixtures/vcr_cassettes/discord/success_dispatch.yml b/spec/fixtures/vcr_cassettes/discord/success_process.yml
similarity index 100%
rename from spec/fixtures/vcr_cassettes/discord/success_dispatch.yml
rename to spec/fixtures/vcr_cassettes/discord/success_process.yml
diff --git a/spec/fixtures/vcr_cassettes/discord/success_dispatch_empty_name.yml b/spec/fixtures/vcr_cassettes/discord/success_process_empty_name.yml
similarity index 100%
rename from spec/fixtures/vcr_cassettes/discord/success_dispatch_empty_name.yml
rename to spec/fixtures/vcr_cassettes/discord/success_process_empty_name.yml
diff --git a/spec/fixtures/vcr_cassettes/slack/failed_dispatch_empty_payload.yml b/spec/fixtures/vcr_cassettes/slack/failed_process_empty_payload.yml
similarity index 100%
rename from spec/fixtures/vcr_cassettes/slack/failed_dispatch_empty_payload.yml
rename to spec/fixtures/vcr_cassettes/slack/failed_process_empty_payload.yml
diff --git a/spec/fixtures/vcr_cassettes/slack/failed_dispatch_invalid_webhook.yml b/spec/fixtures/vcr_cassettes/slack/failed_process_invalid_webhook.yml
similarity index 100%
rename from spec/fixtures/vcr_cassettes/slack/failed_dispatch_invalid_webhook.yml
rename to spec/fixtures/vcr_cassettes/slack/failed_process_invalid_webhook.yml
diff --git a/spec/fixtures/vcr_cassettes/slack/success_dispatch.yml b/spec/fixtures/vcr_cassettes/slack/success_process.yml
similarity index 100%
rename from spec/fixtures/vcr_cassettes/slack/success_dispatch.yml
rename to spec/fixtures/vcr_cassettes/slack/success_process.yml
diff --git a/spec/fixtures/vcr_cassettes/slack/success_dispatch_empty_name.yml b/spec/fixtures/vcr_cassettes/slack/success_process_empty_name.yml
similarity index 100%
rename from spec/fixtures/vcr_cassettes/slack/success_dispatch_empty_name.yml
rename to spec/fixtures/vcr_cassettes/slack/success_process_empty_name.yml
From e67df980ac1e50fbe3429ba6f6a17c01a6075336 Mon Sep 17 00:00:00 2001
From: FelipeGuzmanSierra
<97761783+FelipeGuzmanSierra@users.noreply.github.com>
Date: Fri, 12 Apr 2024 16:29:25 -0500
Subject: [PATCH 3/5] Update references to the Dispatcher
---
lib/bas/formatter/base.rb | 2 +-
lib/bas/formatter/birthday.rb | 4 +--
lib/bas/formatter/pto.rb | 4 +--
lib/bas/formatter/support_emails.rb | 4 +--
lib/bas/formatter/work_items_limit.rb | 4 +--
lib/bas/use_cases/types/config.rb | 6 ++--
lib/bas/use_cases/use_case.rb | 10 +++---
lib/bas/use_cases/use_cases.rb | 48 +++++++++++++--------------
8 files changed, 41 insertions(+), 41 deletions(-)
diff --git a/lib/bas/formatter/base.rb b/lib/bas/formatter/base.rb
index f0f05de..f99385c 100644
--- a/lib/bas/formatter/base.rb
+++ b/lib/bas/formatter/base.rb
@@ -30,7 +30,7 @@ def initialize(config = {})
#
# raises Domain::Exceptions::FunctionNotImplemented when missing implementation.
#
- # returns String Formatted payload suitable for a Dispatcher::Base implementation.
+ # returns String Formatted payload suitable for a Process::Base implementation.
#
def format(_domain_data)
raise Domain::Exceptions::FunctionNotImplemented
diff --git a/lib/bas/formatter/birthday.rb b/lib/bas/formatter/birthday.rb
index 968a4b2..66a857a 100644
--- a/lib/bas/formatter/birthday.rb
+++ b/lib/bas/formatter/birthday.rb
@@ -7,7 +7,7 @@
module Formatter
##
# This class implements methods from the Formatter::Base module, tailored to format the
- # Domain::Birthday structure for a dispatcher.
+ # Domain::Birthday structure for a Process.
class Birthday < Base
# Implements the logic for building a formatted payload with the given template for birthdays.
#
@@ -19,7 +19,7 @@ class Birthday < Base
# raises Formatter::Exceptions::InvalidData when invalid data is provided.
#
#
- # returns String payload: formatted payload suitable for a Dispatcher.
+ # returns String payload: formatted payload suitable for a Processor.
#
def format(birthdays_list)
raise Formatter::Exceptions::InvalidData unless birthdays_list.all? do |brithday|
diff --git a/lib/bas/formatter/pto.rb b/lib/bas/formatter/pto.rb
index 39615a1..b982552 100644
--- a/lib/bas/formatter/pto.rb
+++ b/lib/bas/formatter/pto.rb
@@ -9,7 +9,7 @@
module Formatter
##
# This class implements methods from the Formatter::Base module, tailored to format the
- # Domain::Pto structure for a dispatcher.
+ # Domain::Pto structure for a Process.
class Pto < Base
DEFAULT_TIME_ZONE = "+00:00"
@@ -32,7 +32,7 @@ def initialize(config = {})
# raises Formatter::Exceptions::InvalidData when invalid data is provided.
#
#
- # returns String payload, formatted payload suitable for a Dispatcher.
+ # returns String payload, formatted payload suitable for a Processor.
#
def format(ptos_list)
diff --git a/lib/bas/formatter/support_emails.rb b/lib/bas/formatter/support_emails.rb
index c7ae177..f7acaae 100644
--- a/lib/bas/formatter/support_emails.rb
+++ b/lib/bas/formatter/support_emails.rb
@@ -7,7 +7,7 @@
module Formatter
##
# This class implements methods from the Formatter::Base module, tailored to format the
- # Domain::Email structure for a dispatcher.
+ # Domain::Email structure for a Process.
class SupportEmails < Base
DEFAULT_TIME_ZONE = "+00:00"
@@ -31,7 +31,7 @@ def initialize(config = {})
# raises Formatter::Exceptions::InvalidData when invalid data is provided.
#
#
- # returns String payload: formatted payload suitable for a Dispatcher.
+ # returns String payload: formatted payload suitable for a Processor.
#
def format(support_emails_list)
raise Formatter::Exceptions::InvalidData unless support_emails_list.all? do |support_email|
diff --git a/lib/bas/formatter/work_items_limit.rb b/lib/bas/formatter/work_items_limit.rb
index 1c11e72..218f2b7 100644
--- a/lib/bas/formatter/work_items_limit.rb
+++ b/lib/bas/formatter/work_items_limit.rb
@@ -7,7 +7,7 @@
module Formatter
##
# This class implements methods from the Formatter::Base module, tailored to format the
- # Domain::WorkItemsLimit structure for a dispatcher.
+ # Domain::WorkItemsLimit structure for a Process.
class WorkItemsLimit < Base
DEFAULT_DOMAIN_LIMIT = 6
@@ -30,7 +30,7 @@ def initialize(config = {})
# raises Formatter::Exceptions::InvalidData when invalid data is provided.
#
#
- # returns String payload, formatted payload suitable for a Dispatcher.
+ # returns String payload, formatted payload suitable for a Processor.
#
def format(work_items_list)
diff --git a/lib/bas/use_cases/types/config.rb b/lib/bas/use_cases/types/config.rb
index 13297ef..33290d6 100644
--- a/lib/bas/use_cases/types/config.rb
+++ b/lib/bas/use_cases/types/config.rb
@@ -6,13 +6,13 @@ module Types
# Represents a the configuration composing the initial components required by a UseCases::UseCase implementation.
#
class Config
- attr_reader :read, :serialize, :formatter, :dispatcher
+ attr_reader :read, :serialize, :formatter, :process
- def initialize(read, serialize, formatter, dispatcher)
+ def initialize(read, serialize, formatter, process)
@read = read
@serialize = serialize
@formatter = formatter
- @dispatcher = dispatcher
+ @process = process
end
end
end
diff --git a/lib/bas/use_cases/use_case.rb b/lib/bas/use_cases/use_case.rb
index f045486..608763b 100644
--- a/lib/bas/use_cases/use_case.rb
+++ b/lib/bas/use_cases/use_case.rb
@@ -6,7 +6,7 @@ module UseCases
# logic flow by coordinating the execution of its components to fulfill a specific use case.
#
class UseCase
- attr_reader :read, :serialize, :formatter, :dispatcher
+ attr_reader :read, :serialize, :formatter, :process
# Initializes the use case with the necessary components.
#
@@ -18,13 +18,13 @@ def initialize(config)
@read = config.read
@serialize = config.serialize
@formatter = config.formatter
- @dispatcher = config.dispatcher
+ @process = config.process
end
- # Executes the use case by orchestrating the sequential execution of the read, serialize, formatter, and dispatcher.
+ # Executes the use case by orchestrating the sequential execution of the read, serialize, formatter, and process.
#
#
- # returns Dispatcher::Discord::Types::Response
+ # returns Process::Discord::Types::Response
#
def perform
response = read.execute
@@ -33,7 +33,7 @@ def perform
formatted_payload = formatter.format(serialization)
- dispatcher.dispatch(formatted_payload)
+ process.execute(formatted_payload)
end
end
end
diff --git a/lib/bas/use_cases/use_cases.rb b/lib/bas/use_cases/use_cases.rb
index 9916e34..1ee2b9d 100644
--- a/lib/bas/use_cases/use_cases.rb
+++ b/lib/bas/use_cases/use_cases.rb
@@ -24,9 +24,9 @@
require_relative "../formatter/work_items_limit"
require_relative "../formatter/support_emails"
-# dispatcher
-require_relative "../dispatcher/discord/implementation"
-require_relative "../dispatcher/slack/implementation"
+# process
+require_relative "../process/discord/implementation"
+require_relative "../process/slack/implementation"
require_relative "use_case"
require_relative "./types/config"
@@ -45,7 +45,7 @@ module UseCases
# database_id: NOTION_DATABASE_ID,
# secret: NOTION_API_INTEGRATION_SECRET,
# },
- # dispatch_options: {
+ # process_options: {
# webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
# name: "Birthday Bot"
# }
@@ -78,8 +78,8 @@ def self.notify_birthday_from_notion_to_discord(options)
read = Read::Notion::BirthdayToday.new(options[:read_options])
serialize = Serialize::Notion::BirthdayToday.new
formatter = Formatter::Birthday.new(options[:format_options])
- dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, dispatcher)
+ process = Process::Discord::Implementation.new(options[:process_options])
+ use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process)
UseCases::UseCase.new(use_case_config)
end
@@ -93,7 +93,7 @@ def self.notify_birthday_from_notion_to_discord(options)
# database_id: NOTION_DATABASE_ID,
# secret: NOTION_API_INTEGRATION_SECRET,
# },
- # dispatch_options: {
+ # process_options: {
# webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
# name: "Birthday Bot"
# },
@@ -130,8 +130,8 @@ def self.notify_next_week_birthday_from_notion_to_discord(options)
read = Read::Notion::BirthdayNextWeek.new(options[:read_options])
serialize = Serialize::Notion::BirthdayToday.new
formatter = Formatter::Birthday.new(options[:format_options])
- dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
- use_case_cofig = UseCases::Types::Config.new(read, serialize, formatter, dispatcher)
+ process = Process::Discord::Implementation.new(options[:process_options])
+ use_case_cofig = UseCases::Types::Config.new(read, serialize, formatter, process)
UseCases::UseCase.new(use_case_cofig)
end
@@ -146,7 +146,7 @@ def self.notify_next_week_birthday_from_notion_to_discord(options)
# database_id: NOTION_DATABASE_ID,
# secret: NOTION_API_INTEGRATION_SECRET,
# },
- # dispatch_options: {
+ # process_options: {
# webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
# name: "Pto Bot"
# }
@@ -177,8 +177,8 @@ def self.notify_pto_from_notion_to_discord(options)
read = Read::Notion::PtoToday.new(options[:read_options])
serialize = Serialize::Notion::PtoToday.new
formatter = Formatter::Pto.new(options[:format_options])
- dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, dispatcher)
+ process = Process::Discord::Implementation.new(options[:process_options])
+ use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process)
UseCases::UseCase.new(use_case_config)
end
@@ -193,7 +193,7 @@ def self.notify_pto_from_notion_to_discord(options)
# database_id: NOTION_DATABASE_ID,
# secret: NOTION_API_INTEGRATION_SECRET,
# },
- # dispatch_options: {
+ # process_options: {
# webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
# name: "Pto Bot"
# },
@@ -228,8 +228,8 @@ def self.notify_next_week_pto_from_notion_to_discord(options)
read = Read::Notion::PtoNextWeek.new(options[:read_options])
serialize = Serialize::Notion::PtoToday.new
formatter = Formatter::Pto.new(options[:format_options])
- dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, dispatcher)
+ process = Process::Discord::Implementation.new(options[:process_options])
+ use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process)
UseCases::UseCase.new(use_case_config)
end
@@ -249,7 +249,7 @@ def self.notify_next_week_pto_from_notion_to_discord(options)
# password: "postgres"
# }
# },
- # dispatch_options:{
+ # process_options:{
# webhook: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
# name: "Pto Bot"
# },
@@ -282,8 +282,8 @@ def self.notify_pto_from_postgres_to_slack(options)
read = Read::Postgres::PtoToday.new(options[:read_options])
serialize = Serialize::Postgres::PtoToday.new
formatter = Formatter::Pto.new(options[:format_options])
- dispatcher = Dispatcher::Slack::Implementation.new(options[:dispatch_options])
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, dispatcher)
+ process = Process::Slack::Implementation.new(options[:process_options])
+ use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process)
UseCases::UseCase.new(use_case_config)
end
@@ -298,7 +298,7 @@ def self.notify_pto_from_postgres_to_slack(options)
# database_id: NOTION_DATABASE_ID,
# secret: NOTION_API_INTEGRATION_SECRET
# },
- # dispatch_options: {
+ # process_options: {
# webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
# name: "wipLimit"
# }
@@ -329,8 +329,8 @@ def self.notify_wip_limit_from_notion_to_discord(options)
read = Read::Notion::WorkItemsLimit.new(options[:read_options])
serialize = Serialize::Notion::WorkItemsLimit.new
formatter = Formatter::WorkItemsLimit.new(options[:format_options])
- dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, dispatcher)
+ process = Process::Discord::Implementation.new(options[:process_options])
+ use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process)
UseCases::UseCase.new(use_case_config)
end
@@ -349,7 +349,7 @@ def self.notify_wip_limit_from_notion_to_discord(options)
# inbox: 'INBOX',
# search_email: 'support@email.co'
# },
- # dispatch_options: {
+ # process_options: {
# webhook: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
# name: "emailSupport"
# }
@@ -371,8 +371,8 @@ def self.notify_support_email_from_imap_to_discord(options)
read = Read::Imap::SupportEmails.new(options[:read_options])
serialize = Serialize::Imap::SupportEmails.new
formatter = Formatter::SupportEmails.new(options[:format_options])
- dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, dispatcher)
+ process = Process::Discord::Implementation.new(options[:process_options])
+ use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process)
UseCases::UseCase.new(use_case_config)
end
From 9bc6260c22bb7cd42107ac2ea34b6bcf7a3bdabe Mon Sep 17 00:00:00 2001
From: FelipeGuzmanSierra
<97761783+FelipeGuzmanSierra@users.noreply.github.com>
Date: Fri, 12 Apr 2024 16:29:48 -0500
Subject: [PATCH 4/5] Update README
---
README.md | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/README.md b/README.md
index 51a47d9..7fb5e37 100644
--- a/README.md
+++ b/README.md
@@ -39,7 +39,7 @@ There are 7 currently implemented use cases:
* WIP limit exceeded - from Notion to Discord
* Support email notification - from IMAP to Discord
-For this example we'll analyze the birthday notification use case, bringing data from a notion database, and dispatching the
+For this example we'll analyze the birthday notification use case, bringing data from a notion database, and sending the
notifications to a Discord channel.
A *Use Case* object, consists on 4 main components, having it's own responsibility:
@@ -67,11 +67,11 @@ The **Formatter**, is in charge of preparing the message to be sent in our notif
The template or 'format' to be used should be included in the use case configurations, which we'll review in a further step. It's
implementation can be found under `/bas/formatter/birthday.rb`.
-### 4. Dispatcher - Sending your notification
+### 4. Process - Optional Data Process
-Finally, the **Dispatcher** basically, sends or dispatches the formatted message into a destination, since the use case was implemented for
+Finally, the **Processor** basically, allow required data process depending on the use case like sending formatted messages into a destination. In this case, since the use case was implemented for
Discord, it implements specific logic to communicate with a Discord channel using a webhook. The webhook configuration and name for the 'Sender'
-in the channel should be provided with the initial use case configurations. It can be found under `/bas/dispatcher/discord/implementation.rb`
+in the channel should be provided with the initial use case configurations. It can be found under `/bas/process/discord/implementation.rb`
## Examples
@@ -113,7 +113,7 @@ today = Date.now
}
```
-* A template for the formatter to be used for formatting the payload to dispatch to Discord. For this specific case, the format of the messages should be:
+* A template for the formatter to be used for formatting the payload to be send to Discord. For this specific case, the format of the messages should be:
`"NAME, Wishing you a very happy birthday! Enjoy your special day! :birthday: :gift:"`
@@ -145,7 +145,7 @@ options = {
secret: NOTION_API_INTEGRATION_SECRET,
filter: filter
},
- dispatch_options: {
+ process_options: {
webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
name: "Birthday Bot"
}
@@ -235,7 +235,7 @@ module Notifier
# Service description
class UseCaseName
def self.notify(*)
- options = { read_options:, dispatch_options: }
+ options = { read_options:, process_options: }
begin
use_case = UseCases.use_case_build_function(options)
@@ -266,7 +266,7 @@ module Notifier
]
end
- def self.dispatch_options
+ def self.process_options
{
webhook: DISCORD_WEBHOOK,
name: DISCORD_BOT_NAME
From e4cefa3764f93730e08a65926406e4508db1f0d0 Mon Sep 17 00:00:00 2001
From: FelipeGuzmanSierra
<97761783+FelipeGuzmanSierra@users.noreply.github.com>
Date: Mon, 15 Apr 2024 09:42:05 -0500
Subject: [PATCH 5/5] Fix Processor typo
---
README.md | 2 +-
lib/bas/formatter/birthday.rb | 2 +-
lib/bas/formatter/pto.rb | 2 +-
lib/bas/formatter/support_emails.rb | 2 +-
lib/bas/formatter/work_items_limit.rb | 2 +-
lib/bas/process/base.rb | 2 +-
6 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/README.md b/README.md
index 7fb5e37..3ec3641 100644
--- a/README.md
+++ b/README.md
@@ -69,7 +69,7 @@ implementation can be found under `/bas/formatter/birthday.rb`.
### 4. Process - Optional Data Process
-Finally, the **Processor** basically, allow required data process depending on the use case like sending formatted messages into a destination. In this case, since the use case was implemented for
+Finally, the **Process** basically, allow required data process depending on the use case like sending formatted messages into a destination. In this case, since the use case was implemented for
Discord, it implements specific logic to communicate with a Discord channel using a webhook. The webhook configuration and name for the 'Sender'
in the channel should be provided with the initial use case configurations. It can be found under `/bas/process/discord/implementation.rb`
diff --git a/lib/bas/formatter/birthday.rb b/lib/bas/formatter/birthday.rb
index 66a857a..5294d28 100644
--- a/lib/bas/formatter/birthday.rb
+++ b/lib/bas/formatter/birthday.rb
@@ -19,7 +19,7 @@ class Birthday < Base
# raises Formatter::Exceptions::InvalidData when invalid data is provided.
#
#
- # returns String payload: formatted payload suitable for a Processor.
+ # returns String payload: formatted payload suitable for a Process.
#
def format(birthdays_list)
raise Formatter::Exceptions::InvalidData unless birthdays_list.all? do |brithday|
diff --git a/lib/bas/formatter/pto.rb b/lib/bas/formatter/pto.rb
index b982552..daedd47 100644
--- a/lib/bas/formatter/pto.rb
+++ b/lib/bas/formatter/pto.rb
@@ -32,7 +32,7 @@ def initialize(config = {})
# raises Formatter::Exceptions::InvalidData when invalid data is provided.
#
#
- # returns String payload, formatted payload suitable for a Processor.
+ # returns String payload, formatted payload suitable for a Process.
#
def format(ptos_list)
diff --git a/lib/bas/formatter/support_emails.rb b/lib/bas/formatter/support_emails.rb
index f7acaae..1c826cc 100644
--- a/lib/bas/formatter/support_emails.rb
+++ b/lib/bas/formatter/support_emails.rb
@@ -31,7 +31,7 @@ def initialize(config = {})
# raises Formatter::Exceptions::InvalidData when invalid data is provided.
#
#
- # returns String payload: formatted payload suitable for a Processor.
+ # returns String payload: formatted payload suitable for a Process.
#
def format(support_emails_list)
raise Formatter::Exceptions::InvalidData unless support_emails_list.all? do |support_email|
diff --git a/lib/bas/formatter/work_items_limit.rb b/lib/bas/formatter/work_items_limit.rb
index 218f2b7..9091df9 100644
--- a/lib/bas/formatter/work_items_limit.rb
+++ b/lib/bas/formatter/work_items_limit.rb
@@ -30,7 +30,7 @@ def initialize(config = {})
# raises Formatter::Exceptions::InvalidData when invalid data is provided.
#
#
- # returns String payload, formatted payload suitable for a Processor.
+ # returns String payload, formatted payload suitable for a Process.
#
def format(work_items_list)
diff --git a/lib/bas/process/base.rb b/lib/bas/process/base.rb
index cd66637..59d8b86 100644
--- a/lib/bas/process/base.rb
+++ b/lib/bas/process/base.rb
@@ -11,7 +11,7 @@ module Process
class Base
attr_reader :webhook, :name
- # Initializes the processor with essential configuration parameters.
+ # Initializes the process with essential configuration parameters.
#
def initialize(config)
@webhook = config[:webhook]