Module: UseCases
- Included in:
- Bas
- Defined in:
- lib/bas/use_cases/use_cases.rb,
lib/bas/use_cases/use_case.rb,
lib/bas/use_cases/types/config.rb
Overview
This module provides factory methods for use cases within the system. Each method represents a use case implementation introduced in the system.
Defined Under Namespace
Modules: Types Classes: UseCase
Class Method Summary collapse
-
.notify_birthday_from_notion_to_discord(options) ⇒ Object
Provides an instance of the Birthdays notifications from Notion to Discord use case implementation.
-
.notify_next_week_birthday_from_notion_to_discord(options) ⇒ Object
Provides an instance of the next week Birthdays notifications from Notion to Discord use case implementation.
-
.notify_next_week_pto_from_notion_to_discord(options) ⇒ Object
Provides an instance of the next week PTO notifications from Notion to Discord use case implementation.
-
.notify_pto_from_notion_to_discord(options) ⇒ Object
Provides an instance of the PTO notifications from Notion to Discord use case implementation.
-
.notify_pto_from_postgres_to_slack(options) ⇒ Object
Provides an instance of the PTO notifications from Postgres to Slack use case implementation.
-
.notify_support_email_from_imap_to_discord(options) ⇒ Object
Provides an instance of the support emails from an google IMAP server to Discord use case implementation.
-
.notify_wip_limit_from_notion_to_discord(options) ⇒ Object
Provides an instance of the Work Items wip limit notifications from Notion to Discord use case implementation.
Class Method Details
.notify_birthday_from_notion_to_discord(options) ⇒ Object
Provides an instance of the Birthdays notifications from Notion to Discord use case implementation.
Example
options = {
fetch_options: {
database_id: NOTION_DATABASE_ID,
secret: NOTION_API_INTEGRATION_SECRET,
},
dispatch_options: {
webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
name: "Birthday Bot"
}
}
use_case = UseCases.notify_birthday_from_notion_to_discord(options)
use_case.perform
#################################################################################
Requirements:
* Notion database ID, from a database with the following structure:
_________________________________________________________________________________
| Complete Name (text) | BD_this_year (formula) | BD (date) |
| -------------------- | --------------------------- | ------------------------ |
| John Doe | January 24, 2024 | January 24, 2000 |
| Jane Doe | June 20, 2024 | June 20, 2000 |
---------------------------------------------------------------------------------
With the following formula for the BD_this_year column:
dateAdd(prop("BD"), year(now()) - year(prop("BD")), "years")
* A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
integration** buttons.
* A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
75 76 77 78 79 80 81 82 83 |
# File 'lib/bas/use_cases/use_cases.rb', line 75 def self.notify_birthday_from_notion_to_discord() fetcher = Fetcher::Notion::BirthdayToday.new([:fetch_options]) mapper = Mapper::Notion::BirthdayToday.new formatter = Formatter::Birthday.new([:format_options]) dispatcher = Dispatcher::Discord::Implementation.new([:dispatch_options]) use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher) UseCases::UseCase.new(use_case_config) end |
.notify_next_week_birthday_from_notion_to_discord(options) ⇒ Object
Provides an instance of the next week Birthdays notifications from Notion to Discord use case implementation.
Example
options = {
fetch_options: {
database_id: NOTION_DATABASE_ID,
secret: NOTION_API_INTEGRATION_SECRET,
},
dispatch_options: {
webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
name: "Birthday Bot"
},
format_options: {
template: "individual_name, Wishing you a very happy birthday! Enjoy your special day! :birthday: :gift:",
timezone: "-05:00"
}
}
use_case = UseCases.notify_next_week_birthday_from_notion_to_discord(options)
use_case.perform
#################################################################################
Requirements:
* Notion database ID, from a database with the following structure:
_________________________________________________________________________________
| Complete Name (text) | BD_this_year (formula) | BD (date) |
| -------------------- | --------------------------- | ------------------------ |
| John Doe | January 24, 2024 | January 24, 2000 |
| Jane Doe | June 20, 2024 | June 20, 2000 |
---------------------------------------------------------------------------------
With the following formula for the BD_this_year column:
dateAdd(prop("BD"), year(now()) - year(prop("BD")), "years")
* A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
integration** buttons.
* A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
127 128 129 130 131 132 133 134 135 |
# File 'lib/bas/use_cases/use_cases.rb', line 127 def self.notify_next_week_birthday_from_notion_to_discord() fetcher = Fetcher::Notion::BirthdayNextWeek.new([:fetch_options]) mapper = Mapper::Notion::BirthdayToday.new formatter = Formatter::Birthday.new([:format_options]) dispatcher = Dispatcher::Discord::Implementation.new([:dispatch_options]) use_case_cofig = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher) UseCases::UseCase.new(use_case_cofig) end |
.notify_next_week_pto_from_notion_to_discord(options) ⇒ Object
Provides an instance of the next week PTO notifications from Notion to Discord use case implementation.
Example
options = {
fetch_options: {
database_id: NOTION_DATABASE_ID,
secret: NOTION_API_INTEGRATION_SECRET,
},
dispatch_options: {
webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
name: "Pto Bot"
},
format_options: {
template: ":beach: individual_name its going to be on PTO next week,",
timezone: "-05:00"
}
}
use_case = UseCases.notify_next_week_pto_from_notion_to_discord(options)
use_case.perform
#################################################################################
Requirements:
* Notion database ID, from a database with the following structure:
________________________________________________________________________________________________________
| Person (person) | Desde? (date) | Hasta? (date) |
| -------------------- | --------------------------------------- | ------------------------------------ |
| John Doe | January 24, 2024 | January 27, 2024 |
| Jane Doe | November 11, 2024 2:00 PM | November 11, 2024 6:00 PM |
---------------------------------------------------------------------------------------------------------
* A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
integration** buttons.
* A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
225 226 227 228 229 230 231 232 233 |
# File 'lib/bas/use_cases/use_cases.rb', line 225 def self.notify_next_week_pto_from_notion_to_discord() fetcher = Fetcher::Notion::PtoNextWeek.new([:fetch_options]) mapper = Mapper::Notion::PtoToday.new formatter = Formatter::Pto.new([:format_options]) dispatcher = Dispatcher::Discord::Implementation.new([:dispatch_options]) use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher) UseCases::UseCase.new(use_case_config) end |
.notify_pto_from_notion_to_discord(options) ⇒ Object
Provides an instance of the PTO notifications from Notion to Discord use case implementation.
Example
options = {
fetch_options: {
database_id: NOTION_DATABASE_ID,
secret: NOTION_API_INTEGRATION_SECRET,
},
dispatch_options: {
webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
name: "Pto Bot"
}
}
use_case = UseCases.notify_pto_from_notion_to_discord(options)
use_case.perform
#################################################################################
Requirements:
* Notion database ID, from a database with the following structure:
________________________________________________________________________________________________________
| Person (person) | Desde? (date) | Hasta? (date) |
| -------------------- | --------------------------------------- | ------------------------------------ |
| John Doe | January 24, 2024 | January 27, 2024 |
| Jane Doe | November 11, 2024 2:00 PM | November 11, 2024 6:00 PM |
---------------------------------------------------------------------------------------------------------
* A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
integration** buttons.
* A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
174 175 176 177 178 179 180 181 182 |
# File 'lib/bas/use_cases/use_cases.rb', line 174 def self.notify_pto_from_notion_to_discord() fetcher = Fetcher::Notion::PtoToday.new([:fetch_options]) mapper = Mapper::Notion::PtoToday.new formatter = Formatter::Pto.new([:format_options]) dispatcher = Dispatcher::Discord::Implementation.new([:dispatch_options]) use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher) UseCases::UseCase.new(use_case_config) end |
.notify_pto_from_postgres_to_slack(options) ⇒ Object
Provides an instance of the PTO notifications from Postgres to Slack use case implementation.
Example
options = {
fetch_options: {
connection: {
host: "localhost",
port: 5432,
dbname: "db_pto",
user: "postgres",
password: "postgres"
}
},
dispatch_options:{
webhook: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
name: "Pto Bot"
},
format_options: {
template: "Custom template",
timezone: "-05:00"
}
}
use_case = UseCases.notify_pto_from_postgres_to_slack(options)
use_case.perform
#################################################################################
Requirements:
* A connection to a Postgres database and a table with the following structure:
Column | Type | Collation | Nullable | Default
-----------------+------------------------+-----------+----------+------------------------------
id | integer | | not null | generated always as identity
create_time | date | | |
individual_name | character varying(255) | | |
start_date | date | | |
end_date | date | | |
* A webhook key, which can be generated directly on slack on the desired channel, following this instructions:
https://api.slack.com/messaging/webhooks#create_a_webhook
279 280 281 282 283 284 285 286 287 |
# File 'lib/bas/use_cases/use_cases.rb', line 279 def self.notify_pto_from_postgres_to_slack() fetcher = Fetcher::Postgres::PtoToday.new([:fetch_options]) mapper = Mapper::Postgres::PtoToday.new formatter = Formatter::Pto.new([:format_options]) dispatcher = Dispatcher::Slack::Implementation.new([:dispatch_options]) use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher) UseCases::UseCase.new(use_case_config) end |
.notify_support_email_from_imap_to_discord(options) ⇒ Object
Provides an instance of the support emails from an google IMAP server to Discord use case implementation.
Example
options = {
fetch_options: {
user: '[email protected]',
refresh_token: REFRESH_TOKEN,
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
inbox: 'INBOX',
search_email: '[email protected]'
},
dispatch_options: {
webhook: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
name: "emailSupport"
}
}
use_case = UseCases.notify_support_email_from_imap_to_discord(options)
use_case.perform
#################################################################################
Requirements:
* A google gmail account with IMAP support activated.
* A set of authorization parameters like a client_id, client_secret, and a resfresh_token. To
generate them, follow this instructions: https://developers.google.com/identity/protocols/oauth2
* A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
368 369 370 371 372 373 374 375 376 |
# File 'lib/bas/use_cases/use_cases.rb', line 368 def self.notify_support_email_from_imap_to_discord() fetcher = Fetcher::Imap::SupportEmails.new([:fetch_options]) mapper = Mapper::Imap::SupportEmails.new formatter = Formatter::SupportEmails.new([:format_options]) dispatcher = Dispatcher::Discord::Implementation.new([:dispatch_options]) use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher) UseCases::UseCase.new(use_case_config) end |
.notify_wip_limit_from_notion_to_discord(options) ⇒ Object
Provides an instance of the Work Items wip limit notifications from Notion to Discord use case implementation.
Example
options = {
fetch_options: {
database_id: NOTION_DATABASE_ID,
secret: NOTION_API_INTEGRATION_SECRET
},
dispatch_options: {
webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
name: "wipLimit"
}
}
use_case = UseCases.notify_wip_limit_from_notion_to_discord(options)
use_case.perform
#################################################################################
Requirements:
* Notion database ID, from a database with the following structure:
_________________________________________________________________________________
| OK | Status | Responsible Domain |
| -------------------- | --------------------------- | ------------------------ |
| ✅ | In Progress | "kommit.admin" |
| 🚩 | Fail | "kommit.ops" |
---------------------------------------------------------------------------------
* A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
integration** buttons.
* A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
326 327 328 329 330 331 332 333 334 |
# File 'lib/bas/use_cases/use_cases.rb', line 326 def self.notify_wip_limit_from_notion_to_discord() fetcher = Fetcher::Notion::WorkItemsLimit.new([:fetch_options]) mapper = Mapper::Notion::WorkItemsLimit.new formatter = Formatter::WorkItemsLimit.new([:format_options]) dispatcher = Dispatcher::Discord::Implementation.new([:dispatch_options]) use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher) UseCases::UseCase.new(use_case_config) end |