sendgrid-ruby 4.3.3 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -1
  3. data/CHANGELOG.md +20 -1
  4. data/README.md +4 -4
  5. data/USE_CASES.md +5 -5
  6. data/examples/helpers/mail/example.rb +37 -37
  7. data/lib/sendgrid-ruby.rb +20 -0
  8. data/lib/sendgrid/helpers/mail/asm.rb +33 -0
  9. data/lib/sendgrid/helpers/mail/attachment.rb +63 -0
  10. data/lib/sendgrid/helpers/mail/bcc_settings.rb +33 -0
  11. data/lib/sendgrid/helpers/mail/bypass_list_management.rb +43 -0
  12. data/lib/sendgrid/helpers/mail/category.rb +28 -0
  13. data/lib/sendgrid/helpers/mail/click_tracking.rb +33 -0
  14. data/lib/sendgrid/helpers/mail/content.rb +33 -0
  15. data/lib/sendgrid/helpers/mail/custom_arg.rb +24 -0
  16. data/lib/sendgrid/helpers/mail/email.rb +33 -0
  17. data/lib/sendgrid/helpers/mail/footer.rb +43 -0
  18. data/lib/sendgrid/helpers/mail/ganalytics.rb +74 -0
  19. data/lib/sendgrid/helpers/mail/header.rb +24 -0
  20. data/lib/sendgrid/helpers/mail/mail.rb +30 -857
  21. data/lib/sendgrid/helpers/mail/mail_settings.rb +63 -0
  22. data/lib/sendgrid/helpers/mail/open_tracking.rb +33 -0
  23. data/lib/sendgrid/helpers/mail/personalization.rb +75 -0
  24. data/lib/sendgrid/helpers/mail/section.rb +24 -0
  25. data/lib/sendgrid/helpers/mail/spam_check.rb +43 -0
  26. data/lib/sendgrid/helpers/mail/subscription_tracking.rb +53 -0
  27. data/lib/sendgrid/helpers/mail/substitution.rb +24 -0
  28. data/lib/sendgrid/helpers/mail/tracking_settings.rb +53 -0
  29. data/lib/sendgrid/version.rb +1 -1
  30. data/test/sendgrid/helpers/mail/test_category.rb +27 -0
  31. data/test/sendgrid/helpers/mail/test_mail.rb +170 -52
  32. data/test/sendgrid/helpers/mail/test_personalizations.rb +146 -0
  33. data/test/sendgrid/test_sendgrid-ruby.rb +1 -1
  34. metadata +27 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83955f77f1e93c80a05e5d032940419529128ba7
4
- data.tar.gz: d901ce541307f08ac44a499dc846aa14dbd30b50
3
+ metadata.gz: a23133f8c4095f9f190145c808636a48bfd7307c
4
+ data.tar.gz: 0066b643ab7820a2444a8463e2817a9c76826522
5
5
  SHA512:
6
- metadata.gz: c4b15198a85c4a7699322963b53e431ed4f1b2603884542a1155a078791565ba319c359ec67f8babd52d70f3680231c3b711d1df398eddcf993b32c3709ba0ba
7
- data.tar.gz: c2a8deff3ed44c3e994690dffc5c473330abbf60712c7db16fdab8c5e8995c20d3efd2077152ca59cb84be19aed3f54ac95e07b3a4fc895c2db3486f7802d9ec
6
+ metadata.gz: 9a493f33a268e47cbbeacb127f8a85fca38dd63da8a4b65522595e8eb44767c93f62711d7d90a52d5289555394e37cf0d261de6bbfeab2dae6df49a4889c0a3d
7
+ data.tar.gz: c23996c075c861b7aaac71e324c381f05fe5921dc1b07f41f03ac3538a48e0ce34d671ff38e8036a152afe90c0c8e9cbb2332c5856b24267b722b712123e8c6c
@@ -1,6 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2
3
+ - 2.2.6
4
+ - 2.3.4
5
+ - 2.4.1
4
6
  gemfile:
5
7
  - gemfiles/Sinatra_1.gemfile
6
8
  - gemfiles/Sinatra_2.gemfile
@@ -1,6 +1,25 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [5.0.0] - 2017-05-27
5
+ ### BREAKING CHANGE
6
+ - #108 Fix unexpected `Mail` `#categories`, `#categories=` behavior
7
+ - Fixed Issue #95 Refactor Mail Helper Array Assignments
8
+ - `personalization.to` becomes `personalization.add_to()`
9
+ - `personalization.cc` becomes `personalization.add_cc()`
10
+ - `personalization.bcc` becomes `personalization.add_bcc()`
11
+ - `personalization.headers` becomes `personalization.add_header()`
12
+ - `personalization.substitutions` becomes `personalization.add_substitution()`
13
+ - `personalization.custom_args` becomes `personalization.add_custom_arg()`
14
+ - `mail.personalizations` becomes `mail.add_personalization()`
15
+ - `mail.contents` becomes `mail.add_content()`
16
+ - `mail.attachments` becomes `mail.attachment()`
17
+ - `mail.sections` becomes `mail.add_section()`
18
+ - `mail.headers` becomes `mail.add_header()`
19
+ - `mail.categories` becomes `mail.add_category()`
20
+ - `mail.custom_args` becomes `mail.custom_args()`
21
+ - For a full example of usage, please [see here](https://github.com/sendgrid/sendgrid-ruby/blob/master/examples/helpers/mail/example.rb#L21).
22
+
4
23
  ## [4.3.3] - 2017-5-2
5
24
  ### Update
6
25
  - #157: Specify required ruby version as '>= 2.2'
@@ -32,7 +51,7 @@ All notable changes to this project will be documented in this file.
32
51
 
33
52
  ## [4.2.0] - 2017-4-10 ##
34
53
  ### Added
35
- - #148: Set api_key to empty string
54
+ - #148: Set api_key to empty string
36
55
  - This makes creating an API key for a SendGrid subuser who does not have an API key easier. See #146 for details
37
56
  - Thanks to [Adam Beck](https://github.com/Gwash3189) for the pull request!
38
57
 
data/README.md CHANGED
@@ -81,9 +81,9 @@ require 'sendgrid-ruby'
81
81
  include SendGrid
82
82
 
83
83
  from = Email.new(email: 'test@example.com')
84
- subject = 'Hello World from the SendGrid Ruby Library!'
85
84
  to = Email.new(email: 'test@example.com')
86
- content = Content.new(type: 'text/plain', value: 'Hello, Email!')
85
+ subject = 'Sending with SendGrid is Fun'
86
+ content = Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
87
87
  mail = Mail.new(from, subject, to, content)
88
88
 
89
89
  sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
@@ -111,7 +111,7 @@ data = JSON.parse('{
111
111
  "email": "test@example.com"
112
112
  }
113
113
  ],
114
- "subject": "Hello World from the SendGrid Ruby Library!"
114
+ "subject": "Sending with SendGrid is Fun"
115
115
  }
116
116
  ],
117
117
  "from": {
@@ -120,7 +120,7 @@ data = JSON.parse('{
120
120
  "content": [
121
121
  {
122
122
  "type": "text/plain",
123
- "value": "Hello, Email!"
123
+ "value": "and easy to do anywhere, even with Ruby"
124
124
  }
125
125
  ]
126
126
  }')
@@ -51,11 +51,11 @@ mail = Mail.new
51
51
  mail.from = Email.new(email: 'test@example.com')
52
52
  mail.subject = 'I\'m replacing the subject tag'
53
53
  personalization = Personalization.new
54
- personalization.to = Email.new(email: 'test@example.com')
55
- personalization.substitutions = Substitution.new(key: '-name-', value: 'Example User')
56
- personalization.substitutions = Substitution.new(key: '-city-', value: 'Denver')
57
- mail.personalizations = personalization
58
- mail.contents = Content.new(type: 'text/html', value: 'I\'m replacing the <strong>body tag</strong>')
54
+ personalization.add_to(Email.new(email: 'test@example.com'))
55
+ personalization.add_substitution(Substitution.new(key: '-name-', value: 'Example User'))
56
+ personalization.add_substitution(Substitution.new(key: '-city-', value: 'Denver'))
57
+ mail.add_personalization(personalization)
58
+ mail.add_content(Content.new(type: 'text/html', value: 'I\'m replacing the <strong>body tag</strong>'))
59
59
  mail.template_id = '13b8f94f-bcae-4ec6-b752-70d6cb59f932'
60
60
 
61
61
  sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
@@ -23,41 +23,41 @@ def kitchen_sink
23
23
  mail.from = Email.new(email: 'test@example.com')
24
24
  mail.subject = 'Hello World from the SendGrid Ruby Library'
25
25
  personalization = Personalization.new
26
- personalization.to = Email.new(email: 'test1@example.com', name: 'Example User')
27
- personalization.to = Email.new(email: 'test2@example.com', name: 'Example User')
28
- personalization.cc = Email.new(email: 'test3@example.com', name: 'Example User')
29
- personalization.cc = Email.new(email: 'test4@example.com', name: 'Example User')
30
- personalization.bcc = Email.new(email: 'test5@example.com', name: 'Example User')
31
- personalization.bcc = Email.new(email: 'test6@example.com', name: 'Example User')
26
+ personalization.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
27
+ personalization.add_to(Email.new(email: 'test2@example.com', name: 'Example User'))
28
+ personalization.add_cc(Email.new(email: 'test3@example.com', name: 'Example User'))
29
+ personalization.add_cc(Email.new(email: 'test4@example.com', name: 'Example User'))
30
+ personalization.add_bcc(Email.new(email: 'test5@example.com', name: 'Example User'))
31
+ personalization.add_bcc(Email.new(email: 'test6@example.com', name: 'Example User'))
32
32
  personalization.subject = 'Hello World from the Personalized SendGrid Ruby Library'
33
- personalization.headers = Header.new(key: 'X-Test', value: 'True')
34
- personalization.headers = Header.new(key: 'X-Mock', value: 'False')
35
- personalization.substitutions = Substitution.new(key: '%name%', value: 'Example User')
36
- personalization.substitutions = Substitution.new(key: '%city%', value: 'Denver')
37
- personalization.custom_args = CustomArg.new(key: 'user_id', value: '343')
38
- personalization.custom_args = CustomArg.new(key: 'type', value: 'marketing')
33
+ personalization.add_header(Header.new(key: 'X-Test', value: 'True'))
34
+ personalization.add_header(Header.new(key: 'X-Mock', value: 'False'))
35
+ personalization.add_substitution(Substitution.new(key: '%name%', value: 'Example User'))
36
+ personalization.add_substitution(Substitution.new(key: '%city%', value: 'Denver'))
37
+ personalization.add_custom_arg(CustomArg.new(key: 'user_id', value: '343'))
38
+ personalization.add_custom_arg(CustomArg.new(key: 'type', value: 'marketing'))
39
39
  personalization.send_at = 1443636843
40
- mail.personalizations = personalization
40
+ mail.add_personalization(personalization)
41
41
 
42
42
  personalization2 = Personalization.new
43
- personalization2.to = Email.new(email: 'test1@example.com', name: 'Example User')
44
- personalization2.to = Email.new(email: 'test2@example.com', name: 'Example User')
45
- personalization2.cc = Email.new(email: 'test3@example.com', name: 'Example User')
46
- personalization2.cc = Email.new(email: 'test4@example.com', name: 'Example User')
47
- personalization2.bcc = Email.new(email: 'test5@example.com', name: 'Example User')
48
- personalization2.bcc = Email.new(email: 'test6@example.com', name: 'Example User')
43
+ personalization2.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
44
+ personalization2.add_to(Email.new(email: 'test2@example.com', name: 'Example User'))
45
+ personalization2.add_cc(Email.new(email: 'test3@example.com', name: 'Example User'))
46
+ personalization2.add_cc(Email.new(email: 'test4@example.com', name: 'Example User'))
47
+ personalization2.add_bcc(Email.new(email: 'test5@example.com', name: 'Example User'))
48
+ personalization2.add_bcc(Email.new(email: 'test6@example.com', name: 'Example User'))
49
49
  personalization2.subject = 'Hello World from the Personalized SendGrid Ruby Library'
50
- personalization2.headers = Header.new(key: 'X-Test', value: 'True')
51
- personalization2.headers = Header.new(key: 'X-Mock', value: 'False')
52
- personalization2.substitutions = Substitution.new(key: '%name%', value: 'Example User')
53
- personalization2.substitutions = Substitution.new(key: '%city%', value: 'Denver')
54
- personalization2.custom_args = CustomArg.new(key: 'user_id', value: '343')
55
- personalization2.custom_args = CustomArg.new(key: 'type', value: 'marketing')
50
+ personalization2.add_header(Header.new(key: 'X-Test', value: 'True'))
51
+ personalization2.add_header(Header.new(key: 'X-Mock', value: 'False'))
52
+ personalization2.add_substitution(Substitution.new(key: '%name%', value: 'Example User'))
53
+ personalization2.add_substitution(Substitution.new(key: '%city%', value: 'Denver'))
54
+ personalization2.add_custom_arg(CustomArg.new(key: 'user_id', value: '343'))
55
+ personalization2.add_custom_arg(CustomArg.new(key: 'type', value: 'marketing'))
56
56
  personalization2.send_at = 1443636843
57
57
  mail.personalizations = personalization2
58
58
 
59
- mail.contents = Content.new(type: 'text/plain', value: 'some text here')
60
- mail.contents = Content.new(type: 'text/html', value: '<html><body>some text here</body></html>')
59
+ mail.add_content(Content.new(type: 'text/plain', value: 'some text here'))
60
+ mail.add_content(Content.new(type: 'text/html', value: '<html><body>some text here</body></html>'))
61
61
 
62
62
  attachment = Attachment.new
63
63
  attachment.content = 'TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12'
@@ -66,7 +66,7 @@ def kitchen_sink
66
66
  attachment.disposition = 'attachment'
67
67
  attachment.content_id = 'Balance Sheet'
68
68
 
69
- mail.attachments = attachment
69
+ mail.add_attachment(attachment)
70
70
 
71
71
  attachment2 = Attachment.new
72
72
  attachment2.content = 'BwdW'
@@ -74,21 +74,21 @@ def kitchen_sink
74
74
  attachment2.filename = 'banner.png'
75
75
  attachment2.disposition = 'inline'
76
76
  attachment2.content_id = 'Banner'
77
- mail.attachments = attachment2
77
+ mail.add_attachment(attachment2)
78
78
 
79
79
  mail.template_id = '13b8f94f-bcae-4ec6-b752-70d6cb59f932'
80
80
 
81
- mail.sections = Section.new(key: '%section1%', value: 'Substitution Text for Section 1')
82
- mail.sections = Section.new(key: '%section2%', value: 'Substitution Text for Section 2')
81
+ mail.add_section(Section.new(key: '%section1%', value: 'Substitution Text for Section 1'))
82
+ mail.add_section(Section.new(key: '%section2%', value: 'Substitution Text for Section 2'))
83
83
 
84
- mail.headers = Header.new(key: 'X-Test3', value: 'test3')
85
- mail.headers = Header.new(key: 'X-Test4', value: 'test4')
84
+ mail.add_header(Header.new(key: 'X-Test3', value: 'test3'))
85
+ mail.add_header(Header.new(key: 'X-Test4', value: 'test4'))
86
86
 
87
- mail.categories = Category.new(name: 'May')
88
- mail.categories = Category.new(name: '2016')
87
+ mail.add_category(Category.new(name: 'May'))
88
+ mail.add_category(Category.new(name: '2016'))
89
89
 
90
- mail.custom_args = CustomArg.new(key: 'campaign', value: 'welcome')
91
- mail.custom_args = CustomArg.new(key: 'weekday', value: 'morning')
90
+ mail.add_custom_arg(CustomArg.new(key: 'campaign', value: 'welcome'))
91
+ mail.add_custom_arg(CustomArg.new(key: 'weekday', value: 'morning'))
92
92
 
93
93
  mail.send_at = 1443636842
94
94
 
@@ -1,4 +1,24 @@
1
1
  require_relative 'sendgrid/client'
2
2
  require_relative 'sendgrid/version'
3
+ require_relative 'sendgrid/helpers/mail/asm'
4
+ require_relative 'sendgrid/helpers/mail/attachment'
5
+ require_relative 'sendgrid/helpers/mail/bcc_settings'
6
+ require_relative 'sendgrid/helpers/mail/bypass_list_management'
7
+ require_relative 'sendgrid/helpers/mail/category'
8
+ require_relative 'sendgrid/helpers/mail/click_tracking'
9
+ require_relative 'sendgrid/helpers/mail/content'
10
+ require_relative 'sendgrid/helpers/mail/custom_arg'
11
+ require_relative 'sendgrid/helpers/mail/email'
12
+ require_relative 'sendgrid/helpers/mail/footer'
13
+ require_relative 'sendgrid/helpers/mail/ganalytics'
14
+ require_relative 'sendgrid/helpers/mail/header'
3
15
  require_relative 'sendgrid/helpers/mail/mail'
16
+ require_relative 'sendgrid/helpers/mail/mail_settings'
17
+ require_relative 'sendgrid/helpers/mail/open_tracking'
18
+ require_relative 'sendgrid/helpers/mail/personalization'
19
+ require_relative 'sendgrid/helpers/mail/section'
20
+ require_relative 'sendgrid/helpers/mail/spam_check'
21
+ require_relative 'sendgrid/helpers/mail/subscription_tracking'
22
+ require_relative 'sendgrid/helpers/mail/substitution'
23
+ require_relative 'sendgrid/helpers/mail/tracking_settings'
4
24
  require_relative 'sendgrid/helpers/settings/settings'
@@ -0,0 +1,33 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class ASM
5
+ def initialize(group_id: nil, groups_to_display: nil)
6
+ @group_id = group_id
7
+ @groups_to_display = groups_to_display
8
+ end
9
+
10
+ def group_id=(group_id)
11
+ @group_id = group_id
12
+ end
13
+
14
+ def group_id
15
+ @group_id
16
+ end
17
+
18
+ def groups_to_display=(groups_to_display)
19
+ @groups_to_display = groups_to_display
20
+ end
21
+
22
+ def groups_to_display
23
+ @groups_to_display
24
+ end
25
+
26
+ def to_json(*)
27
+ {
28
+ 'group_id' => self.group_id,
29
+ 'groups_to_display' => self.groups_to_display
30
+ }.delete_if { |_, value| value.to_s.strip == '' }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,63 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class Attachment
5
+ def initialize
6
+ @content = nil
7
+ @type = nil
8
+ @filename = nil
9
+ @disposition = nil
10
+ @content_id = nil
11
+ end
12
+
13
+ def content=(content)
14
+ @content = content
15
+ end
16
+
17
+ def content
18
+ @content
19
+ end
20
+
21
+ def type=(type)
22
+ @type = type
23
+ end
24
+
25
+ def type
26
+ @type
27
+ end
28
+
29
+ def filename=(filename)
30
+ @filename = filename
31
+ end
32
+
33
+ def filename
34
+ @filename
35
+ end
36
+
37
+ def disposition=(disposition)
38
+ @disposition = disposition
39
+ end
40
+
41
+ def disposition
42
+ @disposition
43
+ end
44
+
45
+ def content_id=(content_id)
46
+ @content_id = content_id
47
+ end
48
+
49
+ def content_id
50
+ @content_id
51
+ end
52
+
53
+ def to_json(*)
54
+ {
55
+ 'content' => self.content,
56
+ 'type' => self.type,
57
+ 'filename' => self.filename,
58
+ 'disposition' => self.disposition,
59
+ 'content_id' => self.content_id
60
+ }.delete_if { |_, value| value.to_s.strip == '' }
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,33 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class BccSettings
5
+ def initialize(enable: nil, email: nil)
6
+ @enable = enable
7
+ @email = email
8
+ end
9
+
10
+ def enable=(enable)
11
+ @enable = enable
12
+ end
13
+
14
+ def enable
15
+ @enable
16
+ end
17
+
18
+ def email=(email)
19
+ @email = email
20
+ end
21
+
22
+ def email
23
+ @email
24
+ end
25
+
26
+ def to_json(*)
27
+ {
28
+ 'enable' => self.enable,
29
+ 'email' => self.email
30
+ }.delete_if { |_, value| value.to_s.strip == '' }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,43 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class BypassListManagement
5
+ def initialize(enable: nil)
6
+ @enable = enable
7
+ end
8
+
9
+ def enable=(enable)
10
+ @enable = enable
11
+ end
12
+
13
+ def enable
14
+ @enable
15
+ end
16
+
17
+ def to_json(*)
18
+ {
19
+ 'enable' => self.enable
20
+ }.delete_if { |_, value| value.to_s.strip == '' }
21
+ end
22
+ end
23
+
24
+ class SandBoxMode
25
+ def initialize(enable: nil)
26
+ @enable = enable
27
+ end
28
+
29
+ def enable=(enable)
30
+ @enable = enable
31
+ end
32
+
33
+ def enable
34
+ @enable
35
+ end
36
+
37
+ def to_json(*)
38
+ {
39
+ 'enable' => self.enable
40
+ }.delete_if { |_, value| value.to_s.strip == '' }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,28 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class Category
5
+ attr_accessor :name
6
+
7
+ def initialize(name: nil)
8
+ @name = name
9
+ end
10
+
11
+ def name=(name)
12
+ @name = name
13
+ end
14
+
15
+ def name
16
+ @name
17
+ end
18
+
19
+ def to_json(*)
20
+ {
21
+ 'category' => name
22
+ }.delete_if { |_, value| value.to_s.strip == '' }
23
+ end
24
+
25
+ alias :category :name
26
+ alias :category= :name=
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class ClickTracking
5
+ def initialize(enable: nil, enable_text: nil)
6
+ @enable = enable
7
+ @enable_text = enable_text
8
+ end
9
+
10
+ def enable=(enable)
11
+ @enable = enable
12
+ end
13
+
14
+ def enable
15
+ @enable
16
+ end
17
+
18
+ def enable_text=(enable_text)
19
+ @enable_text = enable_text
20
+ end
21
+
22
+ def enable_text
23
+ @enable_text
24
+ end
25
+
26
+ def to_json(*)
27
+ {
28
+ 'enable' => self.enable,
29
+ 'enable_text' => self.enable_text
30
+ }.delete_if { |_, value| value.to_s.strip == '' }
31
+ end
32
+ end
33
+ end