sendgrid-ruby 1.0.3 → 1.0.4
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/CHANGELOG.md +4 -0
- data/example.rb +4 -2
- data/lib/sendgrid/mail.rb +35 -7
- data/lib/sendgrid/version.rb +1 -1
- data/spec/lib/sendgrid_spec.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe49ac48dbbef01dbbe18d96e06ed7af349d6858
|
4
|
+
data.tar.gz: 6a722af6c7b10747a1859200da527b22f75f5303
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0a8b7a4a6ccf9a7ac503911f2ed89e6a48c628956c3f7ac8f94256f8c8d25b86e67727a3c69d972f1cae3e872fd46e1d0b118aff1c9399fb6f808efe0b893b5
|
7
|
+
data.tar.gz: 7b963bf04a0388e59b4d8ec357c3b15e037b579ca2e038d2489455aa0ef2c765f0bc062642585cad270eb3ea8d8766375116ec343079abf183589ee583ae7123
|
data/CHANGELOG.md
CHANGED
data/example.rb
CHANGED
@@ -22,9 +22,11 @@ mail = SendGrid::Mail.new do |m|
|
|
22
22
|
m.to = 'elmer.thomas@sendgrid.com'
|
23
23
|
m.from = 'elmer@thinkingserious.com'
|
24
24
|
m.subject = 'Hello world!'
|
25
|
-
m.text = 'I heard you like
|
25
|
+
m.text = 'I heard you like the beach.'
|
26
|
+
m.html = 'I heard you like the beach <div><img src="cid:beach"></div>'
|
26
27
|
end
|
27
|
-
mail.
|
28
|
+
mail.add_content('/tmp/beach.jpg', 'beach')
|
29
|
+
mail.add_attachment('/tmp/report.pdf', 'report.pdf')
|
28
30
|
result = client.send(mail)
|
29
31
|
puts result.code
|
30
32
|
puts result.body
|
data/lib/sendgrid/mail.rb
CHANGED
@@ -5,7 +5,7 @@ require 'mimemagic'
|
|
5
5
|
module SendGrid
|
6
6
|
class Mail
|
7
7
|
attr_accessor :to, :to_name, :from, :from_name, :subject, :text, :html, :cc,
|
8
|
-
:bcc, :reply_to, :date, :smtpapi, :attachments
|
8
|
+
:bcc, :reply_to, :date, :smtpapi, :attachments, :content
|
9
9
|
|
10
10
|
def initialize(params = {})
|
11
11
|
params.each do |k, v|
|
@@ -103,6 +103,17 @@ module SendGrid
|
|
103
103
|
def attachments
|
104
104
|
@attachments ||= []
|
105
105
|
end
|
106
|
+
|
107
|
+
def contents
|
108
|
+
@contents ||= []
|
109
|
+
end
|
110
|
+
|
111
|
+
def add_content(path, cid)
|
112
|
+
mime_type = MimeMagic.by_path(path)
|
113
|
+
file = Faraday::UploadIO.new(path, mime_type)
|
114
|
+
name ||= File.basename(file)
|
115
|
+
contents << {file: file, cid: cid, name: name}
|
116
|
+
end
|
106
117
|
|
107
118
|
def smtpapi
|
108
119
|
@smtpapi ||= Smtpapi::Header.new
|
@@ -123,7 +134,8 @@ module SendGrid
|
|
123
134
|
:text => text,
|
124
135
|
:html => html,
|
125
136
|
:'x-smtpapi' => smtpapi.to_json,
|
126
|
-
:
|
137
|
+
:content => ({":default"=>"0"} unless contents.empty?),
|
138
|
+
:files => ({":default"=>"0"} unless attachments.empty? and contents.empty?)
|
127
139
|
# If I don't define a default value, I get a Nil error when
|
128
140
|
# in attachments.each do |file|
|
129
141
|
#:files => ({} unless attachments.empty?)
|
@@ -132,13 +144,29 @@ module SendGrid
|
|
132
144
|
payload.delete(:'x-smtpapi') if payload[:'x-smtpapi'] == '{}'
|
133
145
|
|
134
146
|
payload[:to] = payload[:from] if payload[:to].nil? and not smtpapi.to.empty?
|
135
|
-
|
136
|
-
return payload if attachments.empty?
|
137
147
|
|
138
|
-
attachments.
|
139
|
-
|
148
|
+
unless attachments.empty?
|
149
|
+
attachments.each do |file|
|
150
|
+
payload[:files][file[:name]] = file[:file]
|
151
|
+
end
|
152
|
+
if payload[:files].has_key?(":default")
|
153
|
+
payload[:files].delete(":default")
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
unless contents.empty?
|
158
|
+
contents.each do |content|
|
159
|
+
payload[:content][content[:name]] = content[:cid]
|
160
|
+
payload[:files][content[:name]] = content[:file]
|
161
|
+
end
|
162
|
+
if payload[:content].has_key?(":default")
|
163
|
+
payload[:content].delete(":default")
|
164
|
+
end
|
140
165
|
end
|
141
|
-
|
166
|
+
|
167
|
+
puts payload[:files]
|
168
|
+
puts payload[:content]
|
169
|
+
|
142
170
|
payload
|
143
171
|
end
|
144
172
|
# rubocop:enable Style/HashSyntax
|
data/lib/sendgrid/version.rb
CHANGED
data/spec/lib/sendgrid_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendgrid-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robin Johnson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-10-
|
12
|
+
date: 2015-10-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: smtpapi
|
@@ -242,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
242
242
|
version: '0'
|
243
243
|
requirements: []
|
244
244
|
rubyforge_project:
|
245
|
-
rubygems_version: 2.4.
|
245
|
+
rubygems_version: 2.4.8
|
246
246
|
signing_key:
|
247
247
|
specification_version: 4
|
248
248
|
summary: Official SendGrid Gem
|