neon_email 0.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: dbd091c753b505fe2db9ef77f45b12d098eb48a12f4fd4cf37a66281b2e06d37
4
+ data.tar.gz: a225077ecd4b16ff36442a010ed3a2b69a51fe23a41faee712061f25f3619992
5
+ SHA512:
6
+ metadata.gz: 05d9dd0adc3d29cd27f7b315f2e8a21c94ddd97b83bb0e9d4d1ae667e9654618235dec14bd3613aff5a95d3f28fdf58cec4709e529758ff34c6f4aaa6e9aea21
7
+ data.tar.gz: 52b9efbcbb865a4a3c51d7f17d51938b82af4395f0c4e7187397958b5e0bf9cfa50f285b3dc30cb84a7826a835ff0cba299ed586dfaf10b9424bf9dca2b79471
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
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
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/lib/neon_email.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "neon_email/version"
2
+ require "neon_email/listener"
3
+
4
+ module NeonEmail
5
+ class Error < StandardError; end
6
+ end
@@ -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
@@ -0,0 +1,12 @@
1
+ require "kafka"
2
+
3
+ module NeonEmail
4
+ class Producer
5
+ def self.produce_greeting
6
+ kafka = Kafka.new(["localhost:9092"])
7
+ kafka.deliver_message("Hello, World!", topic: "greetings")
8
+ end
9
+ end
10
+ end
11
+
12
+ NeonEmail::Producer.produce_greeting
@@ -0,0 +1,3 @@
1
+ module NeonEmail
2
+ VERSION = "0.0.1"
3
+ end
@@ -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: []