bns 0.1.0 → 0.1.1
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/CHANGELOG.md +4 -0
- data/README.md +4 -1
- data/SECURITY.md +13 -0
- data/lib/bns/domain/birthday.rb +2 -0
- data/lib/bns/domain/pto.rb +2 -0
- data/lib/bns/formatter/base.rb +22 -1
- data/lib/bns/formatter/discord/birthday.rb +3 -10
- data/lib/bns/formatter/discord/pto.rb +10 -13
- data/lib/bns/use_cases/use_cases.rb +2 -2
- data/lib/bns/version.rb +1 -1
- data/renovate.json +6 -0
- metadata +4 -3
- data/Gemfile.lock +0 -91
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '088295440471344d853d850bf071e7fb885fa824a49bfcd182fe5d6a6de03b6c'
|
4
|
+
data.tar.gz: 909cec977526aaf735599e1b6dcbf8a0144eeb0dc8f02a37e371a4f90fb62405
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 473e834fb819c4f8b36a053643b883b2cf5704c89aa470f9a58c063e148fbdfa7c8f78ac745b85f9ef193066f4e00e4b084f2add8385a58f892759297a23fa1f
|
7
|
+
data.tar.gz: bc15074b2628619f25786b8da2edcd5a0ec20eb5154df50027450886bc7e2f3c6cceba8897081ef78d0ac9770d19c2ca349ff799c64842bdef8ef4736a6b6fe6
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.1.1 (07.02.2024)
|
4
|
+
- [Add custom templates option](https://github.com/kommitters/bns/issues/25)
|
5
|
+
- [PTO's formatting use cases](https://github.com/kommitters/bns/issues/24)
|
6
|
+
|
3
7
|
## 0.1.0 (06.02.2024)
|
4
8
|
|
5
9
|
- [Build initial codebase](https://github.com/kommitters/bns/issues/6)
|
data/README.md
CHANGED
@@ -2,10 +2,13 @@
|
|
2
2
|
|
3
3
|
The business notification system is designed to be a versatile platform, offering key components for building various use cases. It provides an easy-to-use tool for implementing notifications without excessive complexity.
|
4
4
|
|
5
|
+

|
6
|
+

|
5
7
|

|
6
8
|
[](https://coveralls.io/github/kommitters/bns?branch=main)
|
7
|
-
[](https://api.securityscorecards.dev/projects/github.com/kommitters/bns)
|
8
9
|

|
10
|
+
[](https://api.securityscorecards.dev/projects/github.com/kommitters/bns)
|
11
|
+
[](https://bestpractices.coreinfrastructure.org/projects/8383)
|
9
12
|
|
10
13
|
## Installation
|
11
14
|
|
data/SECURITY.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Security Policy
|
2
|
+
|
3
|
+
## Reporting Security Issues
|
4
|
+
|
5
|
+
To report a security issue, you can either:
|
6
|
+
- Privately report a vulnerability through repository's Security tab by clicking "Report a vulnerability".
|
7
|
+
- Email us at [oss@kommit.co](mailto:oss@kommit.co).
|
8
|
+
|
9
|
+
Please, make sure to provide a description of the issue, the steps you took to create the issue, affected versions, and, if known, mitigations for the issue.
|
10
|
+
|
11
|
+
## Responsible Disclosure
|
12
|
+
|
13
|
+
If the issue is confirmed as a vulnerability, we will open a Security Advisory and acknowledge your contributions as part of it.
|
data/lib/bns/domain/birthday.rb
CHANGED
data/lib/bns/domain/pto.rb
CHANGED
@@ -9,6 +9,8 @@ module Domain
|
|
9
9
|
class Pto
|
10
10
|
attr_reader :individual_name, :start_date, :end_date
|
11
11
|
|
12
|
+
ATTRIBUTES = %w[individual_name start_date end_date].freeze
|
13
|
+
|
12
14
|
# Initializes a Domain::Pto instance with the specified individual name, start date, and end date.
|
13
15
|
#
|
14
16
|
# <br>
|
data/lib/bns/formatter/base.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "../domain/exceptions/function_not_implemented"
|
4
|
+
require "erb"
|
4
5
|
|
5
6
|
module Formatter
|
6
7
|
##
|
@@ -8,7 +9,7 @@ module Formatter
|
|
8
9
|
# within the Formatter module. Defines essential methods, that provide a blueprint for creating custom
|
9
10
|
# formatters tailored to different use cases.
|
10
11
|
#
|
11
|
-
|
12
|
+
class Base
|
12
13
|
# A method meant to give an specified format depending on the implementation to the data coming from an
|
13
14
|
# implementation of the Mapper::Base interface.
|
14
15
|
# Must be overridden by subclasses, with specific logic based on the use case.
|
@@ -22,8 +23,28 @@ module Formatter
|
|
22
23
|
#
|
23
24
|
# <b>returns</b> <tt>String</tt> Formatted payload suitable for a Dispatcher::Base implementation.
|
24
25
|
#
|
26
|
+
attr_reader :template
|
27
|
+
|
28
|
+
def initialize(config = {})
|
29
|
+
@template = config[:template]
|
30
|
+
end
|
31
|
+
|
25
32
|
def format(_domain_data)
|
26
33
|
raise Domain::Exceptions::FunctionNotImplemented
|
27
34
|
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
def build_template(attributes, instance)
|
39
|
+
formated_template = format_template(attributes, instance)
|
40
|
+
|
41
|
+
"#{ERB.new(formated_template).result(binding)}\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
def format_template(attributes, _instance)
|
45
|
+
attributes.reduce(template) do |formated_template, attribute|
|
46
|
+
formated_template.gsub(attribute, "<%= instance.#{attribute} %>")
|
47
|
+
end
|
48
|
+
end
|
28
49
|
end
|
29
50
|
end
|
@@ -9,9 +9,7 @@ module Formatter
|
|
9
9
|
##
|
10
10
|
# This class implementats the methods of the Formatter::Base module, specifically designed for formatting birthday
|
11
11
|
# data in a way suitable for Discord messages.
|
12
|
-
class Birthday
|
13
|
-
include Base
|
14
|
-
|
12
|
+
class Birthday < Base
|
15
13
|
# Implements the logic for building a formatted payload with the given template for birthdays.
|
16
14
|
#
|
17
15
|
# <br>
|
@@ -29,14 +27,9 @@ module Formatter
|
|
29
27
|
brithday.is_a?(Domain::Birthday)
|
30
28
|
end
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
birthdays_list.each do |birthday|
|
36
|
-
payload += "#{template.gsub("NAME", birthday.individual_name)}\n"
|
30
|
+
birthdays_list.reduce("") do |payload, birthday|
|
31
|
+
payload + build_template(Domain::Birthday::ATTRIBUTES, birthday)
|
37
32
|
end
|
38
|
-
|
39
|
-
payload
|
40
33
|
end
|
41
34
|
end
|
42
35
|
end
|
@@ -8,9 +8,7 @@ module Formatter
|
|
8
8
|
##
|
9
9
|
# This class is an implementation of the Formatter::Base interface, specifically designed for formatting PTO
|
10
10
|
# data in a way suitable for Discord messages.
|
11
|
-
class Pto
|
12
|
-
include Base
|
13
|
-
|
11
|
+
class Pto < Base
|
14
12
|
# Implements the logic for building a formatted payload with the given template for PTO's.
|
15
13
|
#
|
16
14
|
# <br>
|
@@ -23,28 +21,27 @@ module Formatter
|
|
23
21
|
# <br>
|
24
22
|
# <b>returns</b> <tt>String</tt> payload, formatted payload suitable for a Discord message.
|
25
23
|
#
|
24
|
+
|
26
25
|
def format(ptos_list)
|
27
26
|
raise Formatter::Discord::Exceptions::InvalidData unless ptos_list.all? { |pto| pto.is_a?(Domain::Pto) }
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
ptos_list.each do |pto|
|
33
|
-
payload += "#{template.gsub("NAME", pto.individual_name)} #{build_pto_message(pto)}\n"
|
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)
|
34
31
|
end
|
35
|
-
|
36
|
-
payload
|
37
32
|
end
|
38
33
|
|
39
34
|
private
|
40
35
|
|
41
|
-
def
|
36
|
+
def format_message_by_case(built_template, pto)
|
42
37
|
if pto.start_date.include?("|")
|
43
38
|
start_time = pto.start_date.split("|")
|
44
39
|
end_time = pto.end_date.split("|")
|
45
|
-
"#{start_time[1]} - #{end_time[1]}"
|
40
|
+
"#{built_template} #{start_time[1]} - #{end_time[1]}\n"
|
41
|
+
elsif pto.start_date == pto.end_date
|
42
|
+
"#{built_template} all day\n"
|
46
43
|
else
|
47
|
-
"
|
44
|
+
"#{built_template} #{pto.start_date} - #{pto.end_date}\n"
|
48
45
|
end
|
49
46
|
end
|
50
47
|
end
|
@@ -73,7 +73,7 @@ module UseCases
|
|
73
73
|
def self.notify_birthday_from_notion_to_discord(options)
|
74
74
|
fetcher = Fetcher::Notion::Birthday.new(options[:fetch_options])
|
75
75
|
mapper = Mapper::Notion::Birthday.new
|
76
|
-
formatter = Formatter::Discord::Birthday.new
|
76
|
+
formatter = Formatter::Discord::Birthday.new(options[:format_options])
|
77
77
|
dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
|
78
78
|
use_case_cofig = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
|
79
79
|
|
@@ -141,7 +141,7 @@ module UseCases
|
|
141
141
|
def self.notify_pto_from_notion_to_discord(options)
|
142
142
|
fetcher = Fetcher::Notion::Pto.new(options[:fetch_options])
|
143
143
|
mapper = Mapper::Notion::Pto.new
|
144
|
-
formatter = Formatter::Discord::Pto.new
|
144
|
+
formatter = Formatter::Discord::Pto.new(options[:format_options])
|
145
145
|
dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
|
146
146
|
use_case_cofig = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
|
147
147
|
|
data/lib/bns/version.rb
CHANGED
data/renovate.json
ADDED
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.1.
|
4
|
+
version: 0.1.1
|
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-02-
|
11
|
+
date: 2024-02-08 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
|
@@ -25,10 +25,10 @@ files:
|
|
25
25
|
- CODE_OF_CONDUCT.md
|
26
26
|
- CONTRIBUTING.md
|
27
27
|
- Gemfile
|
28
|
-
- Gemfile.lock
|
29
28
|
- LICENSE
|
30
29
|
- README.md
|
31
30
|
- Rakefile
|
31
|
+
- SECURITY.md
|
32
32
|
- lib/bns.rb
|
33
33
|
- lib/bns/dispatcher/base.rb
|
34
34
|
- lib/bns/dispatcher/discord/exceptions/invalid_webhook_token.rb
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- lib/bns/use_cases/use_case.rb
|
56
56
|
- lib/bns/use_cases/use_cases.rb
|
57
57
|
- lib/bns/version.rb
|
58
|
+
- renovate.json
|
58
59
|
- sig/business_notification_system.rbs
|
59
60
|
homepage: https://github.com/kommitters/bns
|
60
61
|
licenses:
|
data/Gemfile.lock
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
bns (0.1.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
addressable (2.8.6)
|
10
|
-
public_suffix (>= 2.0.2, < 6.0)
|
11
|
-
ast (2.4.2)
|
12
|
-
crack (0.4.5)
|
13
|
-
rexml
|
14
|
-
diff-lcs (1.5.0)
|
15
|
-
docile (1.4.0)
|
16
|
-
hashdiff (1.1.0)
|
17
|
-
httparty (0.21.0)
|
18
|
-
mini_mime (>= 1.0.0)
|
19
|
-
multi_xml (>= 0.5.2)
|
20
|
-
json (2.7.1)
|
21
|
-
language_server-protocol (3.17.0.3)
|
22
|
-
mini_mime (1.1.5)
|
23
|
-
multi_xml (0.6.0)
|
24
|
-
parallel (1.24.0)
|
25
|
-
parser (3.3.0.3)
|
26
|
-
ast (~> 2.4.1)
|
27
|
-
racc
|
28
|
-
public_suffix (5.0.4)
|
29
|
-
racc (1.7.3)
|
30
|
-
rainbow (3.1.1)
|
31
|
-
rake (13.1.0)
|
32
|
-
regexp_parser (2.9.0)
|
33
|
-
rexml (3.2.6)
|
34
|
-
rspec (3.12.0)
|
35
|
-
rspec-core (~> 3.12.0)
|
36
|
-
rspec-expectations (~> 3.12.0)
|
37
|
-
rspec-mocks (~> 3.12.0)
|
38
|
-
rspec-core (3.12.2)
|
39
|
-
rspec-support (~> 3.12.0)
|
40
|
-
rspec-expectations (3.12.3)
|
41
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
-
rspec-support (~> 3.12.0)
|
43
|
-
rspec-mocks (3.12.6)
|
44
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
-
rspec-support (~> 3.12.0)
|
46
|
-
rspec-support (3.12.1)
|
47
|
-
rubocop (1.59.0)
|
48
|
-
json (~> 2.3)
|
49
|
-
language_server-protocol (>= 3.17.0)
|
50
|
-
parallel (~> 1.10)
|
51
|
-
parser (>= 3.2.2.4)
|
52
|
-
rainbow (>= 2.2.2, < 4.0)
|
53
|
-
regexp_parser (>= 1.8, < 3.0)
|
54
|
-
rexml (>= 3.2.5, < 4.0)
|
55
|
-
rubocop-ast (>= 1.30.0, < 2.0)
|
56
|
-
ruby-progressbar (~> 1.7)
|
57
|
-
unicode-display_width (>= 2.4.0, < 3.0)
|
58
|
-
rubocop-ast (1.30.0)
|
59
|
-
parser (>= 3.2.1.0)
|
60
|
-
ruby-progressbar (1.13.0)
|
61
|
-
simplecov (0.22.0)
|
62
|
-
docile (~> 1.1)
|
63
|
-
simplecov-html (~> 0.11)
|
64
|
-
simplecov_json_formatter (~> 0.1)
|
65
|
-
simplecov-html (0.12.3)
|
66
|
-
simplecov-lcov (0.8.0)
|
67
|
-
simplecov_json_formatter (0.1.4)
|
68
|
-
unicode-display_width (2.5.0)
|
69
|
-
vcr (6.2.0)
|
70
|
-
webmock (3.19.1)
|
71
|
-
addressable (>= 2.8.0)
|
72
|
-
crack (>= 0.3.2)
|
73
|
-
hashdiff (>= 0.4.0, < 2.0.0)
|
74
|
-
|
75
|
-
PLATFORMS
|
76
|
-
arm64-darwin-23
|
77
|
-
x86_64-linux
|
78
|
-
|
79
|
-
DEPENDENCIES
|
80
|
-
bns!
|
81
|
-
httparty
|
82
|
-
rake (~> 13.0)
|
83
|
-
rspec (~> 3.0)
|
84
|
-
rubocop (~> 1.21)
|
85
|
-
simplecov
|
86
|
-
simplecov-lcov (~> 0.8.0)
|
87
|
-
vcr
|
88
|
-
webmock
|
89
|
-
|
90
|
-
BUNDLED WITH
|
91
|
-
2.4.10
|