bns 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +14 -0
  4. data/CHANGELOG.md +11 -0
  5. data/CODE_OF_CONDUCT.md +132 -0
  6. data/CONTRIBUTING.md +66 -0
  7. data/Gemfile +18 -0
  8. data/Gemfile.lock +91 -0
  9. data/LICENSE +21 -0
  10. data/README.md +198 -0
  11. data/Rakefile +12 -0
  12. data/lib/bns/dispatcher/base.rb +31 -0
  13. data/lib/bns/dispatcher/discord/exceptions/invalid_webhook_token.rb +16 -0
  14. data/lib/bns/dispatcher/discord/implementation.rb +51 -0
  15. data/lib/bns/dispatcher/discord/types/response.rb +22 -0
  16. data/lib/bns/domain/birthday.rb +23 -0
  17. data/lib/bns/domain/exceptions/function_not_implemented.rb +18 -0
  18. data/lib/bns/domain/pto.rb +26 -0
  19. data/lib/bns/fetcher/base.rb +30 -0
  20. data/lib/bns/fetcher/notion/birthday.rb +53 -0
  21. data/lib/bns/fetcher/notion/exceptions/invalid_api_key.rb +15 -0
  22. data/lib/bns/fetcher/notion/exceptions/invalid_database_id.rb +15 -0
  23. data/lib/bns/fetcher/notion/helper.rb +21 -0
  24. data/lib/bns/fetcher/notion/pto.rb +48 -0
  25. data/lib/bns/fetcher/notion/types/response.rb +26 -0
  26. data/lib/bns/formatter/base.rb +29 -0
  27. data/lib/bns/formatter/discord/birthday.rb +43 -0
  28. data/lib/bns/formatter/discord/exceptions/invalid_data.rb +17 -0
  29. data/lib/bns/formatter/discord/pto.rb +52 -0
  30. data/lib/bns/mapper/base.rb +30 -0
  31. data/lib/bns/mapper/notion/birthday.rb +76 -0
  32. data/lib/bns/mapper/notion/pto.rb +96 -0
  33. data/lib/bns/use_cases/types/config.rb +19 -0
  34. data/lib/bns/use_cases/use_case.rb +39 -0
  35. data/lib/bns/use_cases/use_cases.rb +150 -0
  36. data/lib/bns/version.rb +6 -0
  37. data/lib/bns.rb +9 -0
  38. data/sig/business_notification_system.rbs +4 -0
  39. metadata +84 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a422fa03f80a83a9c8ba021d998a00b90ee7381a5167d96e23562c67cc6d73d1
