sendgrid-ruby 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6430c97ce833bb11b86ed69d969f9f37dca211cf
4
- data.tar.gz: 54d826be8c3d7d4533166e2cbf0fd5bf4b85567f
3
+ metadata.gz: fe49ac48dbbef01dbbe18d96e06ed7af349d6858
4
+ data.tar.gz: 6a722af6c7b10747a1859200da527b22f75f5303
5
5
  SHA512:
6
- metadata.gz: 99daaa4e54c8f71f2d127201d9c08e9f102008b8d13ff1f71f20d460db728101260a5b6ffd95e41a67cf10baa9b9466c36a9beb888feff75b395a591911b10a4
7
- data.tar.gz: fef29993e6322e3b838e52639a7ca3573b7acd5e28303868a8551cde06071a2244620a0db344b8b27439376fb4f3e79dc8de1539c92c583dbbe28ba666aea618
6
+ metadata.gz: d0a8b7a4a6ccf9a7ac503911f2ed89e6a48c628956c3f7ac8f94256f8c8d25b86e67727a3c69d972f1cae3e872fd46e1d0b118aff1c9399fb6f808efe0b893b5
7
+ data.tar.gz: 7b963bf04a0388e59b4d8ec357c3b15e037b579ca2e038d2489455aa0ef2c765f0bc062642585cad270eb3ea8d8766375116ec343079abf183589ee583ae7123
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [1.0.5] - 2015-10-06
5
+ ### Added
6
+ Inline content support
7
+
4
8
  ## [1.0.3] - 2015-10-01
5
9
  ### Fixed
6
10
  Payload 'to' attribute fix for smtpapi
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 pineapple.'
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.add_attachment('/tmp/report.pdf', 'july_report.pdf')
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
- :files => ({":default"=>"0"} unless attachments.empty?)
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.each do |file|
139
- payload[:files][file[:name]] = file[:file]
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
- payload[:files].delete(":default")
166
+
167
+ puts payload[:files]
168
+ puts payload[:content]
169
+
142
170
  payload
143
171
  end
144
172
  # rubocop:enable Style/HashSyntax
@@ -1,3 +1,3 @@
1
1
  module SendGrid
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe 'SendGrid' do
4
4
  it 'should have a version' do
5
- expect(SendGrid::VERSION).to eq('1.0.3')
5
+ expect(SendGrid::VERSION).to eq('1.0.4')
6
6
  end
7
7
  end
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.3
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-01 00:00:00.000000000 Z
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.5
245
+ rubygems_version: 2.4.8
246
246
  signing_key:
247
247
  specification_version: 4
248
248
  summary: Official SendGrid Gem