plunk_mail 0.1.0

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: 14aa48ca43599b9ebd0b078b2a7ba3ae10ce2e13f5ccb350b25a760142719f00
4
+ data.tar.gz: ae4fc89ef05e07b45ae16e7e969b1ce22697eb186c98a8f6707e56192ab0c368
5
+ SHA512:
6
+ metadata.gz: b124b878c5e45d6124c4674c4e49c1a0333b4bd5c16e104197e672102e64f047ac4ba24626d8ab87fe307f609f0e8e7204232be6330b39f96d26fb6d7e23284b
7
+ data.tar.gz: fce30f08f21a0b59e6d1589abb670b446ec766fba0830180437dcfd9c7b8af1f486cc42dc504fdb8c2bc1b9198ace2a82615946fc9ace15c6b82b3de61b437cc
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright Andres
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,70 @@
1
+ # PlunkMail
2
+
3
+ ActionMailer delivery method for sending emails through Plunk.
4
+
5
+ PlunkMail allows Rails applications to use Plunk as an ActionMailer delivery method:
6
+
7
+ ```ruby
8
+ config.action_mailer.delivery_method = :plunk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Configure Plunk in your `config/environments/production.rb`:
14
+
15
+ ```ruby
16
+ config.action_mailer.delivery_method = :plunk
17
+
18
+ config.action_mailer.plunk_settings = {
19
+ api_key: ENV["PLUNK_API_KEY"]
20
+ }
21
+ ```
22
+
23
+ Use ActionMailer normally:
24
+
25
+ ```ruby
26
+ class UserMailer < ApplicationMailer
27
+ def welcome(user)
28
+ mail(
29
+ to: user.email,
30
+ subject: "Welcome"
31
+ )
32
+ end
33
+ end
34
+ ```
35
+
36
+ Send the email:
37
+
38
+ ```ruby
39
+ UserMailer.welcome(user).deliver_now
40
+ ```
41
+
42
+ HTML emails are supported automatically. If an HTML part exists, it will be sent through Plunk.
43
+
44
+ ## Installation
45
+
46
+ Add this line to your application's Gemfile:
47
+
48
+ ```ruby
49
+ gem "plunk_mail"
50
+ ```
51
+
52
+ And then execute:
53
+
54
+ ```bash
55
+ $ bundle
56
+ ```
57
+
58
+ Or install it yourself as:
59
+
60
+ ```bash
61
+ $ gem install plunk_mail
62
+ ```
63
+
64
+ ## Contributing
65
+
66
+ Contribution directions go here.
67
+
68
+ ## License
69
+
70
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,38 @@
1
+ require "faraday"
2
+
3
+ module PlunkMail
4
+ class DeliveryMethod
5
+ def initialize(settings = {})
6
+ @api_key = settings[:api_key]
7
+ end
8
+
9
+ def deliver!(mail)
10
+ response = Faraday.post(
11
+ "https://next-api.useplunk.com/v1/send",
12
+ {
13
+ to: mail.to.first,
14
+ subject: mail.subject,
15
+ body: email_body(mail),
16
+ from: {
17
+ name: mail[:from]&.display_names&.first,
18
+ email: mail.from.first
19
+ }.compact
20
+ }.to_json,
21
+ {
22
+ "Authorization" => "Bearer #{@api_key}",
23
+ "Content-Type" => "application/json"
24
+ }
25
+ )
26
+
27
+ raise "Plunk error: #{response.status} #{response.body}" unless response.success?
28
+
29
+ response
30
+ end
31
+
32
+ private
33
+
34
+ def email_body(mail)
35
+ mail.html_part&.body&.decoded || mail.body.decoded
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module PlunkMail
2
+ VERSION = "0.1.0"
3
+ end
data/lib/plunk_mail.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "plunk_mail/version"
2
+ require "plunk_mail/delivery_method"
3
+ require "action_mailer"
4
+
5
+ ActionMailer::Base.add_delivery_method(
6
+ :plunk,
7
+ PlunkMail::DeliveryMethod
8
+ )
9
+
10
+ module PlunkMail
11
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :plunk_mail do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plunk_mail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andres Gracia Danies
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rails
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 8.1.3
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 8.1.3
26
+ - !ruby/object:Gem::Dependency
27
+ name: faraday
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: webmock
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rspec
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ description: PlunkMail allows Rails applications to use Plunk as an ActionMailer delivery
69
+ method.
70
+ email:
71
+ - 18741308+a-gracia@users.noreply.github.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - MIT-LICENSE
77
+ - README.md
78
+ - lib/plunk_mail.rb
79
+ - lib/plunk_mail/delivery_method.rb
80
+ - lib/plunk_mail/version.rb
81
+ - lib/tasks/plunk_mail_tasks.rake
82
+ homepage: https://github.com/a-gracia/plunk_mail
83
+ licenses:
84
+ - MIT
85
+ metadata:
86
+ homepage_uri: https://github.com/a-gracia/plunk_mail
87
+ source_code_uri: https://github.com/a-gracia/plunk_mail
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubygems_version: 3.7.2
103
+ specification_version: 4
104
+ summary: ActionMailer delivery method for sending emails through Plunk.
105
+ test_files: []