neon_email 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/Gemfile +20 -0
- data/Gemfile.lock +88 -0
- data/README.md +14 -0
- data/Rakefile +6 -0
- data/lib/neon_email.rb +6 -0
- data/lib/neon_email/consumer.rb +30 -0
- data/lib/neon_email/greeting_mailer.rb +32 -0
- data/lib/neon_email/producer.rb +12 -0
- data/lib/neon_email/version.rb +3 -0
- data/neon_email.gemspec +25 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dbd091c753b505fe2db9ef77f45b12d098eb48a12f4fd4cf37a66281b2e06d37
|
4
|
+
data.tar.gz: a225077ecd4b16ff36442a010ed3a2b69a51fe23a41faee712061f25f3619992
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 05d9dd0adc3d29cd27f7b315f2e8a21c94ddd97b83bb0e9d4d1ae667e9654618235dec14bd3613aff5a95d3f28fdf58cec4709e529758ff34c6f4aaa6e9aea21
|
7
|
+
data.tar.gz: 52b9efbcbb865a4a3c51d7f17d51938b82af4395f0c4e7187397958b5e0bf9cfa50f285b3dc30cb84a7826a835ff0cba299ed586dfaf10b9424bf9dca2b79471
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in neon_postgres.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem "rake", "~> 12.0"
|
7
|
+
gem "rspec", "~> 3.0"
|
8
|
+
gem "standard"
|
9
|
+
|
10
|
+
gem "sequel", "~> 5.43"
|
11
|
+
gem "fixture_dependencies", "~> 1.10"
|
12
|
+
gem "pg", "~> 1.2"
|
13
|
+
|
14
|
+
gem "pry", "~> 0.14.1"
|
15
|
+
|
16
|
+
gem "faker", "~> 2.17"
|
17
|
+
|
18
|
+
gem "ruby-kafka", "~> 1.3"
|
19
|
+
|
20
|
+
gem "sendgrid-ruby", "~> 6.4"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
neon_email (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
coderay (1.1.3)
|
11
|
+
concurrent-ruby (1.1.8)
|
12
|
+
diff-lcs (1.4.4)
|
13
|
+
digest-crc (0.6.3)
|
14
|
+
rake (>= 12.0.0, < 14.0.0)
|
15
|
+
faker (2.17.0)
|
16
|
+
i18n (>= 1.6, < 2)
|
17
|
+
fixture_dependencies (1.10.0)
|
18
|
+
i18n (1.8.10)
|
19
|
+
concurrent-ruby (~> 1.0)
|
20
|
+
method_source (1.0.0)
|
21
|
+
parallel (1.20.1)
|
22
|
+
parser (3.0.1.0)
|
23
|
+
ast (~> 2.4.1)
|
24
|
+
pg (1.2.3)
|
25
|
+
pry (0.14.1)
|
26
|
+
coderay (~> 1.1)
|
27
|
+
method_source (~> 1.0)
|
28
|
+
rainbow (3.0.0)
|
29
|
+
rake (12.3.3)
|
30
|
+
regexp_parser (2.1.1)
|
31
|
+
rexml (3.2.5)
|
32
|
+
rspec (3.10.0)
|
33
|
+
rspec-core (~> 3.10.0)
|
34
|
+
rspec-expectations (~> 3.10.0)
|
35
|
+
rspec-mocks (~> 3.10.0)
|
36
|
+
rspec-core (3.10.1)
|
37
|
+
rspec-support (~> 3.10.0)
|
38
|
+
rspec-expectations (3.10.1)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.10.0)
|
41
|
+
rspec-mocks (3.10.2)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.10.0)
|
44
|
+
rspec-support (3.10.2)
|
45
|
+
rubocop (1.12.1)
|
46
|
+
parallel (~> 1.10)
|
47
|
+
parser (>= 3.0.0.0)
|
48
|
+
rainbow (>= 2.2.2, < 4.0)
|
49
|
+
regexp_parser (>= 1.8, < 3.0)
|
50
|
+
rexml
|
51
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
52
|
+
ruby-progressbar (~> 1.7)
|
53
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
54
|
+
rubocop-ast (1.4.1)
|
55
|
+
parser (>= 2.7.1.5)
|
56
|
+
rubocop-performance (1.10.1)
|
57
|
+
rubocop (>= 0.90.0, < 2.0)
|
58
|
+
rubocop-ast (>= 0.4.0)
|
59
|
+
ruby-kafka (1.3.0)
|
60
|
+
digest-crc
|
61
|
+
ruby-progressbar (1.11.0)
|
62
|
+
ruby_http_client (3.5.2)
|
63
|
+
sendgrid-ruby (6.4.0)
|
64
|
+
ruby_http_client (~> 3.4)
|
65
|
+
sequel (5.43.0)
|
66
|
+
standard (1.0.5)
|
67
|
+
rubocop (= 1.12.1)
|
68
|
+
rubocop-performance (= 1.10.1)
|
69
|
+
unicode-display_width (2.0.0)
|
70
|
+
|
71
|
+
PLATFORMS
|
72
|
+
ruby
|
73
|
+
|
74
|
+
DEPENDENCIES
|
75
|
+
faker (~> 2.17)
|
76
|
+
fixture_dependencies (~> 1.10)
|
77
|
+
neon_email!
|
78
|
+
pg (~> 1.2)
|
79
|
+
pry (~> 0.14.1)
|
80
|
+
rake (~> 12.0)
|
81
|
+
rspec (~> 3.0)
|
82
|
+
ruby-kafka (~> 1.3)
|
83
|
+
sendgrid-ruby (~> 6.4)
|
84
|
+
sequel (~> 5.43)
|
85
|
+
standard
|
86
|
+
|
87
|
+
BUNDLED WITH
|
88
|
+
2.1.4
|
data/README.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Neon Email
|
2
|
+
|
3
|
+
This gem is used to listen to email messages to Kafka and then interact with the
|
4
|
+
Sendgrid API.
|
5
|
+
|
6
|
+
## Necessary API Keys
|
7
|
+
|
8
|
+
* Kafka URL - Where to consume email messages
|
9
|
+
* Sendgrid API Key - The API Key for SendGrid
|
10
|
+
|
11
|
+
## Contributing
|
12
|
+
|
13
|
+
Bug reports and pull requests are welcome on GitHub at
|
14
|
+
https://github.com/neonlaw/codebase.
|
data/Rakefile
ADDED
data/lib/neon_email.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "kafka"
|
2
|
+
|
3
|
+
module NeonEmail
|
4
|
+
class Consumer
|
5
|
+
def self.consume_messages
|
6
|
+
kafka = Kafka.new(["localhost:9092"])
|
7
|
+
|
8
|
+
# Consumers with the same group id will form a Consumer Group together.
|
9
|
+
consumer = kafka.consumer(group_id: "email")
|
10
|
+
|
11
|
+
# It's possible to subscribe to multiple topics by calling `subscribe`
|
12
|
+
# repeatedly.
|
13
|
+
consumer.subscribe("greetings")
|
14
|
+
|
15
|
+
# Stop the consumer when the SIGTERM signal is sent to the process.
|
16
|
+
# It's better to shut down gracefully than to kill the process.
|
17
|
+
trap("TERM") { consumer.stop }
|
18
|
+
|
19
|
+
# This will loop indefinitely, yielding each message in turn.
|
20
|
+
consumer.each_message do |message|
|
21
|
+
case message.topic
|
22
|
+
when "greetings"
|
23
|
+
NeonEmail::GreetingMailer.deliver(message: message.value)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
NeonEmail::Consumer.consume_messages
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "sendgrid-ruby"
|
2
|
+
|
3
|
+
module NeonEmail
|
4
|
+
class GreetingMailer
|
5
|
+
include SendGrid
|
6
|
+
|
7
|
+
def self.deliver(message:)
|
8
|
+
new(message: message).deliver
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(message:)
|
12
|
+
@message = message
|
13
|
+
end
|
14
|
+
|
15
|
+
def deliver
|
16
|
+
from = SendGrid::Email.new(email: "test@example.com")
|
17
|
+
to = SendGrid::Email.new(email: "test@example.com")
|
18
|
+
subject = "Sending with Twilio SendGrid is Fun"
|
19
|
+
content = SendGrid::Content.new(type: "text/plain", value: message)
|
20
|
+
mail = SendGrid::Mail.new(from, subject, to, content)
|
21
|
+
|
22
|
+
sg = SendGrid::API.new(api_key: ENV["SENDGRID_API_KEY"])
|
23
|
+
response = sg.client.mail._("send").post(request_body: mail.to_json)
|
24
|
+
|
25
|
+
puts response
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :message
|
31
|
+
end
|
32
|
+
end
|
data/neon_email.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "lib/neon_email/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "neon_email"
|
5
|
+
spec.version = NeonEmail::VERSION
|
6
|
+
spec.authors = ["Neon Law"]
|
7
|
+
spec.email = ["support@neonlaw.com"]
|
8
|
+
|
9
|
+
spec.summary = "A gem to test the Neon Law Postgres database."
|
10
|
+
spec.description = 'This gem contains tests and sequel setup to speak to
|
11
|
+
the Neon Law database'
|
12
|
+
spec.homepage = "https://github.com/neonlaw/codebase"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
17
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: neon_email
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Neon Law
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-05-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |-
|
14
|
+
This gem contains tests and sequel setup to speak to
|
15
|
+
the Neon Law database
|
16
|
+
email:
|
17
|
+
- support@neonlaw.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- ".gitignore"
|
23
|
+
- ".rspec"
|
24
|
+
- ".rspec_status"
|
25
|
+
- Gemfile
|
26
|
+
- Gemfile.lock
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- lib/neon_email.rb
|
30
|
+
- lib/neon_email/consumer.rb
|
31
|
+
- lib/neon_email/greeting_mailer.rb
|
32
|
+
- lib/neon_email/producer.rb
|
33
|
+
- lib/neon_email/version.rb
|
34
|
+
- neon_email.gemspec
|
35
|
+
homepage: https://github.com/neonlaw/codebase
|
36
|
+
licenses: []
|
37
|
+
metadata:
|
38
|
+
homepage_uri: https://github.com/neonlaw/codebase
|
39
|
+
source_code_uri: https://github.com/neonlaw/codebase
|
40
|
+
changelog_uri: https://github.com/neonlaw/codebase
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 2.3.0
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubygems_version: 3.2.15
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: A gem to test the Neon Law Postgres database.
|
60
|
+
test_files: []
|