sendgrid-ruby 0.0.2 → 0.0.3

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: 9dedc1735da8ee2a09e97d3555e92b63fd631526
4
- data.tar.gz: 29028865ccff1abe7dec82a570942229b7489c9a
3
+ metadata.gz: 852d4c2923fcdcae762675d591aae678ff97664d
4
+ data.tar.gz: 95acbc4f1b36c036fceac5cda5eba764718021b0
5
5
  SHA512:
6
- metadata.gz: 7ea857ca795888f80c853713d7a5ceb145d11d387f0a03e389b9e762ca089b576c68c7c5ed48e79d9c154d60296108e88df746dc2db81e778ea328c2228fe754
7
- data.tar.gz: 77f7f2b3f6db200b02b3faff9e3434f7a219de75f326ec03838436589008be37c13f8e8f646c2217cf1343f9fa3f93437dbc647421084b48bcccc87db4f8c66f
6
+ metadata.gz: abd3afa7292e24ef33ea86f70515a49f9a81b40484fc3c6f88ad37b430d00f42bbb0bee6f7aa3d50384d34055afd9738d66df170772f6cc4f298219c6b89d27b
7
+ data.tar.gz: 9c77400d124690b7deb810e760d1f1f3dcc6c35d8cf8a908a04205eeb8738d3591d341d13361e3b78f9803ab281db61c701f7a34796124a11a7b2c2020be6b7f
data/README.md CHANGED
@@ -26,7 +26,14 @@ Create a new client with your SendGrid Username and Password.
26
26
  ```ruby
27
27
  require 'sendgrid-ruby'
28
28
 
29
+ # As a hash
29
30
  client = SendGrid::Client.new(api_user: 'SENDGRID_USERNAME', api_key: 'SENDGRID_PASSWORD')
31
+
32
+ # Or as a block
33
+ client = SendGrid::Client.new do |c|
34
+ c.api_user = 'SENDGRID_USERNAME'
35
+ c.api_key = 'SENDGRID_PASSWORD'
36
+ end
30
37
  ```
31
38
 
32
39
  Create a new Mail object and send:
@@ -69,21 +76,185 @@ params = {
69
76
  }
