sendgrid-ruby 1.0.0.alpha.1 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 151bbef80094a16705ac90105265586a3b297f72
4
- data.tar.gz: 978bc5da9b1f788440e1e7e55cb821a0864571da
3
+ metadata.gz: fe36a0b285a30dfac2804d6f3ac46d3ee0562a67
4
+ data.tar.gz: 1dab6a58bc0f677a75cce07a459afa925561db3f
5
5
  SHA512:
6
- metadata.gz: 6445b8feda2318bb755c4a0a448f3456610d2de94982ae223acee641e1c5a1ea4ac6177e94fd89fd46323434f71512221528f904a967738f5aed176c0634e6c7
7
- data.tar.gz: 379ae309fb47ad14331bc2747b226f016a865c8671d45567ab725eef5f2fdb8db4daf305ffba6143d3070b99302472863017484f860282b052b5d32116b18f6d
6
+ metadata.gz: 4a21dacb775797d79fc03f3b21eef8dff075cce772e14f7a7de4c29c79deb1274ce0dc471e435bc5543d7cb2d7aa700be8528cfbc459011cc0607867ed9b45be
7
+ data.tar.gz: bc714d2321f8d349b6388025f0f669113f5437ebd06a336b294bbc36096e3c9d6933b5e795f30c811216979961e7da2e8d4f7ac3a5002dd6574c9367b3de95ab
data/.env_sample ADDED
@@ -0,0 +1,3 @@
1
+ SENDGRID_USERNAME=your_sendgrid_username
2
+ SENDGRID_PASSWORD=your_sendgrid_password
3
+ SENDGRID_APIKEY=your_sendgrid_apikey
data/.gitignore CHANGED
@@ -11,6 +11,8 @@
11
11
  /test/tmp/
12
12
  /test/version_tmp/
13
13
  /tmp/
14
+ .env
15
+ test.rb
14
16
 
15
17
  ## Specific to RubyMotion:
16
18
  .dat*
data/.travis.yml CHANGED
@@ -12,9 +12,9 @@ notifications:
12
12
  Build %{build_number}</a> on branch <i>%{branch}</i> by %{author}: <strong>%{message}</strong>
13
13
  <a href="https://github.com/sendgrid/docs/commits/%{commit}">View on GitHub</a>'
14
14
  format: html
15
- notify: true
15
+ notify: false
16
16
  before_script:
17
17
  - bundle install
18
18
  script:
19
- - rubocop --fail-level=W
19
+ - rubocop --fail-level=E
20
20
  - rake
data/Gemfile CHANGED
@@ -1,2 +1,5 @@
1
+ gem 'dotenv-rails'
2
+ gem 'smtpapi'
3
+ gem 'rest-client'
1
4
  source 'https://rubygems.org'
2
5
  gemspec
data/README.md CHANGED
@@ -17,7 +17,7 @@ And then execute:
17
17
 
18
18
  $ bundle
19
19
 
20
- Or install it yourself as:
20
+ Or install it yourself using:
21
21
 
22
22
  $ gem install sendgrid-ruby
23
23
 
@@ -36,6 +36,11 @@ client = SendGrid::Client.new do |c|
36
36
  c.api_user = 'SENDGRID_USERNAME'
37
37
  c.api_key = 'SENDGRID_PASSWORD'
38
38
  end
39
+
40
+ # or as a block with the API key only #
41
+ client = SendGrid::Client.new do |c|
42
+ c.api_key = 'SENDGRID_APIKEY'
43
+ end
39
44
  ```
40
45
 
41
46
  Create a new Mail object and send:
@@ -51,7 +56,7 @@ puts client.send(mail)
51
56
  # {"message":"success"}
52
57
  ```
53
58
 
54
- You can also create a mail object with a hash:
59
+ You can also create a Mail object with a hash:
55
60
  ```ruby
56
61
  client.send(SendGrid::Mail.new(to: 'example@example.com', from: 'taco@cat.limo', subject: 'Hello world!', text: 'Hi there!', html: '<b>Hi there!</b>'))
57
62
 
@@ -60,7 +65,7 @@ client.send(SendGrid::Mail.new(to: 'example@example.com', from: 'taco@cat.limo',
60
65
 
61
66
  #### Attachments
62
67
 
63
- Attachments can be added to a mail object with the `add_attachment` method. The first parameter is the path to the file, the second (optional) parameter is the desired name of the file. If a file name is not provided, it will use the original filename.
68
+ Attachments can be added to a Mail object with the `add_attachment` method. The first parameter is the path to the file, the second (optional) parameter is the desired name of the file. If a file name is not provided, it will use the original filename.
64
69
  ```ruby