4
+ data.tar.gz: 168f81ac480dc71796c2123c24ad27a5b04cbd1a9543388c1010425a037ad08f
5
+ SHA512:
6
+ metadata.gz: 28919c76616533281768cd65bb00e4e2d0d7c0e22c480ffe38bf75d23e5d46a3b768f3e1e99bc68e55b3d822eb01fd598731e12e35351f8b29a15b60f80bee3d
7
+ data.tar.gz: d88313f8d80abce0480c63a4e35d8b5ccfa0151c2afb13205b2ae31a755974d72f2be87fdd726ac573b6b80ac4f1fcd133899936b04728af70e95d3be4a358e7
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Metrics/BlockLength:
13
+ Exclude:
14
+ - 'spec/**/*_spec.rb'
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (06.02.2024)
4
+
5
+ - [Build initial codebase](https://github.com/kommitters/bns/issues/6)
6
+ - [Birthdays use case implementation](https://github.com/kommitters/bns/issues/7)
7
+ - [PTO’s use case implementation](https://github.com/kommitters/bns/issues/8)
8
+ - [Error handler implementation](https://github.com/kommitters/bns/issues/9)
9
+ - [Types implementation](https://github.com/kommitters/bns/issues/11)
10
+ - [Documentation completion](https://github.com/kommitters/bns/issues/12)
11
+ - [Opensource configurations](https://github.com/kommitters/bns/issues/10)
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community includes:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing other's private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at [oss@kommit.co](mailto:oss@kommit.co).
63
+
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available
126
+ at [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,66 @@
1
+ # Contributing 🎉
2
+
3
+ Hi there! We are thrilled that you'd like to contribute to this project. Your help is essential for keeping it great 🙌.
4
+
5
+ Contributions to this project are [released][contributions-under-repo] to the public under the project's open source license.
6
+
7
+ Here are a few things you can do that will increase the likelihood of your pull request being accepted:
8
+ - Follow standards for style and code quality.
9
+ - Write tests (if applicable).
10
+ - Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests.
11
+ - Write a [good commit message][commit-msg].
12
+ - All content, comments, pull requests and other contributions must comply with the [code of conduct][coc].
13
+
14
+ ## Getting started
15
+
16
+ * Make sure you have a [GitHub account][github-signup].
17
+ * Create a GitHub issue for your contribution, assuming one does not already exist.
18
+ * Choose one of the templates and clearly describe the issue.
19
+ * Fork the repository on GitHub.
20
+ * Try to keep your local repository in a "rebased" state.
21
+
22
+ ## Finding things to work on
23
+
24
+ Issues marked with [good first issue][good-first-issue] or [help wanted][help-wanted] are usually pretty self-contained and a good place to get started.
25
+
26
+ If you see any issues that are assigned to a particular person or have the `📍 Work in progress` label, that means
27
+ someone is currently working on that issue this issue in the next week or two.
28
+
29
+ Of course, feel free to create a new issue if you think something needs to be added or fixed.
30
+
31
+ ## Making changes
32
+
33
+ * Create a topic branch from where you want to base your work `git checkout -b my-branch-name`.
34
+ * This is usually the `main` branch.
35
+ * Please avoid working directly on the `main` branch.
36
+
37
+ ## Submitting changes
38
+ * Push changes to your fork.
39
+ * Submit a pull request.
40
+
41
+ At this point, you're waiting on us. We like to at least comment on pull requests within three
42
+ business days (typically, one business day). We may suggest some changes, improvements or
43
+ alternatives.
44
+
45
+ ## Resources
46
+
47
+ - [How to Contribute to Open Source][oss-how-to]
48
+ - [Using Pull Requests][github-help-pr]
49
+ - [GitHub Help][github-help]
50
+
51
+ ## Contact
52
+
53
+ Get in touch: [oss@kommit.co][mail-to] | [@kommitters_oss][twitter] on Twitter.
54
+
55
+
56
+ [twitter]: https://twitter.com/kommitters_oss
57
+ [mail-to]: mailto:oss@kommit.co
58
+ [github-signup]: https://github.com/signup/free
59
+ [github-help]: https://help.github.com
60
+ [github-help-pr]: https://help.github.com/articles/about-pull-requests
61
+ [oss-how-to]: https://opensource.guide/how-to-contribute
62
+ [coc]: https://github.com/kommitters/soroban-did-contract/blob/main/CODE_OF_CONDUCT.md
63
+ [commit-msg]: https://github.com/erlang/otp/wiki/Writing-good-commit-messages
64
+ [good-first-issue]: https://github.com/kommitters/soroban-did-contract/issues?q=is%3Aopen+is%3Aissue+label%3A%22%F0%9F%91%8B+Good+first+issue%22
65
+ [help-wanted]: https://github.com/kommitters/soroban-did-contract/issues?q=is%3Aopen+is%3Aissue+label%3A%22%F0%9F%86%98+Help+wanted%22
66
+ [contributions-under-repo]: https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in bns.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+ gem "rubocop", "~> 1.21"
12
+ gem "simplecov", require: false, group: :test
13
+ gem "simplecov-lcov", "~> 0.8.0"
14
+
15
+ gem "vcr"
16
+ gem "webmock"
17
+
18
+ gem "httparty"
data/Gemfile.lock ADDED
@@ -0,0 +1,91 @@
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
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 kommitters Open Source
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,198 @@
1
+ # BNS - Business Notification System
2
+
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
+
5
+ ![Build Badge](https://img.shields.io/github/actions/workflow/status/kommitters/bns/ci.yml?branch=project-opensource-config&style=for-the-badge)
6
+ [![Coverage Status](https://img.shields.io/coveralls/github/kommitters/bns?style=for-the-badge)](https://coveralls.io/github/kommitters/bns?branch=main)
7
+ [![OpenSSF Scorecard](https://img.shields.io/ossf-scorecard/github.com/kommitters/bns?style=for-the-badge)](https://api.securityscorecards.dev/projects/github.com/kommitters/bns)
8
+ ![GitHub License](https://img.shields.io/github/license/kommitters/bns?style=for-the-badge)
9
+
10
+ ## Installation
11
+
12
+ Install the gem and add to the application's Gemfile by executing:
13
+
14
+ $ bundle add bns
15
+
16
+ If bundler is not being used to manage dependencies, install the gem by executing:
17
+
18
+ $ gem install bns
19
+
20
+ ## Requirements
21
+
22
+ * Ruby 3.2.2 or higher
23
+
24
+ ## Building my own use case
25
+
26
+ The gem provides with basic interfaces, types, and methods to shape your own use cases in an easy way.
27
+
28
+ There are 2 currently implemented use cases:
29
+ * Birthday notifications - from Notion to Discord
30
+ * PTO notifications - from Notion to Discord
31
+
32
+ For this example we'll analize the birthday notification use case, bringing data from a notion database, and dispatching the
33
+ notifications to a Discord channel.
34
+
35
+ A *Use Case* object, consists on 4 main componenets, having it's own responsability:
36
+
37
+ ### 1. Fetcher - Obtaining the data
38
+
39
+ Specifically, a fetcher is an object in charged of bringing data from a data source. The gem already provides the base interface
40
+ for building your own fetcher for your specific data source, or rely on already built classes if they match your purpose.
41
+
42
+ The base interface for a fetcher can be found under the `bns/fetcher/base.rb` class. Since this is a implementation of the `Fetcher::Base`
43
+ for bringing data from a Notion database, it was created on a new namespace for that data source, it can be found under
44
+ `/bns/fetcher/notion/birthday.rb`. It implements specific logic for fetching the data and validating the response.
45
+
46
+ ### 2. Mapper - Shaping it
47
+
48
+ The **Mapper** responsability, is to shape the data using custom types from the app domain, bringing it into a
49
+ common structure understandable for other components, specifically the **Formatter**.
50
+
51
+ Because of the use case, the Mapper implementation for it, relyes on specific types for representing a Birthday it self. It can be found
52
+ under `/bns/mapper/notion/birthday.rb`
53
+
54
+ ### 3. Formatter - Preparing the message
55
+
56
+ The **Formatter**, is in charge of preparing the message to be sent in our notification, and give it the right format with the right data.
57
+ 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
58
+ implementation can be found under `/bns/formatter/discord/birthday.rb`.
59
+
60
+ ### 4. Dispatcher - Sending your notification
61
+
62
+ Finally, the **Dispatcher** basically, sends or dispatches the formatted message into a destination, since the use case was implemented for
63
+ Discord, it implements specific logic to communicate with a Discord channel using a webhook. The webhook configuration and name for the 'Sender'
64
+ in the channel should be provided with the initial use case configurations. It can be found under `/bns/dispatcher/discord/implementation.rb`
65
+
66
+ ## Examples
67
+
68
+ In this example, we demonstrate how to instantiate a birthday notification use case and execute it in a basic Ruby project. We'll also cover its deployment in a serverless configuration, specifically using a simple Lambda deployment.
69
+
70
+ ### Preparing the configurations
71
+
72
+ We'll need some configurations for this specific use case:
73
+ * A **Notion database ID**, from a database with the following structure:
74
+
75
+ | Complete Name (text) | BD_this_year (formula) | BD (date) |
76
+ | -------------------- | --------------------------- | ------------------------ |
77
+ | John Doe | January 24, 2024 | January 24, 2000 |
78
+ | Jane Doe | June 20, 2024 | June 20, 2000 |
79
+
80
+ With the following formula for the **BD_this_year** column: `dateAdd(prop("BD"), year(now()) - year(prop("BD")), "years")`
81
+
82
+ * 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.
83
+
84
+ * A webhook key, which can be generated directly on discord on the desired channel, following this instructions: `https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks`
85
+
86
+ * A filter, to determine which data to bring from the database, for this specific case, the filter we used is:
87
+
88
+ ```
89
+ #### file.rb ####
90
+ today = Date.now
91
+ {
92
+ "filter": {
93
+ "or": [
94
+ {
95
+ "property": "BD_this_year",
96
+ "date": {
97
+ "equals": today
98
+ }
99
+ }
100
+ ]
101
+ },
102
+ "sorts": []
103
+ }
104
+ ```
105
+
106
+ * 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:
107
+
108
+ `"NAME, Wishing you a very happy birthday! Enjoy your special day! :birthday: :gift:"`
109
+
110
+ ### Instantiating the Use Case
111
+
112
+ To instantiate the use case, the `UseCases` module should provide a method for this purpose, for this specific case, the `notify_birthday_from_notion_to_discord`
113
+ is the desired one.
114
+
115
+ **Normal ruby code**
116
+ ```
117
+ filter = {
118
+ "filter": {
119
+ "or": [
120
+ {
121
+ "property": "BD_this_year",
122
+ "date": {
123
+ "equals": today
124
+ }
125
+ }
126
+ ]
127
+ },
128
+ "sorts": []
129
+ }
130
+
131
+ options = {
132
+ fetch_options: {
133
+ base_url: "https://api.notion.com",
134
+ database_id: NOTION_DATABASE_ID,
135
+ secret: NOTION_API_INTEGRATION_SECRET,
136
+ filter: filter
137
+ },
138
+ dispatch_options: {
139
+ webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
140
+ name: "Birthday Bot"
141
+ }
142
+ }
143
+
144
+ use_case = UseCases.notify_birthday_from_notion_to_discord(options)
145
+
146
+ use_case.perform
147
+
148
+ ```
149
+
150
+ **Serverless**
151
+
152
+ Examples of different use cases, and how to configure and deploy the lambdas can be found on: `https://github.com/kommitters/bns_serverless`
153
+
154
+ ## Development
155
+
156
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
157
+
158
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
159
+
160
+ ## Changelog
161
+
162
+ Features and bug fixes are listed in the [CHANGELOG][changelog] file.
163
+
164
+ ## Code of conduct
165
+
166
+ We welcome everyone to contribute. Make sure you have read the [CODE_OF_CONDUCT][coc] before.
167
+
168
+ ## Contributing
169
+
170
+ For information on how to contribute, please refer to our [CONTRIBUTING][contributing] guide.
171
+
172
+ ## License
173
+
174
+ The gem is licensed under an MIT license. See [LICENSE][license] for details.
175
+
176
+ <br/>
177
+
178
+ <hr/>
179
+
180
+ [<img src="https://github.com/kommitters/chaincerts-smart-contracts/assets/1649973/d60d775f-166b-4968-89b6-8be847993f8c" width="80px" alt="kommit"/>](https://kommit.co)
181
+
182
+ <sub>
183
+
184
+ [Website][kommit-website] •
185
+ [Github][kommit-github] •
186
+ [X][kommit-x] •
187
+ [LinkedIn][kommit-linkedin]
188
+
189
+ </sub>
190
+
191
+ [license]: https://github.com/kommitters/bns/blob/main/LICENSE
192
+ [coc]: https://github.com/kommitters/bns/blob/main/CODE_OF_CONDUCT.md
193
+ [changelog]: https://github.com/kommitters/bns/blob/main/CHANGELOG.md
194
+ [contributing]: https://github.com/kommitters/bns/blob/main/CONTRIBUTING.md
195
+ [kommit-website]: https://kommit.co
196
+ [kommit-github]: https://github.com/kommitters
197
+ [kommit-x]: https://twitter.com/kommitco
198
+ [kommit-linkedin]: https://www.linkedin.com/company/kommit-co
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../domain/exceptions/function_not_implemented"
4
+
5
+ module Dispatcher
6
+ ##
7
+ # Serves as a foundational structure for implementing specific dispatchers. Acting as an interface,
8
+ # this class defines essential attributes and methods, providing a blueprint for creating custom
9
+ # dispatchers tailored to different platforms or services.
10
+ #
11
+ class Base
12
+ attr_reader :webhook, :name
13
+
14
+ # Initializes the dispatcher with essential configuration parameters.
15
+ #
16
+ def initialize(config)
17
+ @webhook = config[:webhook]
18
+ @name = config[:name]
19
+ end
20
+
21
+ # A method meant to send messages to an specific destination depending on the implementation.
22
+ # Must be overridden by subclasses, with specific logic based on the use case.
23
+ #
24
+ # <br>
25
+ # <b>returns</b> a <tt>Discord::Response</tt>
26
+ #
27
+ def dispatch(_payload)
28
+ raise Domain::Exceptions::FunctionNotImplemented
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dispatcher
4
+ module Exceptions
5
+ module Discord
6
+ ##
7
+ # Domain specific representation when an invalid Discord webhook token is provided to Discord.
8
+ #
9
+ class InvalidWebookToken < StandardError
10
+ def initialize(message = "The provided Webhook token is invalid.")
11
+ super(message)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end