spamcaster 1.0.1 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1887d7219a11466d1b181bca48bf9e7a7f8894766de4342cb817bafe21df0c14
4
- data.tar.gz: f439ba559478c67e0104e6e75dddb8332a9dbd69ae8b9363872ec08d55099b55
3
+ metadata.gz: 277cf8efebe23c061919063493d64426f2377aeae14c953d525ae3ff468435c9
4
+ data.tar.gz: 2c884f74a56a988a0638010644d5d179d62b05fa011f8c80d1daf59e79669a4e
5
5
  SHA512:
6
- metadata.gz: 42e4bd8e59ac11db89d71dac6fc53663d68114cd149606205cd373e1815f3c0b3108a9d06ac7e1e4b7d4c1aae7a884dd3c2cbdfb7aa11e9f80d286a60f885720
7
- data.tar.gz: 68ca3ffb33454a736e44d5a8cd565d60e5299fcb35774adff33379d895c2b088487892ace284f2ce3d24cf31fc365130e06727e0d059aacf4acf9cf715d59bda
6
+ metadata.gz: 3687da4713b710475f669ebda9474850a70a8e1e510f33e908f8d84419d1242328874063c3d0696cfc338c0d44380fb2695427109754c6cc9eabf00f6540cdf9
7
+ data.tar.gz: d0bc58fc46e21d84fcd66ac159bd385650e4cc196cece1b2a1c3312a06207326ea499919abf9d11c4e951311e6490e77d97d72d43b8a3862d051dee00393251c
data/bin/spamcaster CHANGED
@@ -1,12 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative '../lib/spamcaster/notifier'
4
+ require_relative '../lib/spamcaster/parts_bin'
4
5
  require_relative '../lib/spamcaster/request'
5
6
  require 'json'
6
7
  require 'sinatra'
7
8
  require 'sinatra/namespace'
8
9
 
9
10
  class SpamcasterApp < Sinatra::Application
11
+ parts_bin = Spamcaster::PartsBin.new
12
+
10
13
  namespace '/api/v1' do
11
14
  get '/' do
12
15
  message = "{message: This is the API index. " +
@@ -17,10 +20,11 @@ class SpamcasterApp < Sinatra::Application
17
20
 
18
21
  post '/spamcheck' do
19
22
  body = JSON.parse request.body.read
20
- request = SpamCaster::Request.new body
23
+ request = Spamcaster::Request.new body
21
24
  case request.spam?
22
25
  when true
23
- notification = SpamCaster::Notifier.notify(:slack, request.email_address)
26
+ service_url = parts_bin.service_url
27
+ notification = Spamcaster::Notifier.notify(:slack, request.email_address, service_url)
24
28
  message = "{message: #{notification}}"
25
29
  JSON.generate message
26
30
  else
@@ -1,23 +1,20 @@
1
1
  require 'httpx'
2
2
  require 'json'
3
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)
4
+ module Spamcaster
5
+ class Notifier
6
+ def self.notify(type, recipient, service_url)
7
+ send(type, recipient, service_url)
11
8
  end
12
9
 
13
10
  private
14
11
 
15
- def self.send(type, recipient)
12
+ def self.send(type, recipient, service_url)
16
13
  case type
17
14
  when :email
18
15
  email recipient
19
16
  when :slack
20
- slack recipient
17
+ slack(recipient, service_url)
21
18
  end
22
19
  end
23
20
 
@@ -33,9 +30,9 @@ module SpamCaster
33
30
  "Email notification sent to #{recipient}!"
34
31
  end
35
32
 
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!"
33
+ def self.slack(recipient, service_url)
34
+ HTTPX.post(service_url, :json => slack_json_payload(recipient)[:json])
35
+ "Notification for #{recipient} sent to Spamcaster's channel!"
39
36
  end
40
37
 
41
38
  # Etc. Define methods to send other notification types e.g. SMS here
@@ -0,0 +1,29 @@
1
+ module Spamcaster
2
+ class PartsBin
3
+ SLK_WHK_SUBDOMAIN = 'hooks'
4
+ SLK_WHK_DOMAIN = 'slack'
5
+ SLK_WHK_PATH = 'services'
6
+ SLK_WHK_REMAINDER = {
7
+ 1 => 'TF0RCGM3M',
8
+ 2 => 'B04TWV2A9TJ',
9
+ 3 => 'Z6bAvFPsERSZm6VIPvbONHtr'
10
+ }
11
+
12
+ def self.service_url
13
+ build_service_url
14
+ end
15
+
16
+ private
17
+
18
+ def self.build_service_url
19
+ service_url = "https://#{SLK_WHK_SUBDOMAIN}/" +
20
+ "#{SLK_WHK_DOMAIN}.com/" +
21
+ "#{SLK_WHK_PATH}/" +
22
+ "#{SLK_WHK_REMAINDER[1]}/" +
23
+ "#{SLK_WHK_REMAINDER[2]}/" +
24
+ "#{SLK_WHK_REMAINDER[3]}"
25
+
26
+ service_url
27
+ end
28
+ end
29
+ end
@@ -1,4 +1,4 @@
1
- module SpamCaster
1
+ module Spamcaster
2
2
  class Request
3
3
  attr_reader :email_address, :payload, :spam
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spamcaster
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lloyd Dube
@@ -22,6 +22,7 @@ files:
22
22
  - README.md
23
23
  - bin/spamcaster
24
24
  - lib/spamcaster/notifier.rb
25
+ - lib/spamcaster/parts_bin.rb
25
26
  - lib/spamcaster/request.rb
26
27
  homepage: https://github.com/dubesoftware/spamcaster
27
28
  licenses: