sendgrid-ruby 6.5.2 → 6.6.0

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
  SHA256:
3
- metadata.gz: e9ae3c96f2f17a8c259ea3f8e369e19c37bb8764074abe57a2cbf9af9e14879e
4
- data.tar.gz: 2bd8adf75c2e77b81c5c8d5f6c3e01cb4d8a52ea25252bdea2e24b8cbb9dbaa2
3
+ metadata.gz: 24757e772b52f0b9e130a824d65bea991c3fe5966f705cd3c2b67fdb8b1ade0e
4
+ data.tar.gz: 972ea7b52d490fce2ddb97315356965fab0001e1511087834979620cbeb118a9
5
5
  SHA512:
6
- metadata.gz: 5e6c60136a7aac529987dc16543daa49da5ad7f65120ab994e41f66f00a86665e68aeea7990089893d39f43161d4601ebc08df37f05264b9dc967a169f3fdb7b
7
- data.tar.gz: f940ee99e5254db6ae88e5bc6297ec16f941ad6bf2f1e619c1cefc1605cf9577c8a838ce0423e2ba8dc7e58f875f88aedb287a1ef50e59e4676491cc0e1011d6
6
+ metadata.gz: af9a46c70ff25fadfce7458b64a75e0255063d7f082ff8b9d9f4bbff9f0aa3136969864b717f6f01666ee1c04c354a3bb03afc9dc3620de26ffb4b63e0011002
7
+ data.tar.gz: 7992f9c04da91c16f76eee4cfd6860df83584046c00cff6a3b3f1b5ac0318e2bde8c8f2ee1329016bc28d0fd7c62a0c92d56bedf71805bfb86a5a6436f85035a
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ [2021-11-03] Version 6.6.0
5
+ --------------------------
6
+ **Library - Feature**
7
+ - [PR #473](https://github.com/sendgrid/sendgrid-ruby/pull/473): update tests, use-cases, examples and implementation for From personalization. Thanks to [@beebzz](https://github.com/beebzz)!
8
+
9
+
4
10
  [2021-10-18] Version 6.5.2
5
11
  --------------------------
6
12
  **Library - Docs**
@@ -32,7 +32,7 @@ def kitchen_sink
32
32
  personalization.add_bcc(Email.new(email: 'test6@example.com', name: 'Example User'))
33
33
  # Note, the domain of the from email property specified in any personalization must
34
34
  # match the domain of the from email property specified at root level
35
- personalization.from = Email.new(email: 'alias@example.com', name: "My alias")
35
+ personalization.add_from(Email.new(email: 'alias@example.com', name: "My alias"))
36
36
  personalization.subject = 'Hello World from the Personalized Twilio SendGrid Ruby Library'
37
37
  personalization.add_header(Header.new(key: 'X-Test', value: 'True'))
38
38
  personalization.add_header(Header.new(key: 'X-Mock', value: 'False'))
@@ -2,10 +2,10 @@ require 'json'
2
2
 
3
3
  module SendGrid
4
4
  class Personalization
5
- attr_reader :tos, :ccs, :bccs, :headers, :substitutions, :custom_args,
5
+ attr_reader :tos, :from, :ccs, :bccs, :headers, :substitutions, :custom_args,
6
6
  :dynamic_template_data
7
7
 
8
- attr_accessor :send_at, :subject, :from
8
+ attr_accessor :send_at, :subject
9
9
 
10
10
  def initialize
11
11
  @tos = []
@@ -26,6 +26,10 @@ module SendGrid
26
26
  @tos << to.to_json
27
27
  end
28
28
 
29
+ def add_from(from)
30
+ @from = from.to_json
31
+ end
32
+
29
33
  def add_cc(cc)
30
34
  raise DuplicatePersonalizationError if duplicate?(cc)
31
35
 
@@ -1,3 +1,3 @@
1
1
  module SendGrid
2
- VERSION = '6.5.2'.freeze
2
+ VERSION = '6.6.0'.freeze
3
3
  end
@@ -45,6 +45,19 @@ class TestPersonalization < Minitest::Test
45
45
  end
46
46
  end
47
47
 
48
+ def test_add_from
49
+ @personalization = Personalization.new
50
+ @personalization.add_from(Email.new(email: 'from1@example.com', name: 'Example Sender'))
51
+ expected_json = {
52
+ 'from' => {
53
+ 'email' => 'from1@example.com',
54
+ 'name' => 'Example Sender'
55
+ }
56
+ }
57
+
58
+ assert_equal @personalization.to_json, expected_json
59
+ end
60
+
48
61
  def test_add_cc
49
62
  @personalization = Personalization.new
50
63
  @personalization.add_cc(Email.new(email: 'test1@example.com', name: 'Example User'))
@@ -33,7 +33,7 @@ class TestAPI < MiniTest::Test
33
33
  assert_equal(test_headers, sg.request_headers)
34
34
  assert_equal('v3', sg.version)
35
35
  assert_equal(subuser, sg.impersonate_subuser)
36
- assert_equal('6.5.2', SendGrid::VERSION)
36
+ assert_equal('6.6.0', SendGrid::VERSION)
37
37
  assert_instance_of(SendGrid::Client, sg.client)
38
38
  assert_equal({}, sg.http_options)
39
39
  end
data/use-cases/README.md CHANGED
@@ -5,6 +5,7 @@ Please [open an issue](https://github.com/sendgrid/sendgrid-ruby/issues) or [mak
5
5
  # Email Use Cases
6
6
  * [Transactional Templates](transactional-templates.md)
7
7
  * [Legacy Templates](legacy-templates.md)
8
+ * [Personalizations](personalizations.md)
8
9
 
9
10
  # Twilio Use Cases
10
11
  * [Twilio Setup](twilio-setup.md)
@@ -0,0 +1,34 @@
1
+ # Personalizations
2
+
3
+ This example demonstrates how to send multiple emails with personalizations. For further documentation, refer to [the SendGrid docs](https://docs.sendgrid.com/for-developers/sending-email/personalizations).
4
+
5
+ ```ruby
6
+ require 'sendgrid-ruby'
7
+ include SendGrid
8
+
9
+ # Note that the domain for all From addresses must match
10
+ mail = Mail.new
11
+ mail.from = Email.new(email: 'test@example.com')
12
+ mail.add_content(Content.new(type: 'text/plain', value: 'Some test text'))
13
+ mail.subject = 'Personalized Test Email'
14
+
15
+ personalization = Personalization.new
16
+ personalization.add_to(Email.new(email: 'test1@example.com'))
17
+ mail.add_personalization(personalization)
18
+
19
+ personalization2 = Personalization.new
20
+ personalization2.add_to(Email.new(email: 'test2@example.com'))
21
+ personalization2.add_from(Email.new(email: 'test3@example.com'))
22
+ mail.add_personalization(personalization2)
23
+
24
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
25
+ begin
26
+ response = sg.client.mail._("send").post(request_body: mail.to_json)
27
+ rescue Exception => e
28
+ puts e.message
29
+ end
30
+
31
+ puts response.status_code
32
+ puts response.body
33
+ puts response.headers
34
+ ```
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: 6.5.2
4
+ version: 6.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elmer Thomas
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-10-18 00:00:00.000000000 Z
13
+ date: 2021-11-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ruby_http_client
@@ -300,6 +300,7 @@ files:
300
300
  - use-cases/domain-authentication.md
301
301
  - use-cases/email-statistics.md
302
302
  - use-cases/legacy-templates.md
303
+ - use-cases/personalizations.md
303
304
  - use-cases/sms.md
304
305
  - use-cases/transactional-templates.md
305
306
  - use-cases/twilio-email.md