bns 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/._.rspec_status +0 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +6 -0
- data/README.md +159 -3
- data/lib/bns/dispatcher/discord/exceptions/invalid_webhook_token.rb +2 -2
- data/lib/bns/dispatcher/discord/implementation.rb +1 -1
- data/lib/bns/dispatcher/slack/exceptions/invalid_webhook_token.rb +16 -0
- data/lib/bns/dispatcher/slack/implementation.rb +51 -0
- data/lib/bns/dispatcher/slack/types/response.rb +21 -0
- data/lib/bns/domain/email.rb +34 -0
- data/lib/bns/domain/work_items_limit.rb +25 -0
- data/lib/bns/fetcher/base.rb +13 -0
- data/lib/bns/fetcher/imap/base.rb +70 -0
- data/lib/bns/fetcher/imap/types/response.rb +27 -0
- data/lib/bns/fetcher/imap/use_case/support_emails.rb +26 -0
- data/lib/bns/fetcher/notion/{pto.rb → base.rb} +11 -7
- data/lib/bns/fetcher/notion/types/response.rb +1 -1
- data/lib/bns/fetcher/notion/use_case/birthday_next_week.rb +41 -0
- data/lib/bns/fetcher/notion/use_case/birthday_today.rb +29 -0
- data/lib/bns/fetcher/notion/use_case/pto_next_week.rb +71 -0
- data/lib/bns/fetcher/notion/use_case/pto_today.rb +30 -0
- data/lib/bns/fetcher/notion/use_case/work_items_limit.rb +37 -0
- data/lib/bns/fetcher/postgres/base.rb +46 -0
- data/lib/bns/fetcher/postgres/helper.rb +16 -0
- data/lib/bns/fetcher/postgres/types/response.rb +42 -0
- data/lib/bns/fetcher/postgres/use_case/pto_today.rb +32 -0
- data/lib/bns/formatter/base.rb +11 -8
- data/lib/bns/formatter/birthday.rb +34 -0
- data/lib/bns/formatter/exceptions/invalid_data.rb +15 -0
- data/lib/bns/formatter/pto.rb +88 -0
- data/lib/bns/formatter/support_emails.rb +69 -0
- data/lib/bns/formatter/work_items_limit.rb +64 -0
- data/lib/bns/mapper/imap/support_emails.rb +56 -0
- data/lib/bns/mapper/notion/{birthday.rb → birthday_today.rb} +13 -21
- data/lib/bns/mapper/notion/{pto.rb → pto_today.rb} +15 -41
- data/lib/bns/mapper/notion/work_items_limit.rb +65 -0
- data/lib/bns/mapper/postgres/pto_today.rb +47 -0
- data/lib/bns/use_cases/use_cases.rb +276 -49
- data/lib/bns/version.rb +1 -1
- metadata +31 -9
- data/lib/bns/fetcher/notion/birthday.rb +0 -53
- data/lib/bns/formatter/discord/birthday.rb +0 -36
- data/lib/bns/formatter/discord/exceptions/invalid_data.rb +0 -17
- data/lib/bns/formatter/discord/pto.rb +0 -49
@@ -8,9 +8,11 @@ module Mapper
|
|
8
8
|
##
|
9
9
|
# This class implementats the methods of the Mapper::Base module, specifically designed for preparing or
|
10
10
|
# shaping birthdays data coming from a Fetcher::Base implementation.
|
11
|
-
class
|
11
|
+
class BirthdayToday
|
12
12
|
include Base
|
13
13
|
|
14
|
+
BIRTHDAY_PARAMS = ["Complete Name", "BD_this_year"].freeze
|
15
|
+
|
14
16
|
# Implements the logic for shaping the results from a fetcher response.
|
15
17
|
#
|
16
18
|
# <br>
|
@@ -27,7 +29,7 @@ module Mapper
|
|
27
29
|
normalized_notion_data = normalize_response(notion_response.results)
|
28
30
|
|
29
31
|
normalized_notion_data.map do |birthday|
|
30
|
-
Domain::Birthday.new(birthday["
|
32
|
+
Domain::Birthday.new(birthday["Complete Name"], birthday["BD_this_year"])
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
@@ -36,32 +38,22 @@ module Mapper
|
|
36
38
|
def normalize_response(results)
|
37
39
|
return [] if results.nil?
|
38
40
|
|
39
|
-
normalized_results = []
|
40
|
-
|
41
41
|
results.map do |value|
|
42
|
-
|
43
|
-
properties.delete("Name")
|
42
|
+
birthday_fields = value["properties"].slice(*BIRTHDAY_PARAMS)
|
44
43
|
|
45
|
-
|
44
|
+
birthday_fields.each do |field, birthday_value|
|
45
|
+
birthday_fields[field] = extract_birthday_value(field, birthday_value)
|
46
|
+
end
|
46
47
|
|
47
|
-
|
48
|
+
birthday_fields
|
48
49
|
end
|
49
|
-
|
50
|
-
normalized_results
|
51
50
|
end
|
52
51
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
if k == "Complete Name"
|
58
|
-
normalized_value["name"] = extract_rich_text_field_value(v)
|
59
|
-
elsif k == "BD_this_year"
|
60
|
-
normalized_value["birth_date"] = extract_date_field_value(v)
|
61
|
-
end
|
52
|
+
def extract_birthday_value(field, value)
|
53
|
+
case field
|
54
|
+
when "Complete Name" then extract_rich_text_field_value(value)
|
55
|
+
when "BD_this_year" then extract_date_field_value(value)
|
62
56
|
end
|
63
|
-
|
64
|
-
normalized_value
|
65
57
|
end
|
66
58
|
|
67
59
|
def extract_rich_text_field_value(data)
|
@@ -9,9 +9,11 @@ module Mapper
|
|
9
9
|
# This class implementats the methods of the Mapper::Base module, specifically designed for preparing or
|
10
10
|
# shaping PTO's data coming from a Fetcher::Base implementation.
|
11
11
|
#
|
12
|
-
class
|
12
|
+
class PtoToday
|
13
13
|
include Base
|
14
14
|
|
15
|
+
PTO_PARAMS = ["Person", "Desde?", "Hasta?"].freeze
|
16
|
+
|
15
17
|
# Implements the logic for shaping the results from a fetcher response.
|
16
18
|
#
|
17
19
|
# <br>
|
@@ -26,8 +28,9 @@ module Mapper
|
|
26
28
|
return [] if notion_response.results.empty?
|
27
29
|
|
28
30
|
normalized_notion_data = normalize_response(notion_response.results)
|
31
|
+
|
29
32
|
normalized_notion_data.map do |pto|
|
30
|
-
Domain::Pto.new(pto["
|
33
|
+
Domain::Pto.new(pto["Person"], pto["Desde?"], pto["Hasta?"])
|
31
34
|
end
|
32
35
|
end
|
33
36
|
|
@@ -36,39 +39,22 @@ module Mapper
|
|
36
39
|
def normalize_response(response)
|
37
40
|
return [] if response.nil?
|
38
41
|
|
39
|
-
normalized_response = []
|
40
|
-
|
41
42
|
response.map do |value|
|
42
|
-
|
43
|
-
properties.delete("Name")
|
43
|
+
pto_fields = value["properties"].slice(*PTO_PARAMS)
|
44
44
|
|
45
|
-
|
45
|
+
pto_fields.each do |field, pto_value|
|
46
|
+
pto_fields[field] = extract_pto_value(field, pto_value)
|
47
|
+
end
|
46
48
|
|
47
|
-
|
49
|
+
pto_fields
|
48
50
|
end
|
49
|
-
|
50
|
-
normalized_response
|
51
51
|
end
|
52
52
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
normalized_value
|
61
|
-
end
|
62
|
-
|
63
|
-
def extract_pto_fields(key, value, normalized_value)
|
64
|
-
case key
|
65
|
-
when "Person"
|
66
|
-
user_name = extract_person_field_value(value)
|
67
|
-
normalized_value["name"] = user_name
|
68
|
-
when "Desde?"
|
69
|
-
normalized_value["start"] = extract_date_field_value(value)
|
70
|
-
when "Hasta?"
|
71
|
-
normalized_value["end"] = extract_date_field_value(value)
|
53
|
+
def extract_pto_value(field, value)
|
54
|
+
case field
|
55
|
+
when "Person" then extract_person_field_value(value)
|
56
|
+
when "Desde?" then extract_date_field_value(value)
|
57
|
+
when "Hasta?" then extract_date_field_value(value)
|
72
58
|
end
|
73
59
|
end
|
74
60
|
|
@@ -79,18 +65,6 @@ module Mapper
|
|
79
65
|
def extract_date_field_value(data)
|
80
66
|
data["date"]["start"]
|
81
67
|
end
|
82
|
-
|
83
|
-
def format_date(str_date)
|
84
|
-
return "" if str_date.nil?
|
85
|
-
|
86
|
-
if str_date.include?("T")
|
87
|
-
format = "%Y-%m-%d|%I:%M %p"
|
88
|
-
datetime = Time.new(str_date)
|
89
|
-
datetime.strftime(format)
|
90
|
-
else
|
91
|
-
str_date
|
92
|
-
end
|
93
|
-
end
|
94
68
|
end
|
95
69
|
end
|
96
70
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../domain/work_items_limit"
|
4
|
+
require_relative "../base"
|
5
|
+
|
6
|
+
module Mapper
|
7
|
+
module Notion
|
8
|
+
##
|
9
|
+
# This class implementats the methods of the Mapper::Base module, specifically designed
|
10
|
+
# for preparing or shaping work items data coming from a Fetcher::Base implementation.
|
11
|
+
class WorkItemsLimit
|
12
|
+
include Base
|
13
|
+
|
14
|
+
WORK_ITEM_PARAMS = ["Responsible domain"].freeze
|
15
|
+
|
16
|
+
# Implements the logic for shaping the results from a fetcher response.
|
17
|
+
#
|
18
|
+
# <br>
|
19
|
+
# <b>Params:</b>
|
20
|
+
# * <tt>Fetcher::Notion::Types::Response</tt> notion_response: Notion response object.
|
21
|
+
#
|
22
|
+
# <br>
|
23
|
+
# <b>return</b> <tt>List<Domain::WorkItem></tt> work_items_list, mapped work items to be used by a
|
24
|
+
# Formatter::Base implementation.
|
25
|
+
#
|
26
|
+
def map(notion_response)
|
27
|
+
return [] if notion_response.results.empty?
|
28
|
+
|
29
|
+
normalized_notion_data = normalize_response(notion_response.results)
|
30
|
+
|
31
|
+
domain_items_count = count_domain_items(normalized_notion_data)
|
32
|
+
|
33
|
+
domain_items_count.map do |domain, items_count|
|
34
|
+
Domain::WorkItemsLimit.new(domain, items_count)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def normalize_response(results)
|
41
|
+
return [] if results.nil?
|
42
|
+
|
43
|
+
results.map do |value|
|
44
|
+
work_item_fields = value["properties"].slice(*WORK_ITEM_PARAMS)
|
45
|
+
|
46
|
+
work_item_fields.each do |field, work_item_value|
|
47
|
+
work_item_fields[field] = extract_domain_field_value(work_item_value)
|
48
|
+
end
|
49
|
+
|
50
|
+
work_item_fields
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def extract_domain_field_value(data)
|
55
|
+
data["select"]["name"]
|
56
|
+
end
|
57
|
+
|
58
|
+
def count_domain_items(work_items_list)
|
59
|
+
domain_work_items = work_items_list.group_by { |work_item| work_item["Responsible domain"] }
|
60
|
+
|
61
|
+
domain_work_items.transform_values(&:count)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../domain/pto"
|
4
|
+
require_relative "../base"
|
5
|
+
|
6
|
+
module Mapper
|
7
|
+
module Postgres
|
8
|
+
##
|
9
|
+
# This class implementats the methods of the Mapper::Base module, specifically designed for preparing or
|
10
|
+
# shaping PTO's data coming from the Fetcher::Postgres::Pto class.
|
11
|
+
#
|
12
|
+
class PtoToday
|
13
|
+
# Implements the logic for shaping the results from a fetcher response.
|
14
|
+
#
|
15
|
+
# <br>
|
16
|
+
# <b>Params:</b>
|
17
|
+
# * <tt>Fetcher::Postgres::Types::Response</tt> pg_response: Postgres response object.
|
18
|
+
#
|
19
|
+
# <br>
|
20
|
+
# <b>returns</b> <tt>List<Domain::Pto></tt> ptos_list, mapped PTO's to be used by a Formatter::Base
|
21
|
+
# implementation.
|
22
|
+
#
|
23
|
+
def map(pg_response)
|
24
|
+
return [] if pg_response.records.empty?
|
25
|
+
|
26
|
+
ptos = build_map(pg_response)
|
27
|
+
|
28
|
+
ptos.map do |pto|
|
29
|
+
name = pto["name"]
|
30
|
+
start_date = pto["start_date"]
|
31
|
+
end_date = pto["end_date"]
|
32
|
+
|
33
|
+
Domain::Pto.new(name, start_date, end_date)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def build_map(pg_response)
|
40
|
+
fields = pg_response.fields
|
41
|
+
values = pg_response.records
|
42
|
+
|
43
|
+
values.map { |value| Hash[fields.zip(value)] }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -1,14 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require_relative "../
|
5
|
-
require_relative "../
|
3
|
+
# fetcher
|
4
|
+
require_relative "../fetcher/notion/use_case/birthday_today"
|
5
|
+
require_relative "../fetcher/notion/use_case/birthday_next_week"
|
6
|
+
require_relative "../fetcher/notion/use_case/pto_today"
|
7
|
+
require_relative "../fetcher/notion/use_case/pto_next_week"
|
8
|
+
require_relative "../fetcher/notion/use_case/work_items_limit"
|
9
|
+
require_relative "../fetcher/postgres/use_case/pto_today"
|
10
|
+
require_relative "../fetcher/imap/use_case/support_emails"
|
6
11
|
|
7
|
-
|
8
|
-
require_relative "../mapper/notion/
|
9
|
-
require_relative "../
|
12
|
+
# mapper
|
13
|
+
require_relative "../mapper/notion/birthday_today"
|
14
|
+
require_relative "../mapper/notion/pto_today"
|
15
|
+
require_relative "../mapper/notion/work_items_limit"
|
16
|
+
require_relative "../mapper/postgres/pto_today"
|
17
|
+
require_relative "../mapper/imap/support_emails"
|
10
18
|
|
19
|
+
# formatter
|
20
|
+
require_relative "../formatter/birthday"
|
21
|
+
require_relative "../formatter/pto"
|
22
|
+
require_relative "../formatter/work_items_limit"
|
23
|
+
require_relative "../formatter/support_emails"
|
24
|
+
|
25
|
+
# dispatcher
|
11
26
|
require_relative "../dispatcher/discord/implementation"
|
27
|
+
require_relative "../dispatcher/slack/implementation"
|
28
|
+
|
12
29
|
require_relative "use_case"
|
13
30
|
require_relative "./types/config"
|
14
31
|
|
@@ -21,33 +38,70 @@ module UseCases
|
|
21
38
|
#
|
22
39
|
# <b>Example</b>
|
23
40
|
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
# "date": {
|
29
|
-
# "equals": today
|
30
|
-
# }
|
31
|
-
# }
|
32
|
-
# ]
|
41
|
+
# options = {
|
42
|
+
# fetch_options: {
|
43
|
+
# database_id: NOTION_DATABASE_ID,
|
44
|
+
# secret: NOTION_API_INTEGRATION_SECRET,
|
33
45
|
# },
|
34
|
-
#
|
46
|
+
# dispatch_options: {
|
47
|
+
# webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
|
48
|
+
# name: "Birthday Bot"
|
49
|
+
# }
|
35
50
|
# }
|
36
51
|
#
|
52
|
+
# use_case = UseCases.notify_birthday_from_notion_to_discord(options)
|
53
|
+
# use_case.perform
|
54
|
+
#
|
55
|
+
# #################################################################################
|
56
|
+
#
|
57
|
+
# Requirements:
|
58
|
+
# * Notion database ID, from a database with the following structure:
|
59
|
+
#
|
60
|
+
# _________________________________________________________________________________
|
61
|
+
# | Complete Name (text) | BD_this_year (formula) | BD (date) |
|
62
|
+
# | -------------------- | --------------------------- | ------------------------ |
|
63
|
+
# | John Doe | January 24, 2024 | January 24, 2000 |
|
64
|
+
# | Jane Doe | June 20, 2024 | June 20, 2000 |
|
65
|
+
# ---------------------------------------------------------------------------------
|
66
|
+
# With the following formula for the BD_this_year column:
|
67
|
+
# dateAdd(prop("BD"), year(now()) - year(prop("BD")), "years")
|
68
|
+
#
|
69
|
+
# * A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
|
70
|
+
# browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
|
71
|
+
# integration** buttons.
|
72
|
+
# * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
|
73
|
+
# https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
|
74
|
+
#
|
75
|
+
def self.notify_birthday_from_notion_to_discord(options)
|
76
|
+
fetcher = Fetcher::Notion::BirthdayToday.new(options[:fetch_options])
|
77
|
+
mapper = Mapper::Notion::BirthdayToday.new
|
78
|
+
formatter = Formatter::Birthday.new(options[:format_options])
|
79
|
+
dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
|
80
|
+
use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
|
81
|
+
|
82
|
+
UseCases::UseCase.new(use_case_config)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Provides an instance of the next week Birthdays notifications from Notion to Discord use case implementation.
|
86
|
+
#
|
87
|
+
# <b>Example</b>
|
88
|
+
#
|
37
89
|
# options = {
|
38
90
|
# fetch_options: {
|
39
|
-
# base_url: "https://api.notion.com",
|
40
91
|
# database_id: NOTION_DATABASE_ID,
|
41
92
|
# secret: NOTION_API_INTEGRATION_SECRET,
|
42
|
-
# filter: filter
|
43
93
|
# },
|
44
94
|
# dispatch_options: {
|
45
95
|
# webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
|
46
96
|
# name: "Birthday Bot"
|
97
|
+
# },
|
98
|
+
# format_options: {
|
99
|
+
# template: "individual_name, Wishing you a very happy birthday! Enjoy your special day! :birthday: :gift:",
|
100
|
+
# timezone: "-05:00"
|
47
101
|
# }
|
48
102
|
# }
|
49
103
|
#
|
50
|
-
# use_case = UseCases.
|
104
|
+
# use_case = UseCases.notify_next_week_birthday_from_notion_to_discord(options)
|
51
105
|
# use_case.perform
|
52
106
|
#
|
53
107
|
# #################################################################################
|
@@ -70,10 +124,10 @@ module UseCases
|
|
70
124
|
# * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
|
71
125
|
# https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
|
72
126
|
#
|
73
|
-
def self.
|
74
|
-
fetcher = Fetcher::Notion::
|
75
|
-
mapper = Mapper::Notion::
|
76
|
-
formatter = Formatter::
|
127
|
+
def self.notify_next_week_birthday_from_notion_to_discord(options)
|
128
|
+
fetcher = Fetcher::Notion::BirthdayNextWeek.new(options[:fetch_options])
|
129
|
+
mapper = Mapper::Notion::BirthdayToday.new
|
130
|
+
formatter = Formatter::Birthday.new(options[:format_options])
|
77
131
|
dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
|
78
132
|
use_case_cofig = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
|
79
133
|
|
@@ -85,31 +139,10 @@ module UseCases
|
|
85
139
|
# <br>
|
86
140
|
# <b>Example</b>
|
87
141
|
#
|
88
|
-
# "filter": {
|
89
|
-
# "and": [
|
90
|
-
# {
|
91
|
-
# property: "Desde?",
|
92
|
-
# date: {
|
93
|
-
# "on_or_before": today
|
94
|
-
# }
|
95
|
-
# },
|
96
|
-
# {s
|
97
|
-
# property: "Hasta?",
|
98
|
-
# date: {
|
99
|
-
# "on_or_after": today
|
100
|
-
# }
|
101
|
-
# }
|
102
|
-
# ]
|
103
|
-
# },
|
104
|
-
# "sorts": []
|
105
|
-
# }
|
106
|
-
#
|
107
142
|
# options = {
|
108
143
|
# fetch_options: {
|
109
|
-
# base_url: "https://api.notion.com",
|
110
144
|
# database_id: NOTION_DATABASE_ID,
|
111
145
|
# secret: NOTION_API_INTEGRATION_SECRET,
|
112
|
-
# filter: filter
|
113
146
|
# },
|
114
147
|
# dispatch_options: {
|
115
148
|
# webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
|
@@ -139,12 +172,206 @@ module UseCases
|
|
139
172
|
# https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
|
140
173
|
#
|
141
174
|
def self.notify_pto_from_notion_to_discord(options)
|
142
|
-
fetcher = Fetcher::Notion::
|
143
|
-
mapper = Mapper::Notion::
|
144
|
-
formatter = Formatter::
|
175
|
+
fetcher = Fetcher::Notion::PtoToday.new(options[:fetch_options])
|
176
|
+
mapper = Mapper::Notion::PtoToday.new
|
177
|
+
formatter = Formatter::Pto.new(options[:format_options])
|
145
178
|
dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
|
146
|
-
|
179
|
+
use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
|
147
180
|
|
148
|
-
UseCases::UseCase.new(
|
181
|
+
UseCases::UseCase.new(use_case_config)
|
182
|
+
end
|
183
|
+
|
184
|
+
# Provides an instance of the next week PTO notifications from Notion to Discord use case implementation.
|
185
|
+
#
|
186
|
+
# <br>
|
187
|
+
# <b>Example</b>
|
188
|
+
#
|
189
|
+
# options = {
|
190
|
+
# fetch_options: {
|
191
|
+
# database_id: NOTION_DATABASE_ID,
|
192
|
+
# secret: NOTION_API_INTEGRATION_SECRET,
|
193
|
+
# },
|
194
|
+
# dispatch_options: {
|
195
|
+
# webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
|
196
|
+
# name: "Pto Bot"
|
197
|
+
# },
|
198
|
+
# format_options: {
|
199
|
+
# template: ":beach: individual_name its going to be on PTO next week,",
|
200
|
+
# timezone: "-05:00"
|
201
|
+
# }
|
202
|
+
# }
|
203
|
+
#
|
204
|
+
# use_case = UseCases.notify_next_week_pto_from_notion_to_discord(options)
|
205
|
+
# use_case.perform
|
206
|
+
#
|
207
|
+
# #################################################################################
|
208
|
+
#
|
209
|
+
# Requirements:
|
210
|
+
# * Notion database ID, from a database with the following structure:
|
211
|
+
#
|
212
|
+
# ________________________________________________________________________________________________________
|
213
|
+
# | Person (person) | Desde? (date) | Hasta? (date) |
|
214
|
+
# | -------------------- | --------------------------------------- | ------------------------------------ |
|
215
|
+
# | John Doe | January 24, 2024 | January 27, 2024 |
|
216
|
+
# | Jane Doe | November 11, 2024 2:00 PM | November 11, 2024 6:00 PM |
|
217
|
+
# ---------------------------------------------------------------------------------------------------------
|
218
|
+
#
|
219
|
+
# * A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
|
220
|
+
# browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
|
221
|
+
# integration** buttons.
|
222
|
+
# * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
|
223
|
+
# https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
|
224
|
+
#
|
225
|
+
def self.notify_next_week_pto_from_notion_to_discord(options)
|
226
|
+
fetcher = Fetcher::Notion::PtoNextWeek.new(options[:fetch_options])
|
227
|
+
mapper = Mapper::Notion::PtoToday.new
|
228
|
+
formatter = Formatter::Pto.new(options[:format_options])
|
229
|
+
dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
|
230
|
+
use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
|
231
|
+
|
232
|
+
UseCases::UseCase.new(use_case_config)
|
233
|
+
end
|
234
|
+
|
235
|
+
# Provides an instance of the PTO notifications from Postgres to Slack use case implementation.
|
236
|
+
#
|
237
|
+
# <br>
|
238
|
+
# <b>Example</b>
|
239
|
+
#
|
240
|
+
# options = {
|
241
|
+
# fetch_options: {
|
242
|
+
# connection: {
|
243
|
+
# host: "localhost",
|
244
|
+
# port: 5432,
|
245
|
+
# dbname: "db_pto",
|
246
|
+
# user: "postgres",
|
247
|
+
# password: "postgres"
|
248
|
+
# }
|
249
|
+
# },
|
250
|
+
# dispatch_options:{
|
251
|
+
# webhook: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
|
252
|
+
# name: "Pto Bot"
|
253
|
+
# },
|
254
|
+
# format_options: {
|
255
|
+
# template: "Custom template",
|
256
|
+
# timezone: "-05:00"
|
257
|
+
# }
|
258
|
+
# }
|
259
|
+
#
|
260
|
+
# use_case = UseCases.notify_pto_from_postgres_to_slack(options)
|
261
|
+
# use_case.perform
|
262
|
+
#
|
263
|
+
# #################################################################################
|
264
|
+
#
|
265
|
+
# Requirements:
|
266
|
+
# * A connection to a Postgres database and a table with the following structure:
|
267
|
+
#
|
268
|
+
# Column | Type | Collation | Nullable | Default
|
269
|
+
# -----------------+------------------------+-----------+----------+------------------------------
|
270
|
+
# id | integer | | not null | generated always as identity
|
271
|
+
# create_time | date | | |
|
272
|
+
# individual_name | character varying(255) | | |
|
273
|
+
# start_date | date | | |
|
274
|
+
# end_date | date | | |
|
275
|
+
#
|
276
|
+
# * A webhook key, which can be generated directly on slack on the desired channel, following this instructions:
|
277
|
+
# https://api.slack.com/messaging/webhooks#create_a_webhook
|
278
|
+
#
|
279
|
+
def self.notify_pto_from_postgres_to_slack(options)
|
280
|
+
fetcher = Fetcher::Postgres::PtoToday.new(options[:fetch_options])
|
281
|
+
mapper = Mapper::Postgres::PtoToday.new
|
282
|
+
formatter = Formatter::Pto.new(options[:format_options])
|
283
|
+
dispatcher = Dispatcher::Slack::Implementation.new(options[:dispatch_options])
|
284
|
+
use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
|
285
|
+
|
286
|
+
UseCases::UseCase.new(use_case_config)
|
287
|
+
end
|
288
|
+
|
289
|
+
# Provides an instance of the Work Items wip limit notifications from Notion to Discord use case implementation.
|
290
|
+
#
|
291
|
+
# <br>
|
292
|
+
# <b>Example</b>
|
293
|
+
#
|
294
|
+
# options = {
|
295
|
+
# fetch_options: {
|
296
|
+
# database_id: NOTION_DATABASE_ID,
|
297
|
+
# secret: NOTION_API_INTEGRATION_SECRET
|
298
|
+
# },
|
299
|
+
# dispatch_options: {
|
300
|
+
# webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
|
301
|
+
# name: "wipLimit"
|
302
|
+
# }
|
303
|
+
# }
|
304
|
+
#
|
305
|
+
# use_case = UseCases.notify_wip_limit_from_notion_to_discord(options)
|
306
|
+
# use_case.perform
|
307
|
+
#
|
308
|
+
# #################################################################################
|
309
|
+
#
|
310
|
+
# Requirements:
|
311
|
+
# * Notion database ID, from a database with the following structure:
|
312
|
+
#
|
313
|
+
# _________________________________________________________________________________
|
314
|
+
# | OK | Status | Responsible Domain |
|
315
|
+
# | -------------------- | --------------------------- | ------------------------ |
|
316
|
+
# | ✅ | In Progress | "kommit.admin" |
|
317
|
+
# | 🚩 | Fail | "kommit.ops" |
|
318
|
+
# ---------------------------------------------------------------------------------
|
319
|
+
#
|
320
|
+
# * A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
|
321
|
+
# browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
|
322
|
+
# integration** buttons.
|
323
|
+
# * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
|
324
|
+
# https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
|
325
|
+
#
|
326
|
+
def self.notify_wip_limit_from_notion_to_discord(options)
|
327
|
+
fetcher = Fetcher::Notion::WorkItemsLimit.new(options[:fetch_options])
|
328
|
+
mapper = Mapper::Notion::WorkItemsLimit.new
|
329
|
+
formatter = Formatter::WorkItemsLimit.new(options[:format_options])
|
330
|
+
dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
|
331
|
+
use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
|
332
|
+
|
333
|
+
UseCases::UseCase.new(use_case_config)
|
334
|
+
end
|
335
|
+
|
336
|
+
# Provides an instance of the support emails from an google IMAP server to Discord use case implementation.
|
337
|
+
#
|
338
|
+
# <br>
|
339
|
+
# <b>Example</b>
|
340
|
+
#
|
341
|
+
# options = {
|
342
|
+
# fetch_options: {
|
343
|
+
# user: 'info@email.co',
|
344
|
+
# refresh_token: REFRESH_TOKEN,
|
345
|
+
# client_id: CLIENT_ID,
|
346
|
+
# client_secret: CLIENT_SECRET,
|
347
|
+
# inbox: 'INBOX',
|
348
|
+
# search_email: 'support@email.co'
|
349
|
+
# },
|
350
|
+
# dispatch_options: {
|
351
|
+
# webhook: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
|
352
|
+
# name: "emailSupport"
|
353
|
+
# }
|
354
|
+
# }
|
355
|
+
#
|
356
|
+
# use_case = UseCases.notify_support_email_from_imap_to_discord(options)
|
357
|
+
# use_case.perform
|
358
|
+
#
|
359
|
+
# #################################################################################
|
360
|
+
#
|
361
|
+
# Requirements:
|
362
|
+
# * A google gmail account with IMAP support activated.
|
363
|
+
# * A set of authorization parameters like a client_id, client_secret, and a resfresh_token. To
|
364
|
+
# generate them, follow this instructions: https://developers.google.com/identity/protocols/oauth2
|
365
|
+
# * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
|
366
|
+
# https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
|
367
|
+
#
|
368
|
+
def self.notify_support_email_from_imap_to_discord(options)
|
369
|
+
fetcher = Fetcher::Imap::SupportEmails.new(options[:fetch_options])
|
370
|
+
mapper = Mapper::Imap::SupportEmails.new
|
371
|
+
formatter = Formatter::SupportEmails.new(options[:format_options])
|
372
|
+
dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
|
373
|
+
use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
|
374
|
+
|
375
|
+
UseCases::UseCase.new(use_case_config)
|
149
376
|
end
|
150
377
|
end
|
data/lib/bns/version.rb
CHANGED