mailpy 0.1.1 → 0.1.6
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 +4 -4
- data/README.md +13 -1
- data/lib/mailpy.rb +8 -12
- data/lib/mailpy/mailer_api.rb +33 -22
- data/lib/mailpy/version.rb +1 -1
- metadata +3 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21476287a915391df402c2d12dd74a6665e594c1b5eec0a5e19d75f59544fc1e
|
4
|
+
data.tar.gz: 49f4380a0e2d0ec8e7fb07063b7a969d46374ac332dfef8487066372a97e5e1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ca3d484f041f422d8c9d1b97102d3177e678ce5795014220237c9716f8b2fd099cab5d544928ec1cc57e43b93ca9171899a24a97894e6d1e45ab8f3c4055c09
|
7
|
+
data.tar.gz: f09f2eae711235ab0320344db3e535c690844261f611be0cc7c600c8b556849ad6e0490025b31aaf0264b6e2725b1826d083820ea28958b8928cb9cf18e3b997
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Mailpy
|
2
|
-
|
2
|
+
Action Mailer Adapter for Send Email Through HTTP APIs.
|
3
3
|
|
4
4
|
## Usage
|
5
5
|
How to use my plugin.
|
@@ -11,6 +11,18 @@ Add this line to your application's Gemfile:
|
|
11
11
|
gem 'mailpy'
|
12
12
|
```
|
13
13
|
|
14
|
+
Add configuration to your application environments. development.rb, staging.rb, or production.rb
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
config.action_mailer.delivery_method = :mailpy
|
18
|
+
config.action_mailer.mailpy_settings = {
|
19
|
+
endpoint: ENV['MAILER_API_ENDPOINT'],
|
20
|
+
headers: {
|
21
|
+
Authorization: ENV['MAILER_API_KEY_OR_AUTH_TOKEN']
|
22
|
+
}
|
23
|
+
}
|
24
|
+
```
|
25
|
+
|
14
26
|
And then execute:
|
15
27
|
```bash
|
16
28
|
$ bundle
|
data/lib/mailpy.rb
CHANGED
@@ -3,6 +3,8 @@ require "mailpy/mailer_api"
|
|
3
3
|
|
4
4
|
module Mailpy
|
5
5
|
class DeliveryMethod
|
6
|
+
MailpyDeliveryError = Class.new(StandardError)
|
7
|
+
|
6
8
|
attr_accessor :settings
|
7
9
|
|
8
10
|
def initialize(params)
|
@@ -10,20 +12,14 @@ module Mailpy
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def deliver!(mail)
|
13
|
-
|
15
|
+
perform_send_request(mail, settings)
|
14
16
|
end
|
15
17
|
|
16
18
|
private
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
sender: mail.from.try(:join, ', '),
|
23
|
-
subject: mail.subject,
|
24
|
-
endpoint: settings[:endpoint],
|
25
|
-
token: settings[:token]
|
26
|
-
}
|
27
|
-
end
|
19
|
+
def perform_send_request(mail, settings)
|
20
|
+
result = MailerApi.new(mail, settings).send
|
21
|
+
raise(MailpyDeliveryError, JSON.parse(result.body)['message']) unless result.code === 200
|
22
|
+
result
|
23
|
+
end
|
28
24
|
end
|
29
25
|
end
|
data/lib/mailpy/mailer_api.rb
CHANGED
@@ -1,34 +1,45 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
|
3
3
|
class MailerApi
|
4
|
-
|
5
|
-
|
6
|
-
def initialize(options, message)
|
4
|
+
def initialize(mail, options = {})
|
5
|
+
@mail = mail
|
7
6
|
@options = options
|
8
|
-
@message = message
|
9
7
|
end
|
10
8
|
|
11
9
|
def send
|
12
|
-
|
10
|
+
result = HTTParty.post(
|
11
|
+
options[:endpoint],
|
12
|
+
body: form_data,
|
13
|
+
headers: headers
|
14
|
+
)
|
13
15
|
end
|
14
16
|
|
15
17
|
private
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
headers: {
|
29
|
-
'Content-Type': 'application/json',
|
30
|
-
'Authorization': options[:token].to_s
|
18
|
+
attr_reader :mail, :options
|
19
|
+
|
20
|
+
def form_data
|
21
|
+
{
|
22
|
+
to: mail.to.try(:join, ', '),
|
23
|
+
cc: mail.cc.try(:join, ', '),
|
24
|
+
bcc: mail.bcc.try(:join, ', '),
|
25
|
+
from: mail.from.try(:join, ', '),
|
26
|
+
subject: mail.subject,
|
27
|
+
body: body_data,
|
28
|
+
attachment: attachment_data
|
31
29
|
}
|
32
|
-
|
33
|
-
|
30
|
+
end
|
31
|
+
|
32
|
+
def body_data
|
33
|
+
mail.body.parts.present? ? mail.body.parts[0].body.to_s : mail.body.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
def attachment_data
|
37
|
+
attachments = {}
|
38
|
+
mail.attachments.each { |attachment| attachments[attachment.filename] = attachment.body }
|
39
|
+
attachments
|
40
|
+
end
|
41
|
+
|
42
|
+
def headers
|
43
|
+
options[:headers]
|
44
|
+
end
|
34
45
|
end
|
data/lib/mailpy/version.rb
CHANGED
metadata
CHANGED
@@ -1,35 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailpy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nasrul Gunawan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-23 00:00:00.000000000 Z
|
12
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: 5.2.4
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 5.2.4.4
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 5.2.4
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 5.2.4.4
|
33
13
|
- !ruby/object:Gem::Dependency
|
34
14
|
name: httparty
|
35
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,7 +38,7 @@ dependencies:
|
|
58
38
|
- - ">="
|
59
39
|
- !ruby/object:Gem::Version
|
60
40
|
version: '0'
|
61
|
-
description:
|
41
|
+
description: Action Mailer Adapter for Send Email Through HTTP APIs.
|
62
42
|
email:
|
63
43
|
- nasrul.remaza@gmail.com
|
64
44
|
executables: []
|