ombu_labs-notifications 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 49291d1cca1c5739ff9f34e8e37b26ec8f2e9209349869d86f6f6c9bcbcc18ac
4
+ data.tar.gz: '091ecb37aae22fcb44b061e4e8f770b70265fbbf09f488e309fc20c2887cd855'
5
+ SHA512:
6
+ metadata.gz: 9ea20982214f6e618b33a082a1e19df9fd7a0dc388a33d62f52ecdc2d7ff5b551ba1013d7e542681606260f31be208be27a096abb0cb7c41106b2ba247fcaf9f
7
+ data.tar.gz: a9536245616fa49f7469d6dc1f44dabf8c03aa508815104781319bd95e9587c38893b7b86d763d923f6dbc14abd4e6554874421eb492ff07c0de9b6440c011bc
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2022 Fiona
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # OmbuLabs::Notifications
2
+ Source code for OmbuLabs notifications.
3
+
4
+ ## Usage
5
+ This gem can be used in any of our sites to send email and slack notifications. The aim of this gem is to simplify things when we need to update some code when something is broken in all of our sites.
6
+
7
+ There are some ENV variables in this gem that will need to be defined in any new site.
8
+ You will also need to include a Contact model that had the following:
9
+ email, email_sent_at, slack_notified_at, and id. You will also need an update_column method.
10
+
11
+ ## Installation
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'ombu_labs-notifications'
16
+ ```
17
+
18
+ And then execute:
19
+ ```bash
20
+ $ bundle
21
+ ```
22
+
23
+ Or install it yourself as:
24
+ ```bash
25
+ $ gem install ombu_labs-notifications
26
+ ```
27
+
28
+ ## Contributing
29
+ Contribution directions go here.
30
+
31
+ ## License
32
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ load "rails/tasks/statistics.rake"
7
+
8
+ require "bundler/gem_tasks"
9
+
10
+ require "rake/testtask"
11
+
12
+ Rake::TestTask.new(:test) do |t|
13
+ t.libs << 'test'
14
+ t.pattern = 'test/**/*_test.rb'
15
+ t.verbose = false
16
+ end
17
+
18
+ task default: :test
@@ -0,0 +1,11 @@
1
+ # Mailer for the contact form
2
+
3
+ class ContactMailer < ApplicationMailer
4
+ CONTACT_FORM_TO = ENV["CONTACT_FORM_TO"].presence || "hello@ombulabs.com"
5
+ def contact_email(contact)
6
+ @contact = contact
7
+ mail(subject: "[OmbuLabs] #{contact.email} just sent you a message!",
8
+ to: CONTACT_FORM_TO,
9
+ reply_to: contact.email)
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ class SlackNotifier
2
+ def notify_new_contact(contact)
3
+ notifier = Slack::Notifier.new ENV["SLACK_WEBHOOK_URL"]
4
+ notifier.ping contact_message(contact)
5
+ end
6
+
7
+ private
8
+
9
+ def contact_message(contact)
10
+ <<~TEXT
11
+ Hello <!subteam^#{ENV["SLACK_GROUP_ID"]}>!\n
12
+ #{contact.name.titleize} has submitted the following message in our contact form :tada: :
13
+ ```
14
+ #{contact.message}
15
+ ```
16
+ Email: #{contact.email}
17
+ How they found us: #{contact.found_us}
18
+ Request Type: #{contact.request_type&.titleize}\n
19
+ In House Developers: #{contact&.in_house_developers}\n
20
+ They plan to start at: #{contact&.starting_at}\n
21
+ Cheers,\nYour OmbuLabs Robot!
22
+
23
+ TEXT
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ <p>Hello!</p>
2
+
3
+ <p>A message has been submitted.</p>
4
+
5
+ <p>Cheers,<br/>Your OmbuLabs Robot!</p>
@@ -0,0 +1,15 @@
1
+ class ContactMailerWorker
2
+ include Sidekiq::Worker
3
+
4
+ def perform(contact_id)
5
+ return unless (contact = Contact.find(contact_id))
6
+
7
+ if contact.email_sent_at.blank?
8
+ ContactMailer.contact_email(contact).deliver_now
9
+ contact.update_column :email_sent_at, Time.current
10
+ Sidekiq.logger.info "Sent email to #{contact.email}"
11
+ else
12
+ Sidekiq.logger.info "Skipping email to #{contact.email}"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ class ContactSlackWorker
2
+ include Sidekiq::Worker
3
+
4
+ def perform(contact_id)
5
+ return unless (contact = Contact.find(contact_id))
6
+
7
+ if contact.slack_notified_at.blank?
8
+ SlackNotifier.new.notify_new_contact(contact)
9
+ contact.update_column :slack_notified_at, Time.current
10
+ Sidekiq.logger.info "Slack notification sent: #{contact.email}"
11
+ else
12
+ Sidekiq.logger.info "Slack notification skipped: #{contact.email}"
13
+ end
14
+ end
15
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,6 @@
1
+ module OmbuLabs
2
+ module Notifications
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module OmbuLabs
2
+ module Notifications
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require "ombu_labs/notifications/version"
2
+ require "ombu_labs/notifications/engine"
3
+ require "slack-notifier"
4
+
5
+ module OmbuLabs
6
+ module Notifications
7
+ # Your code goes here...
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :ombu_labs_notifications do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ombu_labs-notifications
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fiona
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: slack-notifier
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.4.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.4.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: sidekiq
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: Knows how to send a new contact email, new contact Slack notification
56
+ email:
57
+ - fiona@ombulabs.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - MIT-LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - app/mailers/contact_mailer.rb
66
+ - app/services/slack_notifier.rb
67
+ - app/views/contact_mailer/contact_email.html.erb
68
+ - app/workers/contact_mailer_worker.rb
69
+ - app/workers/contact_slack_worker.rb
70
+ - config/routes.rb
71
+ - lib/ombu_labs/notifications.rb
72
+ - lib/ombu_labs/notifications/engine.rb
73
+ - lib/ombu_labs/notifications/version.rb
74
+ - lib/tasks/ombu_labs/notifications_tasks.rake
75
+ homepage: https://github.com/fastruby/ombu_labs-notifications
76
+ licenses:
77
+ - MIT
78
+ metadata:
79
+ allowed_push_host: https://rubygems.org
80
+ homepage_uri: https://github.com/fastruby/ombu_labs-notifications
81
+ source_code_uri: https://github.com/fastruby/ombu_labs-notifications
82
+ changelog_uri: https://github.com/fastruby/ombu_labs-notifications
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubygems_version: 3.3.7
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: A gem to send notifications via email, Slack
102
+ test_files: []