70
77
  ```
71
78
 
72
- #### Using the X-SMTPAPI Header
73
79
 
74
- To utilize the X-SMTPAPI header, we have directly integrated the [smtpapi-ruby](https://github.com/SendGridJP/smtpapi-ruby) gem. To initialize, you have two options:
80
+ #### Setting Params
81
+
82
+ Params can be set in the usual Ruby ways, including a block or a hash.
83
+
84
+ ````ruby
85
+ mail = SendGrid::Mail.new do |m|
86
+ m.to = 'rbin@sendgrid.com'
87
+ m.from = 'taco@rbin.codes'
88
+ end
89
+
90
+ client.send(SendGrid::Mail.new(to: 'rbin@sendgrid.com', from: 'taco@cat.limo'))
91
+ ````
92
+
93
+ #### :to
94
+
95
+ Using the **:to** param, we can pass a single email address as a string, or an array of email address strings.
96
+
97
+ ````ruby
98
+ mail = SendGrid::Mail.new
99
+ mail.to = 'taco@rbin.codes'
100
+ # or
101
+ mail.to = ['Example Dude <example@email.com>', 'john@email.com']
102
+ # or
103
+ mail.to = ['rbin@sendgrid.com', 'taco@cat.limo']
104
+ ````
105
+
106
+ #### :from
107
+
108
+ ```ruby
109
+ mail = SendGrid::Mail.new
110
+ mail.from = 'me@sendgrid.com'
111
+ ```
112
+
113
+ #### :cc
114
+
115
+ As with **:to**, **:cc** can take a single string or an array of strings.
116
+
117
+ ```ruby
118
+ mail = SendGrid::Mail.new
119
+ mail.cc = ['robin@sendgrid.com', 'taco@cat.limo']
120
+ ```
121
+
122
+ #### :bcc
123
+
124
+ As with **:to** and **:cc**, **:bcc** can take a single string or an array of strings.
125
+
126
+ ```ruby
127
+ mail = SendGrid::Mail.new
128
+ mail.bcc = ['robin@sendgrid.com', 'taco@cat.limo']
129
+ ```
130
+
131
+ #### :subject
132
+
133
+ ```ruby
134
+ mail = SendGrid::Mail.new
135
+ mail.subject = 'This is a subject string'
136
+ ```
137
+
138
+ ### Email Bodies:
139
+ #### :text
140
+
141
+ Using the **:text** param allows us to add plain text to our email body.
142
+
143
+ ```ruby
144
+ mail = SendGrid::Mail.new
145
+ mail.text = 'WHATTUP KITTY CAT!?'
146
+ ```
147
+
148
+ #### :html
149
+
150
+ Using the **:html** param allows us to add html content to our email body.
151
+ ```ruby
152
+ mail = SendGrid::Mail.new
153
+ mail.html = '<html><body>Stuff in here, yo!</body></html>'
154
+ ```
155
+
156
+
157
+ ## Using SendGrid's X-SMTPAPI Header
158
+
159
+ To utilize the X-SMTPAPI header, we have directly integrated the [smtpapi-ruby](https://github.com/SendGridJP/smtpapi-ruby) gem.
160
+
161
+ #### add_to
162
+
163
+ You can directly generate an x-smtpapi add_to header instead of using to *:to* param. ***Please note, this will override all params.***
164
+
165
+ ```ruby
166
+ mail = SendGrid::Mail.new
167
+ mail.smtpapi.add_to('me@rbin.codes')
168
+ mail.smtpapi.add_to('eddiez@otheremail.com')
169
+ ```
170
+
171
+ #### set_tos
172
+
173
+ ```ruby
174
+ mail.smtpapi.set_tos(['rbin@cat.codes', 'eddie@taco.bell'])
175
+ ```
176
+
177
+ #### add_substitution
178
+
179
+ ```ruby
180
+ mail = SendGrid::Mail.new
181
+ mail.smtpapi.add_substitution('keep', array('secret')) # sub = {keep: ['secret']}
182
+ mail.smtpapi.add_substitution('other', array('one', 'two')) # sub = {keep: ['secret'], other: ['one', 'two']}
183
+ ```
184
+
185
+ #### set_substitutions
186
+
187
+ ```ruby
188
+ mail = SendGrid::Mail.new
189
+ mail.smtpapi.set_substitutions({'keep' => 'secret'}) # sub = {keep: ['secret']}
190
+ ```
191
+
192
+ #### add_unique_arg
75
193
 
76
- Create your own and pass it in to the initialize method:
77
194
  ```ruby
78
- header = Smtpapi::Header.new
79
- # Do things to the header
80
- header.add_substitution('keep', ['secret'])
81
- mail = SendGrid::Mail.new(smtpapi: header)
195
+ mail = SendGrid::Mail.new
196
+ mail.smtpapi.add_unique_arg('cat', 'dogs')
82
197
  ```
83
- Or use the one that we create and expose:
198
+
199
+ #### set_unique_args
200
+
84
201
  ```ruby
85
202
  mail = SendGrid::Mail.new
