sendgrid-ruby 6.2.0 → 6.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/config.yml +10 -0
  3. data/.github/workflows/test-and-deploy.yml +120 -0
  4. data/.gitignore +2 -0
  5. data/.rubocop.yml +8 -0
  6. data/.rubocop_todo.yml +127 -0
  7. data/CHANGELOG.md +147 -9
  8. data/CONTRIBUTING.md +11 -21
  9. data/Dockerfile +14 -0
  10. data/FIRST_TIMERS.md +79 -0
  11. data/Gemfile +0 -1
  12. data/ISSUE_TEMPLATE.md +5 -1
  13. data/{LICENSE.md → LICENSE} +1 -1
  14. data/Makefile +9 -2
  15. data/PULL_REQUEST_TEMPLATE.md +5 -5
  16. data/README.md +23 -31
  17. data/Rakefile +2 -3
  18. data/TROUBLESHOOTING.md +17 -5
  19. data/USAGE.md +146 -39
  20. data/examples/accesssettings/accesssettings.rb +9 -12
  21. data/examples/alerts/alerts.rb +8 -11
  22. data/examples/apikeys/apikeys.rb +12 -15
  23. data/examples/asm/asm.rb +27 -30
  24. data/examples/browsers/browsers.rb +0 -3
  25. data/examples/campaigns/campaigns.rb +29 -32
  26. data/examples/categories/categories.rb +0 -3
  27. data/examples/clients/clients.rb +1 -4
  28. data/examples/contactdb/contactdb.rb +63 -66
  29. data/examples/devices/devices.rb +0 -3
  30. data/examples/emailactivity/emailactivity.rb +52 -0
  31. data/examples/geo/geo.rb +0 -3
  32. data/examples/helpers/eventwebhook/example.rb +16 -0
  33. data/examples/helpers/mail/example.rb +24 -13
  34. data/examples/helpers/settings/example.rb +1 -1
  35. data/examples/helpers/stats/example.rb +4 -4
  36. data/examples/ips/ips.rb +19 -22
  37. data/examples/mail/mail.rb +72 -75
  38. data/examples/mailboxproviders/mailboxproviders.rb +0 -3
  39. data/examples/mailsettings/mailsettings.rb +21 -24
  40. data/examples/partnersettings/partnersettings.rb +3 -6
  41. data/examples/scopes/scopes.rb +8 -10
  42. data/examples/senderauthentication/senderauthentication.rb +41 -44
  43. data/examples/senders/senders.rb +28 -31
  44. data/examples/stats/stats.rb +0 -3
  45. data/examples/subusers/subusers.rb +17 -20
  46. data/examples/suppression/suppression.rb +15 -18
  47. data/examples/templates/templates.rb +29 -31
  48. data/examples/trackingsettings/trackingsettings.rb +14 -17
  49. data/examples/user/user.rb +41 -44
  50. data/lib/rack/sendgrid_webhook_verification.rb +55 -0
  51. data/lib/sendgrid/base_interface.rb +8 -4
  52. data/lib/sendgrid/helpers/eventwebhook/eventwebhook.rb +50 -0
  53. data/lib/sendgrid/helpers/inbound/README.md +5 -5
  54. data/lib/sendgrid/helpers/inbound/app.rb +2 -2
  55. data/lib/sendgrid/helpers/inbound/public/index.html +1 -1
  56. data/lib/sendgrid/helpers/inbound/send.rb +3 -3
  57. data/lib/sendgrid/helpers/ip_management/ip_management.rb +1 -1
  58. data/lib/sendgrid/helpers/mail/README.md +3 -3
  59. data/lib/sendgrid/helpers/mail/asm.rb +6 -18
  60. data/lib/sendgrid/helpers/mail/attachment.rb +12 -42
  61. data/lib/sendgrid/helpers/mail/bcc_settings.rb +6 -18
  62. data/lib/sendgrid/helpers/mail/bypass_list_management.rb +8 -18
  63. data/lib/sendgrid/helpers/mail/category.rb +2 -2
  64. data/lib/sendgrid/helpers/mail/click_tracking.rb +6 -18
  65. data/lib/sendgrid/helpers/mail/content.rb +4 -3
  66. data/lib/sendgrid/helpers/mail/custom_arg.rb +6 -10
  67. data/lib/sendgrid/helpers/mail/email.rb +10 -5
  68. data/lib/sendgrid/helpers/mail/footer.rb +7 -27
  69. data/lib/sendgrid/helpers/mail/ganalytics.rb +10 -54
  70. data/lib/sendgrid/helpers/mail/header.rb +6 -10
  71. data/lib/sendgrid/helpers/mail/mail.rb +32 -48
  72. data/lib/sendgrid/helpers/mail/mail_settings.rb +9 -25
  73. data/lib/sendgrid/helpers/mail/open_tracking.rb +6 -18
  74. data/lib/sendgrid/helpers/mail/personalization.rb +40 -27
  75. data/lib/sendgrid/helpers/mail/section.rb +6 -10
  76. data/lib/sendgrid/helpers/mail/spam_check.rb +7 -27
  77. data/lib/sendgrid/helpers/mail/subscription_tracking.rb +8 -36
  78. data/lib/sendgrid/helpers/mail/substitution.rb +6 -10
  79. data/lib/sendgrid/helpers/mail/tracking_settings.rb +8 -20
  80. data/lib/sendgrid/helpers/permissions/scope.rb +2 -2
  81. data/lib/sendgrid/helpers/settings/README.md +2 -2
  82. data/lib/sendgrid/helpers/settings/settings.rb +1 -1
  83. data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +3 -5
  84. data/lib/sendgrid/helpers/stats/metrics.rb +5 -5
  85. data/lib/sendgrid/sendgrid.rb +4 -3
  86. data/lib/sendgrid/twilio_email.rb +1 -1
  87. data/lib/sendgrid/version.rb +1 -1
  88. data/lib/sendgrid-ruby.rb +2 -0
  89. data/mail_helper_v3.md +12 -12
  90. data/sendgrid-ruby.gemspec +8 -8
  91. data/spec/fixtures/event_webhook.rb +22 -0
  92. data/spec/rack/sendgrid_webhook_verification_spec.rb +142 -0
  93. data/spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb +105 -0
  94. data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +3 -3
  95. data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +3 -3
  96. data/spec/sendgrid/helpers/settings/settings_spec.rb +2 -2
  97. data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +3 -3
  98. data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +3 -3
  99. data/spec/sendgrid/helpers/stats/email_stats_spec.rb +22 -23
  100. data/spec/sendgrid/helpers/stats/metrics_spec.rb +19 -20
  101. data/spec/sendgrid/helpers/stats/stats_response_spec.rb +22 -23
  102. data/spec/spec_helper.rb +3 -1
  103. data/static/img/github-fork.png +0 -0
  104. data/static/img/github-sign-up.png +0 -0
  105. data/test/sendgrid/helpers/mail/test_attachment.rb +4 -6
  106. data/test/sendgrid/helpers/mail/test_category.rb +0 -2
  107. data/test/sendgrid/helpers/mail/test_email.rb +17 -10
  108. data/test/sendgrid/helpers/mail/test_mail.rb +101 -102
  109. data/test/sendgrid/helpers/mail/test_personalizations.rb +145 -92
  110. data/test/sendgrid/permissions/test_scopes.rb +1 -3
  111. data/test/sendgrid/test_sendgrid-ruby.rb +1964 -1986
  112. data/twilio_sendgrid_logo.png +0 -0
  113. data/use-cases/README.md +17 -0
  114. data/use-cases/domain-authentication.md +5 -0
  115. data/use-cases/email-statistics.md +52 -0
  116. data/use-cases/legacy-templates.md +98 -0
  117. data/use-cases/personalizations.md +34 -0
  118. data/use-cases/sms.md +39 -0
  119. data/use-cases/transactional-templates.md +111 -0
  120. data/use-cases/twilio-email.md +13 -0
  121. data/use-cases/twilio-setup.md +54 -0
  122. metadata +69 -34
  123. data/.codeclimate.yml +0 -21
  124. data/.travis.yml +0 -40
  125. data/USE_CASES.md +0 -405
  126. data/docker/Dockerfile +0 -12
  127. data/docker/README.md +0 -30
  128. data/test/prism.sh +0 -42