65
70
  mail.add_attachment('/tmp/report.pdf', 'july_report.pdf')
66
71
  ```
@@ -165,108 +170,35 @@ mail.html = '<html><body>Stuff in here, yo!</body></html>'
165
170
 
166
171
  ## Using SendGrid's X-SMTPAPI Header
167
172
 
168
- To utilize the X-SMTPAPI header, we have directly integrated the [smtpapi-ruby](https://github.com/SendGridJP/smtpapi-ruby) gem.
169
-
170
- #### add_to
171
-
172
- You can directly generate an x-smtpapi add_to header instead of using to *:to* param. ***Please note, this will override all params.***
173
-
174
- ```ruby
175
- mail = SendGrid::Mail.new
176
- mail.smtpapi.add_to('me@rbin.codes')
177
- mail.smtpapi.add_to('eddiez@otheremail.com')
178
- ```
179
-
180
- #### set_tos
181
-
182
- ```ruby
183
- mail.smtpapi.set_tos(['rbin@cat.codes', 'eddie@taco.bell'])
184
- ```
185
-
186
- #### add_substitution
187
173
 
188
- ```ruby
189
- mail = SendGrid::Mail.new
190
- mail.smtpapi.add_substitution('keep', array('secret')) # sub = {keep: ['secret']}
191
- mail.smtpapi.add_substitution('other', array('one', 'two')) # sub = {keep: ['secret'], other: ['one', 'two']}
192
- ```
193
-
194
- #### set_substitutions
174
+ <blockquote>
175
+ To utilize the X-SMTPAPI header, we have directly integrated the <a href="https://github.com/SendGridJP/smtpapi-ruby">SendGridJP/smtpapi-ruby</a> gem.
176
+ For more information, view our <a href=https://sendgrid.com/docs/API_Reference/SMTP_API/index.html>SMTPAPI docs page</a>.
177
+ </blockquote>
195
178
 
196
179
  ```ruby
