dm_courier 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +6 -3
- data/lib/dm_courier/service_locator.rb +1 -0
- data/lib/dm_courier/services/sendgrid.rb +79 -0
- data/lib/dm_courier/services/sparkpost.rb +2 -2
- data/lib/dm_courier/version.rb +1 -1
- data/rails_courier.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b8269252a4a2061684ca025fb7b4d50f26b2efa
|
4
|
+
data.tar.gz: c79802dd3c0616b5685e85a2e37db96e770a97d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29d8d0e630c7710ccae8417f752f7adc81c01d4b591cfcd1cb3647203a6e2154b5c7eaa37a626242c289563535cd6685cf72786517808ae37ac4a543a443e02a
|
7
|
+
data.tar.gz: 01ce7c66c0a1197448f9d7f3147cc28e2d3e6bda09de06802c4f9a7e46b3324d73f79e9dc7bd53ce2c55ff8f7f7c38f18ac1fb2a3e6f85ccd5acfaa7f2905ca3
|
data/.travis.yml
CHANGED
@@ -9,7 +9,7 @@ notifications:
|
|
9
9
|
on_failure: always
|
10
10
|
addons:
|
11
11
|
code_climate:
|
12
|
-
repo_token:
|
12
|
+
repo_token: 40f3b0db4e0b69a31588221de4aaca19db947e47c838f9eac9b6f4615cf92bab
|
13
13
|
script:
|
14
14
|
- bundle exec rubocop
|
15
15
|
- bundle exec rake spec
|
data/README.md
CHANGED
@@ -7,8 +7,9 @@
|
|
7
7
|
[![Test Coverage](https://codeclimate.com/github/sumoners/dm_courier/badges/coverage.svg)](https://codeclimate.com/github/sumoners/dm_courier/coverage)
|
8
8
|
[![Code Climate](https://codeclimate.com/github/sumoners/dm_courier/badges/gpa.svg)](https://codeclimate.com/github/sumoners/dm_courier)
|
9
9
|
|
10
|
-
Stick with just one Gem and be free to choose your email delivery service.
|
11
|
-
Courier allows you to change
|
10
|
+
Stick with just one Gem and be free to choose your email delivery service. DM
|
11
|
+
Courier (Delivery Method Courier) allows you to easily change the deliery method
|
12
|
+
as you wish.
|
12
13
|
|
13
14
|
## Rails Setup
|
14
15
|
|
@@ -65,7 +66,7 @@ Option | Mailer Support | Description
|
|
65
66
|
`track_opens` | true | whether or not to turn on open tracking for the message<br />**Services:** mandrill, sparkpost
|
66
67
|
`track_url_without_query_string` | true | whether or not to strip the query string from URLs when aggregating tracked URL data<br />**Services:** mandrill
|
67
68
|
`log_content` | true | set to false to remove content logging for sensitive emails<br />**Services:** mandrill
|
68
|
-
`bcc_address` | true | an optional address to receive an exact copy of each recipient's email<br />**Services:** mandrill
|
69
|
+
`bcc_address` | true | an optional address to receive an exact copy of each recipient's email<br />**Services:** mandrill, sendgrid
|
69
70
|
`return_path_domain` | true | a custom domain to use for the messages's return-path<br />**Services:** mandrill, sparkpost
|
70
71
|
`signing_domain` | true | a custom domain to use for SPF/DKIM signing (for "via" or "on behalf of" in email clients)<br />**Services:** mandrill
|
71
72
|
`subaccount` | true | the unique id of a subaccount - must already exist or will fail with an error<br />**Services:** mandrill
|
@@ -87,6 +88,8 @@ service API. Because of that some options have different names:
|
|
87
88
|
|
88
89
|
> TODO: Sparkpost service implementation does not support BCC emails yet.
|
89
90
|
|
91
|
+
### SendGrid
|
92
|
+
|
90
93
|
## Development & Feedback
|
91
94
|
|
92
95
|
Questions or problems? Please use the issue tracker. If you would like to
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require "sendgrid-ruby"
|
2
|
+
require "base64"
|
3
|
+
|
4
|
+
require "dm_courier/message_helper"
|
5
|
+
|
6
|
+
module DMCourier
|
7
|
+
module Services
|
8
|
+
class Sendgrid
|
9
|
+
include DMCourier::Services::MessageHelper
|
10
|
+
|
11
|
+
attr_reader :api_key, :mail, :options
|
12
|
+
|
13
|
+
def initialize(mail, options = {})
|
14
|
+
@mail = mail
|
15
|
+
@api_key = options.fetch(:api_key)
|
16
|
+
@options = options
|
17
|
+
end
|
18
|
+
|
19
|
+
def name
|
20
|
+
:sendgrid
|
21
|
+
end
|
22
|
+
|
23
|
+
def deliver!
|
24
|
+
sendgrid_api = ::SendGrid::Client.new(api_key)
|
25
|
+
sendgrid_api.send(sendgrid_message)
|
26
|
+
end
|
27
|
+
|
28
|
+
def sendgrid_message
|
29
|
+
message = { to: (mail[:to].formatted if mail[:to]),
|
30
|
+
cc: (mail[:cc].formatted if mail[:cc]),
|
31
|
+
bcc: return_string_value(:bcc_address),
|
32
|
+
from: from_email,
|
33
|
+
from_name: from_name,
|
34
|
+
subject: subject,
|
35
|
+
html: html_part,
|
36
|
+
text: text_part,
|
37
|
+
reply_to: reply_to }
|
38
|
+
|
39
|
+
message[:attachments] = regular_attachments
|
40
|
+
|
41
|
+
::SendGrid::Mail.new(message) do |mail|
|
42
|
+
inline_attachments.each do |attachment|
|
43
|
+
mail.contents << attachment
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def reply_to
|
51
|
+
value = mail["Reply-To"] || options[:reply_to]
|
52
|
+
value.to_s if value
|
53
|
+
end
|
54
|
+
|
55
|
+
def regular_attachments
|
56
|
+
mail.attachments.map do |attachment|
|
57
|
+
next if attachment.inline?
|
58
|
+
|
59
|
+
{ file: Faraday::UploadIO.new(StringIO.new(attachment.body.decoded),
|
60
|
+
attachment.mime_type,
|
61
|
+
attachment.filename),
|
62
|
+
name: attachment.filename }
|
63
|
+
end.compact
|
64
|
+
end
|
65
|
+
|
66
|
+
def inline_attachments
|
67
|
+
mail.attachments.map do |attachment|
|
68
|
+
next unless attachment.inline?
|
69
|
+
|
70
|
+
{ file: Faraday::UploadIO.new(StringIO.new(attachment.body.decoded),
|
71
|
+
attachment.mime_type,
|
72
|
+
attachment.filename),
|
73
|
+
cid: attachment.cid,
|
74
|
+
name: attachment.filename }
|
75
|
+
end.compact
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -91,7 +91,7 @@ module DMCourier
|
|
91
91
|
attachments(inline: false).map do |attachment|
|
92
92
|
{ name: attachment[:name],
|
93
93
|
type: attachment[:type],
|
94
|
-
|
94
|
+
data: attachment[:content] }
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -99,7 +99,7 @@ module DMCourier
|
|
99
99
|
attachments(inline: true).map do |attachment|
|
100
100
|
{ name: attachment[:name],
|
101
101
|
type: attachment[:type],
|
102
|
-
|
102
|
+
data: attachment[:content] }
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
data/lib/dm_courier/version.rb
CHANGED
data/rails_courier.gemspec
CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
|
27
27
|
spec.add_dependency "mandrill-api", "~> 1.0.53"
|
28
28
|
spec.add_dependency "sparkpost", "~> 0.1.2"
|
29
|
+
spec.add_dependency "sendgrid-ruby", "~> 1.1.6"
|
29
30
|
spec.add_dependency "http", "0.9.8"
|
30
31
|
|
31
32
|
spec.add_development_dependency "codeclimate-test-reporter", "~> 0.5"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm_courier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jaison Erick
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mandrill-api
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.1.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sendgrid-ruby
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.1.6
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.1.6
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: http
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -190,6 +204,7 @@ files:
|
|
190
204
|
- lib/dm_courier/railtie.rb
|
191
205
|
- lib/dm_courier/service_locator.rb
|
192
206
|
- lib/dm_courier/services/mandrill.rb
|
207
|
+
- lib/dm_courier/services/sendgrid.rb
|
193
208
|
- lib/dm_courier/services/sparkpost.rb
|
194
209
|
- lib/dm_courier/version.rb
|
195
210
|
- lib/monkey_patch/sparkpost/request.rb
|