@@ -11,7 +11,7 @@ module SendGrid
11
11
  def unassigned
12
12
  response = @sendgrid_client.ips.get
13
13
  ips = JSON.parse(response.body)
14
- ips.select {|ip| ip.subusers.empty?}
14
+ ips.select { |ip| ip.subusers.empty? }
15
15
  end
16
16
  end
17
17
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Quick Start
4
4
 
5
- Run the [example](https://github.com/sendgrid/sendgrid-ruby/tree/master/examples/helpers/mail) (make sure you have set your environment variable to include your SENDGRID_API_KEY).
5
+ Run the [example](../../../../examples/helpers/mail) (make sure you have set your environment variable to include your SENDGRID_API_KEY).
6
6
 
7
7
  ```bash
8
8
  ruby examples/helpers/mail/example.rb
@@ -10,5 +10,5 @@ ruby examples/helpers/mail/example.rb
10
10
 
11
11
  ## Usage
12
12
 
13
- - See the [example](https://github.com/sendgrid/sendgrid-ruby/tree/master/examples/helpers/mail) for a complete working example.
14
- - [Documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/overview.html)
13
+ - See the [example](../../../../examples/helpers/mail) for a complete working example.
14
+ - [Documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html)
@@ -1,30 +1,18 @@
1
+ require 'json'
2
+
1
3
  module SendGrid
2
4
  class ASM
3
- def initialize(group_id: nil, groups_to_display: nil)
4
- @group_id = group_id
5
- @groups_to_display = groups_to_display
6
- end
5
+ attr_accessor :group_id, :groups_to_display
7
6
 
8
- def group_id=(group_id)
7
+ def initialize(group_id: nil, groups_to_display: nil)
9
8
  @group_id = group_id
10
- end
11
-
12
- def group_id
13
- @group_id
14
- end
15
-
16
- def groups_to_display=(groups_to_display)
17
9
  @groups_to_display = groups_to_display
18
10
  end
19
11
 
20
- def groups_to_display
21
- @groups_to_display
22
- end
23
-
24
12
  def to_json(*)
25
13
  {
26
- 'group_id' => self.group_id,
27
- 'groups_to_display' => self.groups_to_display
14
+ 'group_id' => group_id,
15
+ 'groups_to_display' => groups_to_display
28
16
  }.delete_if { |_, value| value.to_s.strip == '' }
29
17
  end
30
18
  end
@@ -2,6 +2,8 @@ require 'base64'
2
2
 
3
3
  module SendGrid
4
4
  class Attachment
5
+ attr_accessor :type, :filename, :disposition, :content_id
6
+
5
7
  def initialize
6
8
  @content = nil
7
9
  @type = nil
@@ -18,52 +20,20 @@ module SendGrid
18
20
  def content
19
21
  return @encoded_content if @encoded_content
20
22
 
21
- if @content.respond_to?(:read)
22
- @encoded_content = encode @content
23
- else
24
- @encoded_content = @content
25
- end
26
- end
27
-
28
- def type=(type)
29
- @type = type
30
- end
31
-
32
- def type
33
- @type
34
- end
35
-
36
- def filename=(filename)
37
- @filename = filename
38
- end
39
-
40
- def filename
41
- @filename
42
- end
43
-
44
- def disposition=(disposition)
45
- @disposition = disposition
46
- end
47
-
48
- def disposition
49
- @disposition
50
- end
51
-
52
- def content_id=(content_id)
53
- @content_id = content_id
54
- end
55
-
56
- def content_id
57
- @content_id
23
+ @encoded_content = if @content.respond_to?(:read)
24
+ encode @content
25
+ else
26
+ @content
27
+ end
58
28
  end
59
29
 
60
30
  def to_json(*)
61
31
  {
62
- 'content' => self.content,
63
- 'type' => self.type,
64
- 'filename' => self.filename,
65
- 'disposition' => self.disposition,
66
- 'content_id' => self.content_id
32
+ 'content' => content,
33
+ 'type' => type,
34
+ 'filename' => filename,
35
+ 'disposition' => disposition,
36
+ 'content_id' => content_id
67
37
  }.delete_if { |_, value| value.to_s.strip == '' }
68
38
  end
69
39
 
@@ -1,30 +1,18 @@
1
+ require 'json'
2
+
1
3
  module SendGrid
2
4
  class BccSettings
3
- def initialize(enable: nil, email: nil)
4
- @enable = enable
5
- @email = email
6
- end
5
+ attr_accessor :enable, :email
7
6
 
8
- def enable=(enable)
7
+ def initialize(enable: nil, email: nil)
9
8
  @enable = enable
10
- end
11
-
12
- def enable
13
- @enable
14
- end
15
-
16
- def email=(email)
17
9
  @email = email
18
10
  end
19
11
 
20
- def email
21
- @email
22
- end
23
-
24
12
  def to_json(*)
25
13
  {
26
- 'enable' => self.enable,
27
- 'email' => self.email
14
+ 'enable' => enable,
15
+ 'email' => email
28
16
  }.delete_if { |_, value| value.to_s.strip == '' }
29
17
  end
30
18
  end
@@ -1,40 +1,30 @@
1
+ require 'json'
2
+
1
3
  module SendGrid
2
4
  class BypassListManagement
3
- def initialize(enable: nil)
4
- @enable = enable
5
- end
5
+ attr_accessor :enable
6
6
 
7
- def enable=(enable)
7
+ def initialize(enable: nil)
8
8
  @enable = enable
9
9
  end
10
10
 
11
- def enable
12
- @enable
13
- end
14
-
15
11
  def to_json(*)
16
12
  {
17
- 'enable' => self.enable
13
+ 'enable' => enable
18
14
  }.delete_if { |_, value| value.to_s.strip == '' }
19
15
  end
20
16
  end
21
17
 
22
18
  class SandBoxMode
23
- def initialize(enable: nil)
24
- @enable = enable
25
- end
19
+ attr_accessor :enable
26
20
 
27
- def enable=(enable)
21
+ def initialize(enable: nil)
28
22
  @enable = enable
29
23
  end
30
24
 
31
- def enable
32
- @enable
33
- end
34
-
35
25
  def to_json(*)
36
26
  {
37
- 'enable' => self.enable
27
+ 'enable' => enable
38
28
  }.delete_if { |_, value| value.to_s.strip == '' }
39
29
  end
40
30
  end
@@ -12,7 +12,7 @@ module SendGrid
12
12
  }.delete_if { |_, value| value.to_s.strip == '' }
13
13
  end
14
14
 
15
- alias :category :name
16
- alias :category= :name=
15
+ alias category name
16
+ alias category= name=
17
17
  end
18
18
  end
@@ -1,30 +1,18 @@
1
+ require 'json'
2
+
1
3
  module SendGrid
2
4
  class ClickTracking
3
- def initialize(enable: nil, enable_text: nil)
4
- @enable = enable
5
- @enable_text = enable_text
6
- end
5
+ attr_accessor :enable, :enable_text
7
6
 
8
- def enable=(enable)
7
+ def initialize(enable: nil, enable_text: nil)
9
8
  @enable = enable
10
- end
11
-
12
- def enable
13
- @enable
14
- end
15
-
16
- def enable_text=(enable_text)
17
9
  @enable_text = enable_text
18
10
  end
19
11
 
20
- def enable_text
21
- @enable_text
22
- end
23
-
24
12
  def to_json(*)
25
13
  {
26
- 'enable' => self.enable,
27
- 'enable_text' => self.enable_text
14
+ 'enable' => enable,
15
+ 'enable_text' => enable_text
28
16
  }.delete_if { |_, value| value.to_s.strip == '' }
29
17
  end
30
18
  end
@@ -1,6 +1,7 @@
1
+ require 'json'
2
+
1
3
  module SendGrid
2
4
  class Content
3
-
4
5
  attr_accessor :type, :value
5
6
 
6
7
  def initialize(type: nil, value: nil)
@@ -10,8 +11,8 @@ module SendGrid
10
11
 
11
12
  def to_json(*)
12
13
  {
13
- 'type' => self.type,
14
- 'value' => self.value
14
+ 'type' => type,
15
+ 'value' => value
15
16
  }.delete_if { |_, value| value.to_s.strip == '' }
16
17
  end
17
18
  end
@@ -1,21 +1,17 @@
1
+ require 'json'
2
+
1
3
  module SendGrid
2
4
  class CustomArg
5
+ attr_accessor :custom_arg
6
+
3
7
  def initialize(key: nil, value: nil)
4
8
  @custom_arg = {}
5
- (key.nil? || value.nil?) ? @custom_arg = nil : @custom_arg[key.to_s] = value.to_s
6
- end
7
-
8
- def custom_arg=(custom_arg)
9
- @custom_arg = custom_arg
10
- end
11
-
12
- def custom_arg
13
- @custom_arg
9
+ key.nil? || value.nil? ? @custom_arg = nil : @custom_arg[key.to_s] = value.to_s
14
10
  end
15
11
 
16
12
  def to_json(*)
17
13
  {
18
- 'custom_arg' => self.custom_arg
14
+ 'custom_arg' => custom_arg
19
15
  }.delete_if { |_, value| value.to_s.strip == '' }
20
16
  end
21
17
  end
@@ -1,9 +1,12 @@
1
+ require 'json'
2
+
1
3
  module SendGrid
2
4
  class Email
3
-
4
5
  attr_accessor :email, :name
5
6
 
6
- def initialize(email: nil, name: nil)
7
+ # @param [String] email required e-mail address
8
+ # @param [String] name optionally personification
9
+ def initialize(email:, name: nil)
7
10
  if name
8
11
  @email = email
9
12
  @name = name
@@ -14,13 +17,15 @@ module SendGrid
14
17
 
15
18
  def split_email(email)
16
19
  split = /(?:(?<address>.+)\s)?<?(?<email>.+@[^>]+)>?/.match(email)
17
- return split[:email], split[:address]
20
+ raise ArgumentError, "email (#{email}) is invalid" unless split
21
+
22
+ [split[:email], split[:address]]
18
23
  end
19
24
 
20
25
  def to_json(*)
21
26
  {
22
- 'email' => self.email,
23
- 'name' => self.name
27
+ 'email' => email,
28
+ 'name' => name
24
29
  }.delete_if { |_, value| value.to_s.strip == '' }
25
30
  end
26
31
  end
@@ -1,40 +1,20 @@
1
+ require 'json'
2
+
1
3
  module SendGrid
2
4
  class Footer
5
+ attr_accessor :enable, :text, :html
6
+
3
7
  def initialize(enable: nil, text: nil, html: nil)
4
8
  @enable = enable
5
9
  @text = text
6
10
  @html = html
7
11
  end
8
12
 
9
- def enable=(enable)
10
- @enable = enable
11
- end
12
-
13
- def enable
14
- @enable
15
- end
16
-
17
- def text=(text)
18
- @text = text
19
- end
20
-
21
- def text
22
- @text
23
- end
24
-
25
- def html=(html)
26
- @html = html
27
- end
28
-
29
- def html
30
- @html
31
- end
32
-
33
13
  def to_json(*)
34
14
  {
35
- 'enable' => self.enable,
36
- 'text' => self.text,
37
- 'html' => self.html
15
+ 'enable' => enable,
16
+ 'text' => text,
17
+ 'html' => html
38
18
  }.delete_if { |_, value| value.to_s.strip == '' }
39
19
  end
40
20
  end
@@ -1,5 +1,9 @@
1
+ require 'json'
2
+
1
3
  module SendGrid
2
4
  class Ganalytics
5
+ attr_accessor :enable, :utm_source, :utm_medium, :utm_term, :utm_content, :utm_name, :utm_campaign
6
+
3
7
  def initialize(enable: nil, utm_source: nil, utm_medium: nil, utm_term: nil, utm_content: nil, utm_campaign: nil, utm_name: nil)
4
8
  @enable = enable
5
9
  @utm_source = utm_source
@@ -10,62 +14,14 @@ module SendGrid
10
14
  @utm_name = utm_name
11
15
  end
12
16
 
13
- def enable=(enable)
14
- @enable = enable
15
- end
16
-
17
- def enable
18
- @enable
19
- end
20
-
21
- def utm_source=(utm_source)
22
- @utm_source = utm_source
23
- end
24
-
25
- def utm_source
26
- @utm_source
27
- end
28
-
29
- def utm_medium=(utm_medium)
30
- @utm_medium = utm_medium
31
- end
32
-
33
- def utm_medium
34
- @utm_medium
35
- end
36
-
37
- def utm_term=(utm_term)
38
- @utm_term = utm_term
39
- end
40
-
41
- def utm_term
42
- @utm_term
43
- end
44
-
45
- def utm_content=(utm_content)
46
- @utm_content = utm_content
47
- end
48
-
49
- def utm_content
50
- @utm_content
51
- end
52
-
53
- def utm_campaign=(utm_campaign)
54
- @utm_campaign = utm_campaign
55
- end
56
-
57
- def utm_campaign
58
- @utm_campaign
59
- end
60
-
61
17
  def to_json(*)
62
18
  {
63
- 'enable' => self.enable,
64
- 'utm_source' => self.utm_source,
65
- 'utm_medium' => self.utm_medium,
66
- 'utm_term' => self.utm_term,
67
- 'utm_content' => self.utm_content,
68
- 'utm_campaign' => self.utm_campaign
19
+ 'enable' => enable,
20
+ 'utm_source' => utm_source,
21
+ 'utm_medium' => utm_medium,
22
+ 'utm_term' => utm_term,
23
+ 'utm_content' => utm_content,
24
+ 'utm_campaign' => utm_campaign
69
25
  }.delete_if { |_, value| value.to_s.strip == '' }
70
26
  end
71
27
  end
@@ -1,21 +1,17 @@
1
+ require 'json'
2
+
1
3
  module SendGrid
2
4
  class Header
5
+ attr_accessor :header
6
+
3
7
  def initialize(key: nil, value: nil)
4
8
  @header = {}
5
- (key.nil? || value.nil?) ? @header = nil : @header[key] = value
6
- end
7
-
8
- def header=(header)
9
- @header = header
10
- end
11
-
12
- def header
13
- @header
9
+ key.nil? || value.nil? ? @header = nil : @header[key] = value
14
10
  end
15
11
 
16
12
  def to_json(*)
17
13
  {
18
- 'header' => self.header
14
+ 'header' => header
19
15
  }.delete_if { |_, value| value.to_s.strip == '' }
20
16
  end
21
17
  end
@@ -1,12 +1,16 @@
1
1
  # Build the request body for the v3/mail/send endpoint
2
2
  # Please see the examples/helpers/mail/example.rb for a demonstration of usage
3
+ require 'json'
4
+
3
5
  module SendGrid
4
6
  class Mail
5
-
6
7
  attr_accessor :subject, :ip_pool_name, :template_id, :send_at, :batch_id
7
8
  attr_reader :personalizations, :contents, :attachments, :categories, :sections, :headers, :custom_args
9
+ attr_writer :from, :asm, :mail_settings, :tracking_settings, :reply_to
8
10
 
9
- def initialize(from_email=nil, subj=nil, to_email=nil, cont=nil)
11
+ # We allow for all nil values here to create uninitialized Mail objects
12
+ # (e.g. <project-root>/use-cases/transactional-templates.md)
13
+ def initialize(from_email = nil, subj = nil, to_email = nil, cont = nil) # rubocop:disable Metrics/ParameterLists
10
14
  @from = nil
11
15
  @subject = nil
12
16
  @personalizations = []
@@ -25,18 +29,14 @@ module SendGrid
25
29
  @tracking_settings = nil
26
30
  @reply_to = nil
27
31
 
28
- if !(from_email.nil? && subj.nil? && to_email.nil? && cont.nil?)
29
- self.from = from_email
30
- self.subject = subj
31
- personalization = Personalization.new
32
- personalization.add_to(to_email)
33
- self.add_personalization(personalization)
34
- self.add_content(cont)
35
- end
36
- end
32
+ return if from_email.nil? && subj.nil? && to_email.nil? && cont.nil?
37
33
 
38
- def from=(from)
39
- @from = from
34
+ self.from = from_email
35
+ self.subject = subj
36
+ personalization = Personalization.new
37
+ personalization.add_to(to_email)
38
+ add_personalization(personalization)
39
+ add_content(cont)
40
40
  end
41
41
 
42
42
  def from
@@ -54,7 +54,7 @@ module SendGrid
54
54
  def check_for_secrets(patterns)
55
55
  contents = @contents.map { |content| content['value'] }.join(' ')
56
56
  patterns.each do |pattern|
57
- raise SecurityError.new('Content contains sensitive information.') if contents.match(pattern)
57
+ raise SecurityError, 'Content contains sensitive information.' if contents.match(pattern)
58
58
  end
59
59
  end
60
60
 
@@ -81,58 +81,42 @@ module SendGrid
81
81
  @custom_args = @custom_args.merge(custom_arg['custom_arg'])
82
82
  end
83
83
 
84
- def asm=(asm)
85
- @asm = asm
86
- end
87
-
88
84
  def asm
89
85
  @asm.nil? ? nil : @asm.to_json
90
86
  end
91
87
 
92
- def mail_settings=(mail_settings)
93
- @mail_settings = mail_settings
94
- end
95
-
96
88
  def mail_settings
97
89
  @mail_settings.nil? ? nil : @mail_settings.to_json
98
90
  end
99
91
 
100
- def tracking_settings=(tracking_settings)
101
- @tracking_settings = tracking_settings
102
- end
103
-
104
92
  def tracking_settings
105
93
  @tracking_settings.nil? ? nil : @tracking_settings.to_json
106
94
  end
107
95
 
108
- def reply_to=(reply_to)
109
- @reply_to = reply_to
110
- end
111
-
112
96
  def reply_to
113
97
  @reply_to.nil? ? nil : @reply_to.to_json
114
98
  end
115
99
 
116
100
  def to_json(*)
117
101
  {
118
- 'from' => self.from,
119
- 'subject' => self.subject,
120
- 'personalizations' => self.personalizations,
121
- 'content' => self.contents,
122
- 'attachments' => self.attachments,
123
- 'template_id' => self.template_id,
124
- 'sections' => self.sections,
125
- 'headers' => self.headers,
126
- 'categories' => self.categories,
127
- 'custom_args' => self.custom_args,
128
- 'send_at' => self.send_at,
129
- 'batch_id' => self.batch_id,
130
- 'asm' => self.asm,
131
- 'ip_pool_name' => self.ip_pool_name,
132
- 'mail_settings' => self.mail_settings,
133
- 'tracking_settings' => self.tracking_settings,
134
- 'reply_to' => self.reply_to
135
- }.delete_if { |_, value| value.to_s.strip == '' || value == [] || value == {}}
102
+ 'from' => from,
103
+ 'subject' => subject,
104
+ 'personalizations' => personalizations,
105
+ 'content' => contents,
106
+ 'attachments' => attachments,
107
+ 'template_id' => template_id,
108
+ 'sections' => sections,
109
+ 'headers' => headers,
110
+ 'categories' => categories,
111
+ 'custom_args' => custom_args,
112
+ 'send_at' => send_at,
113
+ 'batch_id' => batch_id,
114
+ 'asm' => asm,
115
+ 'ip_pool_name' => ip_pool_name,
116
+ 'mail_settings' => mail_settings,
117
+ 'tracking_settings' => tracking_settings,
118
+ 'reply_to' => reply_to
119
+ }.delete_if { |_, value| value.to_s.strip == '' || value == [] || value == {} }
136
120
  end
137
121
  end
138
122
  end