86
- mail.smtpapi.add_substitution('keep', ['secret'])
203
+ mail.smtpapi.set_unique_args({'cow' => 'chicken'})
204
+ mail.smtpapi.set_unique_args({'dad' => 'proud'})
205
+ ```
206
+
207
+ #### add_category
208
+
209
+ ```ruby
210
+ mail = SendGrid::Mail.new
211
+ mail.smtpapi.add_category('tactics') # category = ['tactics']
212
+ mail.smtpapi.add_category('advanced') # category = ['tactics', 'advanced']
213
+ ```
214
+
215
+ #### set_categories
216
+
217
+ ```ruby
218
+ mail = SendGrid::Mail.new
219
+ mail.smtpapi.set_categories(['tactics', 'advanced']) # category = ['tactics', 'advanced']
220
+ ```
221
+
222
+ #### add_section
223
+
224
+ ```ruby
225
+ mail = SendGrid::Mail.new
226
+ mail.smtpapi.add_section('-charge-', 'This ship is useless.'])
227
+ mail.smtpapi.add_section('-bomber-', 'Only for sad vikings.'])
228
+ ```
229
+
230
+ #### set_sections
231
+
232
+ ```ruby
233
+ mail = SendGrid::Mail.new
234
+ mail.smtpapi.set_sections({'-charge-' => 'This ship is useless.'})
235
+ ```
236
+
237
+ #### add_filter
238
+
239
+ ```ruby
240
+ mail = SendGrid::Mail.new
241
+ mail.smtpapi.add_filter('footer', 'enable', 1)
242
+ mail.smtpapi.add_filter('footer', 'text/html', '<strong>boo</strong>')
243
+ ```
244
+
245
+ #### set_filters
246
+
247
+ ```ruby
248
+ mail = SendGrid::Mail.new
249
+ filter = {
250
+ 'footer' => {
251
+ 'setting' => {
252
+ 'enable' => 1,
253
+ "text/plain" => 'You can haz footers!'
254
+ }
255
+ }
256
+ }
257
+ mail.smtpapi.set_filters(filter)
87
258
  ```
88
259
 
89
260
  ## Contributing
data/lib/sendgrid-ruby.rb CHANGED
@@ -6,15 +6,17 @@ require 'rest-client'
6
6
 
7
7
  module SendGrid
8
8
  class Client
9
- attr_reader :api_user, :api_key, :host, :endpoint
9
+ attr_accessor :api_user, :api_key, :host, :endpoint
10
10
 
11
- def initialize(params)
12
- @api_user = params.fetch(:api_user)
13
- @api_key = params.fetch(:api_key)
11
+ def initialize(params = {})
12
+ @api_user = params.fetch(:api_user, nil)
13
+ @api_key = params.fetch(:api_key, nil)
14
14
  @host = params.fetch(:host, 'https://api.sendgrid.com')
15
15
  @endpoint = params.fetch(:endpoint, '/api/mail.send.json')
16
16
  @conn = params.fetch(:conn, create_conn)
17
17
  @user_agent = params.fetch(:user_agent, 'sendgrid/' + SendGrid::VERSION + ';ruby')
18
+ yield self if block_given?
19
+ raise SendGrid::Exception.new('api_user and api_key are required') unless @api_user && @api_key
18
20
  end
19
21
 
20
22
  def send(mail)
@@ -1,3 +1,3 @@
1
1
  module SendGrid
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  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: 0.0.2
4
+ version: 0.0.3
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: 2014-08-07 00:00:00.000000000 Z
12
+ date: 2014-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: smtpapi
@@ -140,7 +140,6 @@ files:
140
140
  - lib/sendgrid/mail.rb
141
141
  - lib/sendgrid/version.rb
142
142
  - sendgrid-ruby.gemspec
143
- - test.rb
144
143
  homepage: http://github.com/sendgrid/sendgrid-ruby
145
144
  licenses:
146
145
  - MIT
@@ -165,5 +164,4 @@ rubygems_version: 2.4.1
165
164
  signing_key:
166
165
  specification_version: 4
167
166
  summary: Official SendGrid Gem
168
- test_files:
169
- - test.rb
167
+ test_files: []
data/test.rb DELETED
@@ -1,7 +0,0 @@
1
- require './lib/sendgrid-ruby.rb'
2
-
3
- client = SendGrid::Client.new ENV['SENDGRID_USERNAME'], ENV['SENDGRID_PASSWORD']
4
- email = SendGrid::Mail.new(from: 'root@mail.doesnotscale.com', subject: 'Test', text: 'Body of sexy')
5
- email.add_to 'eddiezane@sendgrid.com'
6
- email.add_to 'rbin@sendgrid.com'
7
- puts client.send(email)