197
- mail = SendGrid::Mail.new
198
- mail.smtpapi.set_substitutions({'keep' => 'secret'}) # sub = {keep: ['secret']}
199
- ```
200
180
 
201
- #### add_unique_arg
181
+ header = Smtpapi::Header.new
182
+ header.add_to(['john.doe@example.com', 'jane.doe@example.com'])
183
+ header.add_substitution('keep', ['secret']) # sub = {keep: ['secret']}
184
+ header.add_substitution('other', ['one', 'two']) # sub = {keep: ['secret'], other: ['one', 'two']}
185
+ header.add_unique_arg("unique_code", "8675309")
186
+ header.add_category("Newsletter")
187
+ header.add_filter('templates', 'enable', 1) # necessary for each time the template engine is used
188
+ header.add_filter('templates', 'template_id', '1234-5678-9100-abcd')
189
+ header.set_ip_pool("marketing_ip_pool")
190
+ mail.smtpapi = header
202
191
 
203
- ```ruby
204
- mail = SendGrid::Mail.new
205
- mail.smtpapi.add_unique_arg('cat', 'dogs')
206
192
  ```
193
+ ## Testing ##
207
194
 
208
- #### set_unique_args
195
+ `bundle exec rake test`
209
196
 
210
- ```ruby
211
- mail = SendGrid::Mail.new
212
- mail.smtpapi.set_unique_args({'cow' => 'chicken'})
213
- mail.smtpapi.set_unique_args({'dad' => 'proud'})
214
- ```
197
+ ## Deploying ##
215
198
 
216
- #### add_category
217
-
218
- ```ruby
219
- mail = SendGrid::Mail.new
220
- mail.smtpapi.add_category('tactics') # category = ['tactics']
221
- mail.smtpapi.add_category('advanced') # category = ['tactics', 'advanced']
222
- ```
223
-
224
- #### set_categories
225
-
226
- ```ruby
227
- mail = SendGrid::Mail.new
228
- mail.smtpapi.set_categories(['tactics', 'advanced']) # category = ['tactics', 'advanced']
229
- ```
230
-
231
- #### add_section
232
-
233
- ```ruby
234
- mail = SendGrid::Mail.new
235
- mail.smtpapi.add_section('-charge-', 'This ship is useless.'])
236
- mail.smtpapi.add_section('-bomber-', 'Only for sad vikings.'])
237
- ```
238
-
239
- #### set_sections
240
-
241
- ```ruby
242
- mail = SendGrid::Mail.new
243
- mail.smtpapi.set_sections({'-charge-' => 'This ship is useless.'})
244
- ```
245
-
246
- #### add_filter
247
-
248
- ```ruby
249
- mail = SendGrid::Mail.new
250
- mail.smtpapi.add_filter('footer', 'enable', 1)
251
- mail.smtpapi.add_filter('footer', 'text/html', '<strong>boo</strong>')
252
- ```
253
-
254
- #### set_filters
255
-
256
- ```ruby
257
- mail = SendGrid::Mail.new
258
- filter = {
259
- 'footer' => {
260
- 'setting' => {
261
- 'enable' => 1,
262
- "text/plain" => 'You can haz footers!'
263
- }
264
- }
265
- }
266
- mail.smtpapi.set_filters(filter)
267
- ```
199
+ `rake release`
268
200
 
269
- ## Contributing
201
+ ## Contributing ##
270
202
 
271
203
  1. Fork it ( https://github.com/[my-github-username]/sendgrid-ruby/fork )
272
204
  2. Create your feature branch (`git checkout -b my-new-feature`)
@@ -274,4 +206,4 @@ mail.smtpapi.set_filters(filter)
274
206
  4. Push to the branch (`git push origin my-new-feature`)
275
207
  5. Create a new Pull Request
276
208
 
277
- ***Hit up [@rbin](http://twitter.com/rbin) or [@eddiezane](http://twitter.com/eddiezane) on Twitter with any issues.***
209
+ ***Hit up [@rbin](http://twitter.com/rbin) or [@sendgrid](http://twitter.com/sendgrid) on Twitter with any issues.***
data/example.rb ADDED
@@ -0,0 +1,32 @@
1
+ # test using: ruby example.rb
2
+ # using ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
3
+ # attachment is sent but only a corrupted 1k file
4
+
5
+ require_relative "lib/sendgrid-ruby.rb"
6
+
7
+ require 'dotenv'
8
+ Dotenv.load
9
+
10
+ # sendgrid_username = ENV['SENDGRID_USERNAME']
11
+ # sendgrid_password = ENV['SENDGRID_PASSWORD']
12
+ sendgrid_apikey = ENV['SENDGRID_APIKEY']
13
+
14
+ # client = SendGrid::Client.new(api_user: sendgrid_username, api_key: sendgrid_password)
15
+
16
+ client = SendGrid::Client.new do |c|
17
+ # c.api_user = sendgrid_username
18
+ c.api_key = sendgrid_apikey
19
+ end
20
+
21
+ mail = SendGrid::Mail.new do |m|
22
+ m.to = 'elmer.thomas@sendgrid.com'
23
+ m.from = 'elmer@thinkingserious.com'
24
+ m.subject = 'Hello world!'
25
+ m.text = 'I heard you like pineapple.'
26
+ end
27
+ mail.add_attachment('/tmp/report.pdf', 'july_report.pdf')
28
+ result = client.send(mail)
29
+ puts result.code
30
+ puts result.body
31
+
32
+ # puts client.send(SendGrid::Mail.new(to: 'elmer.thomas@sendgrid.com', from: 'elmer@thinkingserious.com', subject: 'Hello world!', text: 'Hi there, testing from Ruby!', html: '<b>Hi there, testing from Ruby!</b>'))
File without changes
@@ -24,9 +24,8 @@ module SendGrid
24
24
  def send(mail)
25
25
  res = conn.post do |req|
26
26
  payload = mail.to_h
27
-
28
27
  req.url(endpoint)
29
-
28
+
30
29
  # Check if using username + password or API key
31
30
  if api_user
32
31
  # Username + password
@@ -35,12 +34,12 @@ module SendGrid
35
34
  # API key
36
35
  req.headers['Authorization'] = "Bearer #{api_key}"
37
36
  end
38
-
37
+
39
38
  req.body = payload
40
39
  end
41
-
40
+
42
41
  fail SendGrid::Exception, res.body if raise_exceptions? && res.status != 200
43
-
42
+
44
43
  SendGrid::Response.new(code: res.status, headers: res.headers, body: res.body)
45
44
  end
46
45
 
data/lib/sendgrid/mail.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'json'
2
2
  require 'smtpapi'
3
+ require 'mimemagic'
3
4
 
4
5
  module SendGrid
5
6
  class Mail
@@ -89,7 +90,8 @@ module SendGrid
89
90
  end
90
91
 
91
92
  def add_attachment(path, name = nil)
92
- file = File.new(path)
93
+ mime_type = MimeMagic.by_path(path)
94
+ file = Faraday::UploadIO.new(path, mime_type)
93
95
  name ||= File.basename(file)
94
96
  attachments << {file: file, name: name}
95
97
  end
@@ -121,18 +123,22 @@ module SendGrid
121
123
  :text => text,
122
124
  :html => html,
123
125
  :'x-smtpapi' => smtpapi.to_json,
124
- :files => ({} unless attachments.empty?)
126
+ :files => ({":default"=>"0"} unless attachments.empty?)
127
+ # If I don't define a default value, I get a Nil error when
128
+ # in attachments.each do |file|
129
+ #:files => ({} unless attachments.empty?)
125
130
  }.reject {|_, v| v.nil? || v.empty?}
126
131
 
127
132
  payload.delete(:'x-smtpapi') if payload[:'x-smtpapi'] == '{}'
128
133
 
129
- payload[:to] = payload[:from] unless payload[:to].nil? && smtpapi.to.empty?
134
+ payload[:to] = payload[:from] unless (not payload[:to].nil?) && smtpapi.to.empty?
130
135
 
131
136
  return payload if attachments.empty?
132
-
137
+
133
138
  attachments.each do |file|
134
139
  payload[:files][file[:name]] = file[:file]
135
140
  end
141
+ payload[:files].delete(":default")
136
142
  payload
137
143
  end
138
144
  # rubocop:enable Style/HashSyntax
@@ -1,3 +1,3 @@
1
1
  module SendGrid
2
- VERSION = '1.0.0.alpha.1'.freeze
2
+ VERSION = '1.0.2'
3
3
  end
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency 'smtpapi', '~> 0.1'
22
22
  spec.add_dependency 'faraday', '~> 0.9'
23
+ spec.add_dependency 'mimemagic'
23
24
  spec.add_development_dependency 'rake'
24
25
  spec.add_development_dependency 'rspec'
25
26
  spec.add_development_dependency 'rspec-nc'
@@ -57,7 +57,7 @@ describe 'SendGrid::Client' do
57
57
  client.send(mail)
58
58
 
59
59
  expect(WebMock).to have_requested(:post, 'https://api.sendgrid.com/api/mail.send.json')
60
- .with(body: 'api_key=abc123&api_user=foobar')
60
+ .with(body: 'api_key=abc123&api_user=foobar&to=')
61
61
  end
62
62
 
63
63
  it 'should raise a SendGrid::Exception if status is not 200' do
@@ -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.0.alpha.1')
5
+ expect(SendGrid::VERSION).to eq('1.0.2')
6
6
  end
7
7
  end
data/spec/spec_helper.rb CHANGED
@@ -1 +1 @@
1
- require_relative '../lib/sendgrid_ruby'
1
+ require_relative '../lib/sendgrid-ruby'
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.0.alpha.1
4
+ version: 1.0.2
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-06-05 00:00:00.000000000 Z
12
+ date: 2015-09-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: smtpapi
@@ -39,6 +39,20 @@ dependencies:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0.9'
42
+ - !ruby/object:Gem::Dependency
43
+ name: mimemagic
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: rake
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -185,6 +199,7 @@ executables: []
185
199
  extensions: []
186
200
  extra_rdoc_files: []
187
201
  files:
202
+ - ".env_sample"
188
203
  - ".gitignore"
189
204
  - ".rspec"
190
205
  - ".rubocop.yml"
@@ -194,12 +209,13 @@ files:
194
209
  - LICENSE.txt
195
210
  - README.md
196
211
  - Rakefile
212
+ - example.rb
213
+ - lib/sendgrid-ruby.rb
197
214
  - lib/sendgrid/client.rb
198
215
  - lib/sendgrid/exceptions.rb
199
216
  - lib/sendgrid/mail.rb
200
217
  - lib/sendgrid/response.rb
201
218
  - lib/sendgrid/version.rb
202
- - lib/sendgrid_ruby.rb
203
219
  - sendgrid-ruby.gemspec
204
220
  - spec/lib/sendgrid/client_spec.rb
205
221
  - spec/lib/sendgrid/mail_spec.rb
@@ -220,9 +236,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
220
236
  version: '0'
221
237
  required_rubygems_version: !ruby/object:Gem::Requirement
222
238
  requirements:
223
- - - ">"
239
+ - - ">="
224
240
  - !ruby/object:Gem::Version
225
- version: 1.3.1
241
+ version: '0'
226
242
  requirements: []
227
243
  rubyforge_project:
228
244
  rubygems_version: 2.4.5