bns 0.1.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kommitters Open Source
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A versatile business notification system offering key components for
|
14
14
|
building various use cases. It provides an easy-to-use tool for implementing
|
@@ -19,6 +19,7 @@ executables: []
|
|
19
19
|
extensions: []
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
|
+
- "._.rspec_status"
|
22
23
|
- ".rspec"
|
23
24
|
- ".rubocop.yml"
|
24
25
|
- CHANGELOG.md
|
@@ -34,23 +35,44 @@ files:
|
|
34
35
|
- lib/bns/dispatcher/discord/exceptions/invalid_webhook_token.rb
|
35
36
|
- lib/bns/dispatcher/discord/implementation.rb
|
36
37
|
- lib/bns/dispatcher/discord/types/response.rb
|
38
|
+
- lib/bns/dispatcher/slack/exceptions/invalid_webhook_token.rb
|
39
|
+
- lib/bns/dispatcher/slack/implementation.rb
|
40
|
+
- lib/bns/dispatcher/slack/types/response.rb
|
37
41
|
- lib/bns/domain/birthday.rb
|
42
|
+
- lib/bns/domain/email.rb
|
38
43
|
- lib/bns/domain/exceptions/function_not_implemented.rb
|
39
44
|
- lib/bns/domain/pto.rb
|
45
|
+
- lib/bns/domain/work_items_limit.rb
|
40
46
|
- lib/bns/fetcher/base.rb
|
41
|
-
- lib/bns/fetcher/
|
47
|
+
- lib/bns/fetcher/imap/base.rb
|
48
|
+
- lib/bns/fetcher/imap/types/response.rb
|
49
|
+
- lib/bns/fetcher/imap/use_case/support_emails.rb
|
50
|
+
- lib/bns/fetcher/notion/base.rb
|
42
51
|
- lib/bns/fetcher/notion/exceptions/invalid_api_key.rb
|
43
52
|
- lib/bns/fetcher/notion/exceptions/invalid_database_id.rb
|
44
53
|
- lib/bns/fetcher/notion/helper.rb
|
45
|
-
- lib/bns/fetcher/notion/pto.rb
|
46
54
|
- lib/bns/fetcher/notion/types/response.rb
|
55
|
+
- lib/bns/fetcher/notion/use_case/birthday_next_week.rb
|
56
|
+
- lib/bns/fetcher/notion/use_case/birthday_today.rb
|
57
|
+
- lib/bns/fetcher/notion/use_case/pto_next_week.rb
|
58
|
+
- lib/bns/fetcher/notion/use_case/pto_today.rb
|
59
|
+
- lib/bns/fetcher/notion/use_case/work_items_limit.rb
|
60
|
+
- lib/bns/fetcher/postgres/base.rb
|
61
|
+
- lib/bns/fetcher/postgres/helper.rb
|
62
|
+
- lib/bns/fetcher/postgres/types/response.rb
|
63
|
+
- lib/bns/fetcher/postgres/use_case/pto_today.rb
|
47
64
|
- lib/bns/formatter/base.rb
|
48
|
-
- lib/bns/formatter/
|
49
|
-
- lib/bns/formatter/
|
50
|
-
- lib/bns/formatter/
|
65
|
+
- lib/bns/formatter/birthday.rb
|
66
|
+
- lib/bns/formatter/exceptions/invalid_data.rb
|
67
|
+
- lib/bns/formatter/pto.rb
|
68
|
+
- lib/bns/formatter/support_emails.rb
|
69
|
+
- lib/bns/formatter/work_items_limit.rb
|
51
70
|
- lib/bns/mapper/base.rb
|
52
|
-
- lib/bns/mapper/
|
53
|
-
- lib/bns/mapper/notion/
|
71
|
+
- lib/bns/mapper/imap/support_emails.rb
|
72
|
+
- lib/bns/mapper/notion/birthday_today.rb
|
73
|
+
- lib/bns/mapper/notion/pto_today.rb
|
74
|
+
- lib/bns/mapper/notion/work_items_limit.rb
|
75
|
+
- lib/bns/mapper/postgres/pto_today.rb
|
54
76
|
- lib/bns/use_cases/types/config.rb
|
55
77
|
- lib/bns/use_cases/use_case.rb
|
56
78
|
- lib/bns/use_cases/use_cases.rb
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "httparty"
|
4
|
-
require "date"
|
5
|
-
|
6
|
-
require_relative "../base"
|
7
|
-
require_relative "./exceptions/invalid_api_key"
|
8
|
-
require_relative "./exceptions/invalid_database_id"
|
9
|
-
require_relative "./types/response"
|
10
|
-
require_relative "./helper"
|
11
|
-
|
12
|
-
module Fetcher
|
13
|
-
module Notion
|
14
|
-
##
|
15
|
-
# This class is an implementation of the Fetcher::Base interface, specifically designed
|
16
|
-
# for fetching birthday data from Notion.
|
17
|
-
#
|
18
|
-
class Birthday < Base
|
19
|
-
# Implements the data fetching logic for Birthdays data from Notion. It sends a POST
|
20
|
-
# request to the Notion API to query the specified database and returns a validated response.
|
21
|
-
#
|
22
|
-
# <br>
|
23
|
-
# <b>raises</b> <tt>Exceptions::Notion::InvalidApiKey</tt> if the API key provided is incorrect or invalid.
|
24
|
-
#
|
25
|
-
# <b>raises</b> <tt>Exceptions::Notion::InvalidDatabaseId</tt> if the Database id provided is incorrect
|
26
|
-
# or invalid.
|
27
|
-
#
|
28
|
-
def fetch
|
29
|
-
url = build_url(config[:base_url], config[:database_id])
|
30
|
-
|
31
|
-
httparty_response = HTTParty.post(url, { body: config[:filter].to_json, headers: headers })
|
32
|
-
|
33
|
-
notion_response = Fetcher::Notion::Types::Response.new(httparty_response)
|
34
|
-
|
35
|
-
Fetcher::Notion::Helper.validate_response(notion_response)
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def headers
|
41
|
-
{
|
42
|
-
"Authorization" => "Bearer #{config[:secret]}",
|
43
|
-
"Content-Type" => "application/json",
|
44
|
-
"Notion-Version" => "2022-06-28"
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
|
-
def build_url(base, database_id)
|
49
|
-
"#{base}/v1/databases/#{database_id}/query"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../../domain/birthday"
|
4
|
-
require_relative "../base"
|
5
|
-
require_relative "./exceptions/invalid_data"
|
6
|
-
|
7
|
-
module Formatter
|
8
|
-
module Discord
|
9
|
-
##
|
10
|
-
# This class implementats the methods of the Formatter::Base module, specifically designed for formatting birthday
|
11
|
-
# data in a way suitable for Discord messages.
|
12
|
-
class Birthday < Base
|
13
|
-
# Implements the logic for building a formatted payload with the given template for birthdays.
|
14
|
-
#
|
15
|
-
# <br>
|
16
|
-
# <b>Params:</b>
|
17
|
-
# * <tt>List<Domain::Birthday></tt> birthdays_list: list of mapped birthdays.
|
18
|
-
#
|
19
|
-
# <br>
|
20
|
-
# <b>raises</b> <tt>Formatter::Discord::Exceptions::InvalidData</tt> when invalid data is provided.
|
21
|
-
#
|
22
|
-
# <br>
|
23
|
-
# <b>returns</b> <tt>String</tt> payload: formatted payload suitable for a Discord message.
|
24
|
-
#
|
25
|
-
def format(birthdays_list)
|
26
|
-
raise Formatter::Discord::Exceptions::InvalidData unless birthdays_list.all? do |brithday|
|
27
|
-
brithday.is_a?(Domain::Birthday)
|
28
|
-
end
|
29
|
-
|
30
|
-
birthdays_list.reduce("") do |payload, birthday|
|
31
|
-
payload + build_template(Domain::Birthday::ATTRIBUTES, birthday)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Formatter
|
4
|
-
module Discord
|
5
|
-
module Exceptions
|
6
|
-
##
|
7
|
-
# Provides a domain-specific representation for errors that occurs when trying to process invalid
|
8
|
-
# data on a Fetcher::Base implementation
|
9
|
-
#
|
10
|
-
class InvalidData < StandardError
|
11
|
-
def initialize(message = "")
|
12
|
-
super(message)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../../domain/pto"
|
4
|
-
require_relative "../base"
|
5
|
-
|
6
|
-
module Formatter
|
7
|
-
module Discord
|
8
|
-
##
|
9
|
-
# This class is an implementation of the Formatter::Base interface, specifically designed for formatting PTO
|
10
|
-
# data in a way suitable for Discord messages.
|
11
|
-
class Pto < Base
|
12
|
-
# Implements the logic for building a formatted payload with the given template for PTO's.
|
13
|
-
#
|
14
|
-
# <br>
|
15
|
-
# <b>Params:</b>
|
16
|
-
# * <tt>List<Domain::Pto></tt> pto_list: List of mapped PTO's.
|
17
|
-
#
|
18
|
-
# <br>
|
19
|
-
# <b>raises</b> <tt>Formatter::Discord::Exceptions::InvalidData</tt> when invalid data is provided.
|
20
|
-
#
|
21
|
-
# <br>
|
22
|
-
# <b>returns</b> <tt>String</tt> payload, formatted payload suitable for a Discord message.
|
23
|
-
#
|
24
|
-
|
25
|
-
def format(ptos_list)
|
26
|
-
raise Formatter::Discord::Exceptions::InvalidData unless ptos_list.all? { |pto| pto.is_a?(Domain::Pto) }
|
27
|
-
|
28
|
-
ptos_list.reduce("") do |payload, pto|
|
29
|
-
built_template = build_template(Domain::Pto::ATTRIBUTES, pto)
|
30
|
-
payload + format_message_by_case(built_template.gsub("\n", ""), pto)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def format_message_by_case(built_template, pto)
|
37
|
-
if pto.start_date.include?("|")
|
38
|
-
start_time = pto.start_date.split("|")
|
39
|
-
end_time = pto.end_date.split("|")
|
40
|
-
"#{built_template} #{start_time[1]} - #{end_time[1]}\n"
|
41
|
-
elsif pto.start_date == pto.end_date
|
42
|
-
"#{built_template} all day\n"
|
43
|
-
else
|
44
|
-
"#{built_template} #{pto.start_date} - #{pto.end_date}\n"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|