spamcaster 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1887d7219a11466d1b181bca48bf9e7a7f8894766de4342cb817bafe21df0c14
4
+ data.tar.gz: f439ba559478c67e0104e6e75dddb8332a9dbd69ae8b9363872ec08d55099b55
5
+ SHA512:
6
+ metadata.gz: 42e4bd8e59ac11db89d71dac6fc53663d68114cd149606205cd373e1815f3c0b3108a9d06ac7e1e4b7d4c1aae7a884dd3c2cbdfb7aa11e9f80d286a60f885720
7
+ data.tar.gz: 68ca3ffb33454a736e44d5a8cd565d60e5299fcb35774adff33379d895c2b088487892ace284f2ce3d24cf31fc365130e06727e0d059aacf4acf9cf715d59bda
data/LICENSE.txt ADDED
@@ -0,0 +1,9 @@
1
+ MIT No Attribution
2
+
3
+ Copyright © 2023 Dube Software
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ A [Sinatra](https://sinatrarb.com/)-based web endpoint that accepts JSON payloads and fires off Slack notifications upon detection of spam.
data/bin/spamcaster ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/spamcaster/notifier'
4
+ require_relative '../lib/spamcaster/request'
5
+ require 'json'
6
+ require 'sinatra'
7
+ require 'sinatra/namespace'
8
+
9
+ class SpamcasterApp < Sinatra::Application
10
+ namespace '/api/v1' do
11
+ get '/' do
12
+ message = "{message: This is the API index. " +
13
+ "To check a JSON payload for spam, POST it to the '/api/v1/spamcheck' path.}"
14
+
15
+ JSON.generate message.strip
16
+ end
17
+
18
+ post '/spamcheck' do
19
+ body = JSON.parse request.body.read
20
+ request = SpamCaster::Request.new body
21
+ case request.spam?
22
+ when true
23
+ notification = SpamCaster::Notifier.notify(:slack, request.email_address)
24
+ message = "{message: #{notification}}"
25
+ JSON.generate message
26
+ else
27
+ JSON.generate '{message: "No spam was detected :)"}'
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ SpamcasterApp.run!
@@ -0,0 +1,43 @@
1
+ require 'httpx'
2
+ require 'json'
3
+
4
+ module SpamCaster
5
+ class Notifier
6
+ # N.B: The Webhook URL would NOT live here in a production application
7
+ SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/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'
8
+
9
+ def self.notify(type, recipient)
10
+ send(type, recipient)
11
+ end
12
+
13
+ private
14
+
15
+ def self.send(type, recipient)
16
+ case type
17
+ when :email
18
+ email recipient
19
+ when :slack
20
+ slack recipient
21
+ end
22
+ end
23
+
24
+ def self.slack_json_payload(recipient)
25
+ {:json =>
26
+ {
27
+ "text" => "A spam payload for the email address #{recipient} was detected."
28
+ }
29
+ }
30
+ end
31
+
32
+ def self.email(recipient)
33
+ "Email notification sent to #{recipient}!"
34
+ end
35
+
36
+ def self.slack(recipient)
37
+ HTTPX.post(SLACK_WEBHOOK_URL, :json => slack_json_payload(recipient)[:json])
38
+ "Slack notification for #{recipient} sent to Spamcaster's Slack channel!"
39
+ end
40
+
41
+ # Etc. Define methods to send other notification types e.g. SMS here
42
+ end
43
+ end
@@ -0,0 +1,44 @@
1
+ module SpamCaster
2
+ class Request
3
+ attr_reader :email_address, :payload, :spam
4
+
5
+ PAYLOAD_TYPE_CODES = {
6
+ spam_notificiation: 512,
7
+ hard_bounce: 1
8
+ }
9
+
10
+ PAYLOAD_TYPES = {
11
+ 512 => "SpamNotification",
12
+ 1 => "HardBounce"
13
+ }
14
+
15
+ def initialize(body)
16
+ @body = body
17
+ @spam = false
18
+ check_spam
19
+ set_email_address
20
+ end
21
+
22
+ def spam?
23
+ @spam
24
+ end
25
+
26
+ def to_s
27
+ @body
28
+ end
29
+
30
+ private
31
+
32
+ def check_spam
33
+ spam_type_code = PAYLOAD_TYPE_CODES[:spam_notificiation]
34
+ spam_type = PAYLOAD_TYPES[spam_type_code]
35
+ received_payload_type = @body["Type"]
36
+
37
+ @spam = (received_payload_type == spam_type)
38
+ end
39
+
40
+ def set_email_address
41
+ @email_address = @body["Email"]
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spamcaster
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Lloyd Dube
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-03-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: "A [Sinatra](https://sinatrarb.com/)-based web endpoint that accepts
14
+ JSON payloads and fires off Slack notifications upon detection of spam. \n"
15
+ email: zebra05+spamcaster@gmail.com
16
+ executables:
17
+ - spamcaster
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE.txt
22
+ - README.md
23
+ - bin/spamcaster
24
+ - lib/spamcaster/notifier.rb
25
+ - lib/spamcaster/request.rb
26
+ homepage: https://github.com/dubesoftware/spamcaster
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '1.9'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubygems_version: 3.4.7
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: A Sinatra-based web endpoint that accepts JSON payloads and fires off Slack
49
+ notifications upon detection of spam.
50
+ test_files: []