sendgrid-ruby 1.1.6 → 6.0.4

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.
Files changed (136) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +21 -0
  3. data/.env_sample +1 -3
  4. data/.gitignore +1 -0
  5. data/.travis.yml +28 -17
  6. data/CHANGELOG.md +231 -1
  7. data/CODE_OF_CONDUCT.md +73 -0
  8. data/CONTRIBUTING.md +214 -0
  9. data/Gemfile +5 -4
  10. data/ISSUE_TEMPLATE.md +26 -0
  11. data/LICENSE.md +21 -0
  12. data/Makefile +7 -0
  13. data/PULL_REQUEST_TEMPLATE.md +31 -0
  14. data/README.md +161 -225
  15. data/Rakefile +9 -2
  16. data/TROUBLESHOOTING.md +137 -0
  17. data/UPGRADE.md +5 -0
  18. data/USAGE.md +5037 -0
  19. data/USE_CASES.md +377 -0
  20. data/config.ru +4 -0
  21. data/docker/Dockerfile +12 -0
  22. data/docker/README.md +30 -0
  23. data/examples/accesssettings/accesssettings.rb +83 -0
  24. data/examples/alerts/alerts.rb +62 -0
  25. data/examples/apikeys/apikeys.rb +84 -0
  26. data/examples/asm/asm.rb +173 -0
  27. data/examples/browsers/browsers.rb +16 -0
  28. data/examples/campaigns/campaigns.rb +153 -0
  29. data/examples/categories/categories.rb +36 -0
  30. data/examples/clients/clients.rb +27 -0
  31. data/examples/contactdb/contactdb.rb +395 -0
  32. data/examples/devices/devices.rb +16 -0
  33. data/examples/geo/geo.rb +16 -0
  34. data/examples/helpers/mail/example.rb +147 -0
  35. data/examples/helpers/settings/example.rb +23 -0
  36. data/examples/helpers/stats/example.rb +42 -0
  37. data/examples/ips/ips.rb +167 -0
  38. data/examples/mail/mail.rb +173 -0
  39. data/examples/mailboxproviders/mailboxproviders.rb +16 -0
  40. data/examples/mailsettings/mailsettings.rb +219 -0
  41. data/examples/partnersettings/partnersettings.rb +39 -0
  42. data/examples/scopes/scopes.rb +61 -0
  43. data/examples/senderauthentication/senderauthentication.rb +310 -0
  44. data/examples/senders/senders.rb +98 -0
  45. data/examples/stats/stats.rb +16 -0
  46. data/examples/subusers/subusers.rb +169 -0
  47. data/examples/suppression/suppression.rb +201 -0
  48. data/examples/templates/templates.rb +129 -0
  49. data/examples/trackingsettings/trackingsettings.rb +110 -0
  50. data/examples/user/user.rb +293 -0
  51. data/gemfiles/Sinatra_1.gemfile +6 -0
  52. data/gemfiles/Sinatra_2.gemfile +6 -0
  53. data/lib/sendgrid/client.rb +33 -57
  54. data/lib/sendgrid/helpers/inbound/README.md +98 -0
  55. data/lib/sendgrid/helpers/inbound/app.rb +32 -0
  56. data/lib/sendgrid/helpers/inbound/config.yml +26 -0
  57. data/lib/sendgrid/helpers/inbound/public/index.html +10 -0
  58. data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +58 -0
  59. data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +57 -0
  60. data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +298 -0
  61. data/lib/sendgrid/helpers/inbound/send.rb +26 -0
  62. data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
  63. data/lib/sendgrid/helpers/mail/README.md +14 -0
  64. data/lib/sendgrid/helpers/mail/asm.rb +33 -0
  65. data/lib/sendgrid/helpers/mail/attachment.rb +86 -0
  66. data/lib/sendgrid/helpers/mail/bcc_settings.rb +33 -0
  67. data/lib/sendgrid/helpers/mail/bypass_list_management.rb +43 -0
  68. data/lib/sendgrid/helpers/mail/category.rb +20 -0
  69. data/lib/sendgrid/helpers/mail/click_tracking.rb +33 -0
  70. data/lib/sendgrid/helpers/mail/content.rb +20 -0
  71. data/lib/sendgrid/helpers/mail/custom_arg.rb +24 -0
  72. data/lib/sendgrid/helpers/mail/email.rb +29 -0
  73. data/lib/sendgrid/helpers/mail/footer.rb +43 -0
  74. data/lib/sendgrid/helpers/mail/ganalytics.rb +74 -0
  75. data/lib/sendgrid/helpers/mail/header.rb +24 -0
  76. data/lib/sendgrid/helpers/mail/mail.rb +140 -0
  77. data/lib/sendgrid/helpers/mail/mail_settings.rb +63 -0
  78. data/lib/sendgrid/helpers/mail/open_tracking.rb +33 -0
  79. data/lib/sendgrid/helpers/mail/personalization.rb +82 -0
  80. data/lib/sendgrid/helpers/mail/section.rb +24 -0
  81. data/lib/sendgrid/helpers/mail/spam_check.rb +43 -0
  82. data/lib/sendgrid/helpers/mail/subscription_tracking.rb +53 -0
  83. data/lib/sendgrid/helpers/mail/substitution.rb +24 -0
  84. data/lib/sendgrid/helpers/mail/tracking_settings.rb +53 -0
  85. data/lib/sendgrid/helpers/permissions/scope.rb +28 -0
  86. data/lib/sendgrid/helpers/permissions/scopes.yml +309 -0
  87. data/lib/sendgrid/helpers/settings/README.md +14 -0
  88. data/lib/sendgrid/helpers/settings/mail_settings_dto.rb +13 -0
  89. data/lib/sendgrid/helpers/settings/partner_settings_dto.rb +13 -0
  90. data/lib/sendgrid/helpers/settings/settings.rb +28 -0
  91. data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +24 -0
  92. data/lib/sendgrid/helpers/settings/user_settings_dto.rb +13 -0
  93. data/lib/sendgrid/helpers/stats/email_stats.rb +46 -0
  94. data/lib/sendgrid/helpers/stats/metrics.rb +35 -0
  95. data/lib/sendgrid/helpers/stats/stats_response.rb +31 -0
  96. data/lib/sendgrid/version.rb +1 -1
  97. data/lib/sendgrid-ruby.rb +27 -6
  98. data/mail_helper_v3.md +390 -0
  99. data/sendgrid-ruby.gemspec +13 -17
  100. data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
  101. data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +32 -0
  102. data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +24 -0
  103. data/spec/sendgrid/helpers/settings/settings_spec.rb +25 -0
  104. data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +27 -0
  105. data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +24 -0
  106. data/spec/sendgrid/helpers/stats/email_stats_spec.rb +112 -0
  107. data/spec/sendgrid/helpers/stats/metrics_spec.rb +46 -0
  108. data/spec/sendgrid/helpers/stats/stats_response_spec.rb +76 -0
  109. data/spec/spec_helper.rb +10 -1
  110. data/test/prism.sh +42 -0
  111. data/test/sendgrid/helpers/mail/test_attachment.rb +35 -0
  112. data/test/sendgrid/helpers/mail/test_category.rb +27 -0
  113. data/test/sendgrid/helpers/mail/test_email.rb +34 -0
  114. data/test/sendgrid/helpers/mail/test_mail.rb +261 -0
  115. data/test/sendgrid/helpers/mail/test_personalizations.rb +161 -0
  116. data/test/sendgrid/permissions/test_scopes.rb +38 -0
  117. data/test/sendgrid/test_sendgrid-ruby.rb +2751 -0
  118. metadata +149 -115
  119. data/.rspec +0 -2
  120. data/.rubocop.yml +0 -30
  121. data/FETCH_HEAD +0 -0
  122. data/Guardfile +0 -10
  123. data/LICENSE.txt +0 -22
  124. data/example.rb +0 -41
  125. data/lib/sendgrid/exceptions.rb +0 -7
  126. data/lib/sendgrid/mail.rb +0 -182
  127. data/lib/sendgrid/recipient.rb +0 -29
  128. data/lib/sendgrid/response.rb +0 -14
  129. data/lib/sendgrid/template.rb +0 -26
  130. data/lib/sendgrid/template_mailer.rb +0 -59
  131. data/spec/lib/sendgrid/client_spec.rb +0 -87
  132. data/spec/lib/sendgrid/mail_spec.rb +0 -151
  133. data/spec/lib/sendgrid/recipient_spec.rb +0 -91
  134. data/spec/lib/sendgrid/template_mailer_spec.rb +0 -86
  135. data/spec/lib/sendgrid/template_spec.rb +0 -61
  136. data/spec/lib/sendgrid_spec.rb +0 -7
@@ -0,0 +1,43 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class Footer
5
+ def initialize(enable: nil, text: nil, html: nil)
6
+ @enable = enable
7
+ @text = text
8
+ @html = html
9
+ end
10
+
11
+ def enable=(enable)
12
+ @enable = enable
13
+ end
14
+
15
+ def enable
16
+ @enable
17
+ end
18
+
19
+ def text=(text)
20
+ @text = text
21
+ end
22
+
23
+ def text
24
+ @text
25
+ end
26
+
27
+ def html=(html)
28
+ @html = html
29
+ end
30
+
31
+ def html
32
+ @html
33
+ end
34
+
35
+ def to_json(*)
36
+ {
37
+ 'enable' => self.enable,
38
+ 'text' => self.text,
39
+ 'html' => self.html
40
+ }.delete_if { |_, value| value.to_s.strip == '' }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,74 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class Ganalytics
5
+ def initialize(enable: nil, utm_source: nil, utm_medium: nil, utm_term: nil, utm_content: nil, utm_campaign: nil, utm_name: nil)
6
+ @enable = enable
7
+ @utm_source = utm_source
8
+ @utm_medium = utm_medium
9
+ @utm_term = utm_term
10
+ @utm_content = utm_content
11
+ @utm_campaign = utm_campaign
12
+ @utm_name = utm_name
13
+ end
14
+
15
+ def enable=(enable)
16
+ @enable = enable
17
+ end
18
+
19
+ def enable
20
+ @enable
21
+ end
22
+
23
+ def utm_source=(utm_source)
24
+ @utm_source = utm_source
25
+ end
26
+
27
+ def utm_source
28
+ @utm_source
29
+ end
30
+
31
+ def utm_medium=(utm_medium)
32
+ @utm_medium = utm_medium
33
+ end
34
+
35
+ def utm_medium
36
+ @utm_medium
37
+ end
38
+
39
+ def utm_term=(utm_term)
40
+ @utm_term = utm_term
41
+ end
42
+
43
+ def utm_term
44
+ @utm_term
45
+ end
46
+
47
+ def utm_content=(utm_content)
48
+ @utm_content = utm_content
49
+ end
50
+
51
+ def utm_content
52
+ @utm_content
53
+ end
54
+
55
+ def utm_campaign=(utm_campaign)
56
+ @utm_campaign = utm_campaign
57
+ end
58
+
59
+ def utm_campaign
60
+ @utm_campaign
61
+ end
62
+
63
+ def to_json(*)
64
+ {
65
+ 'enable' => self.enable,
66
+ 'utm_source' => self.utm_source,
67
+ 'utm_medium' => self.utm_medium,
68
+ 'utm_term' => self.utm_term,
69
+ 'utm_content' => self.utm_content,
70
+ 'utm_campaign' => self.utm_campaign
71
+ }.delete_if { |_, value| value.to_s.strip == '' }
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,24 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class Header
5
+ def initialize(key: nil, value: nil)
6
+ @header = {}
7
+ (key.nil? || value.nil?) ? @header = nil : @header[key] = value
8
+ end
9
+
10
+ def header=(header)
11
+ @header = header
12
+ end
13
+
14
+ def header
15
+ @header
16
+ end
17
+
18
+ def to_json(*)
19
+ {
20
+ 'header' => self.header
21
+ }.delete_if { |_, value| value.to_s.strip == '' }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,140 @@
1
+ # Build the request body for the v3/mail/send endpoint
2
+ # Please see the examples/helpers/mail/example.rb for a demonstration of usage
3
+ require 'json'
4
+
5
+ module SendGrid
6
+ class Mail
7
+
8
+ attr_accessor :subject, :ip_pool_name, :template_id, :send_at, :batch_id
9
+ attr_reader :personalizations, :contents, :attachments, :categories, :sections, :headers, :custom_args
10
+
11
+ def initialize(from_email=nil, subj=nil, to_email=nil, cont=nil)
12
+ @from = nil
13
+ @subject = nil
14
+ @personalizations = []
15
+ @contents = []
16
+ @attachments = []
17
+ @template_id = nil
18
+ @sections = {}
19
+ @headers = {}
20
+ @categories = []
21
+ @custom_args = {}
22
+ @send_at = nil
23
+ @batch_id = nil
24
+ @asm = nil
25
+ @ip_pool_name = nil
26
+ @mail_settings = nil
27
+ @tracking_settings = nil
28
+ @reply_to = nil
29
+
30
+ if !(from_email.nil? && subj.nil? && to_email.nil? && cont.nil?)
31
+ self.from = from_email
32
+ self.subject = subj
33
+ personalization = Personalization.new
34
+ personalization.add_to(to_email)
35
+ self.add_personalization(personalization)
36
+ self.add_content(cont)
37
+ end
38
+ end
39
+
40
+ def from=(from)
41
+ @from = from
42
+ end
43
+
44
+ def from
45
+ @from.nil? ? nil : @from.to_json
46
+ end
47
+
48
+ def add_personalization(personalization)
49
+ @personalizations << personalization.to_json
50
+ end
51
+
52
+ def add_content(content)
53
+ @contents << content.to_json
54
+ end
55
+
56
+ def check_for_secrets(patterns)
57
+ contents = @contents.map { |content| content['value'] }.join(' ')
58
+ patterns.each do |pattern|
59
+ raise SecurityError.new('Content contains sensitive information.') if contents.match(pattern)
60
+ end
61
+ end
62
+
63
+ def add_attachment(attachment)
64
+ @attachments << attachment.to_json
65
+ end
66
+
67
+ def add_category(category)
68
+ @categories << category.name
69
+ end
70
+
71
+ def add_section(section)
72
+ section = section.to_json
73
+ @sections = @sections.merge(section['section'])
74
+ end
75
+
76
+ def add_header(header)
77
+ header = header.to_json
78
+ @headers = @headers.merge(header['header'])
79
+ end
80
+
81
+ def add_custom_arg(custom_arg)
82
+ custom_arg = custom_arg.to_json
83
+ @custom_args = @custom_args.merge(custom_arg['custom_arg'])
84
+ end
85
+
86
+ def asm=(asm)
87
+ @asm = asm
88
+ end
89
+
90
+ def asm
91
+ @asm.nil? ? nil : @asm.to_json
92
+ end
93
+
94
+ def mail_settings=(mail_settings)
95
+ @mail_settings = mail_settings
96
+ end
97
+
98
+ def mail_settings
99
+ @mail_settings.nil? ? nil : @mail_settings.to_json
100
+ end
101
+
102
+ def tracking_settings=(tracking_settings)
103
+ @tracking_settings = tracking_settings
104
+ end
105
+
106
+ def tracking_settings
107
+ @tracking_settings.nil? ? nil : @tracking_settings.to_json
108
+ end
109
+
110
+ def reply_to=(reply_to)
111
+ @reply_to = reply_to
112
+ end
113
+
114
+ def reply_to
115
+ @reply_to.nil? ? nil : @reply_to.to_json
116
+ end
117
+
118
+ def to_json(*)
119
+ {
120
+ 'from' => self.from,
121
+ 'subject' => self.subject,
122
+ 'personalizations' => self.personalizations,
123
+ 'content' => self.contents,
124
+ 'attachments' => self.attachments,
125
+ 'template_id' => self.template_id,
126
+ 'sections' => self.sections,
127
+ 'headers' => self.headers,
128
+ 'categories' => self.categories,
129
+ 'custom_args' => self.custom_args,
130
+ 'send_at' => self.send_at,
131
+ 'batch_id' => self.batch_id,
132
+ 'asm' => self.asm,
133
+ 'ip_pool_name' => self.ip_pool_name,
134
+ 'mail_settings' => self.mail_settings,
135
+ 'tracking_settings' => self.tracking_settings,
136
+ 'reply_to' => self.reply_to
137
+ }.delete_if { |_, value| value.to_s.strip == '' || value == [] || value == {}}
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,63 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class MailSettings
5
+ def initialize
6
+ @bcc = nil
7
+ @bypass_list_management = nil
8
+ @footer = nil
9
+ @sandbox_mode = nil
10
+ @spam_check = nil
11
+ end
12
+
13
+ def sandbox_mode=(sandbox_mode)
14
+ @sandbox_mode = sandbox_mode
15
+ end
16
+
17
+ def sandbox_mode
18
+ @sandbox_mode.nil? ? nil : @sandbox_mode.to_json
19
+ end
20
+
21
+ def bypass_list_management=(bypass_list_management)
22
+ @bypass_list_management = bypass_list_management
23
+ end
24
+
25
+ def bypass_list_management
26
+ @bypass_list_management.nil? ? nil : @bypass_list_management.to_json
27
+ end
28
+
29
+ def footer=(footer)
30
+ @footer = footer
31
+ end
32
+
33
+ def footer
34
+ @footer.nil? ? nil : @footer.to_json
35
+ end
36
+
37
+ def bcc=(bcc)
38
+ @bcc = bcc
39
+ end
40
+
41
+ def bcc
42
+ @bcc.nil? ? nil : @bcc.to_json
43
+ end
44
+
45
+ def spam_check=(spam_check)
46
+ @spam_check = spam_check
47
+ end
48
+
49
+ def spam_check
50
+ @spam_check.nil? ? nil : @spam_check.to_json
51
+ end
52
+
53
+ def to_json(*)
54
+ {
55
+ 'bcc' => self.bcc,
56
+ 'bypass_list_management' => self.bypass_list_management,
57
+ 'footer' => self.footer,
58
+ 'sandbox_mode' => self.sandbox_mode,
59
+ 'spam_check' => self.spam_check
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 OpenTracking
5
+ def initialize(enable: nil, substitution_tag: nil)
6
+ @enable = enable
7
+ @substitution_tag = substitution_tag
8
+ end
9
+
10
+ def enable=(enable)
11
+ @enable = enable
12
+ end
13
+
14
+ def enable
15
+ @enable
16
+ end
17
+
18
+ def substitution_tag=(substitution_tag)
19
+ @substitution_tag = substitution_tag
20
+ end
21
+
22
+ def substitution_tag
23
+ @substitution_tag
24
+ end
25
+
26
+ def to_json(*)
27
+ {
28
+ 'enable' => self.enable,
29
+ 'substitution_tag' => self.substitution_tag
30
+ }.delete_if { |_, value| value.to_s.strip == '' }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,82 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class Personalization
5
+
6
+ attr_reader :tos, :ccs, :bccs, :headers, :substitutions, :custom_args,
7
+ :dynamic_template_data
8
+
9
+ def initialize
10
+ @tos = []
11
+ @ccs = []
12
+ @bccs = []
13
+ @subject = nil
14
+ @headers = {}
15
+ @substitutions = {}
16
+ @custom_args = {}
17
+ @dynamic_template_data = {}
18
+ @send_at = nil
19
+ end
20
+
21
+ def add_to(to)
22
+ @tos << to.to_json
23
+ end
24
+
25
+ def add_cc(cc)
26
+ @ccs << cc.to_json
27
+ end
28
+
29
+ def add_bcc(bcc)
30
+ @bccs << bcc.to_json
31
+ end
32
+
33
+ def subject=(subject)
34
+ @subject = subject
35
+ end
36
+
37
+ def subject
38
+ @subject
39
+ end
40
+
41
+ def add_header(header)
42
+ header = header.to_json
43
+ @headers = @headers.merge(header['header'])
44
+ end
45
+
46
+ def add_substitution(substitution)
47
+ substitution = substitution.to_json
48
+ @substitutions = @substitutions.merge(substitution['substitution'])
49
+ end
50
+
51
+ def add_custom_arg(custom_arg)
52
+ custom_arg = custom_arg.to_json
53
+ @custom_args = @custom_args.merge(custom_arg['custom_arg'])
54
+ end
55
+
56
+ def add_dynamic_template_data(dynamic_template_data)
57
+ @dynamic_template_data.merge!(dynamic_template_data)
58
+ end
59
+
60
+ def send_at=(send_at)
61
+ @send_at = send_at
62
+ end
63
+
64
+ def send_at
65
+ @send_at
66
+ end
67
+
68
+ def to_json(*)
69
+ {
70
+ 'to' => self.tos,
71
+ 'cc' => self.ccs,
72
+ 'bcc' => self.bccs,
73
+ 'subject' => self.subject,
74
+ 'headers' => self.headers,
75
+ 'substitutions' => self.substitutions,
76
+ 'custom_args' => self.custom_args,
77
+ 'dynamic_template_data' => self.dynamic_template_data,
78
+ 'send_at' => self.send_at
79
+ }.delete_if { |_, value| value.to_s.strip == '' || value == [] || value == {}}
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,24 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class Section
5
+ def initialize(key: nil, value: nil)
6
+ @section = {}
7
+ (key.nil? || value.nil?) ? @section = nil : @section[key] = value
8
+ end
9
+
10
+ def section=(section)
11
+ @section = section
12
+ end
13
+
14
+ def section
15
+ @section
16
+ end
17
+
18
+ def to_json(*)
19
+ {
20
+ 'section' => self.section
21
+ }.delete_if { |_, value| value.to_s.strip == '' }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,43 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class SpamCheck
5
+ def initialize(enable: nil, threshold: nil, post_to_url: nil)
6
+ @enable = enable
7
+ @threshold = threshold
8
+ @post_to_url = post_to_url
9
+ end
10
+
11
+ def enable=(enable)
12
+ @enable = enable
13
+ end
14
+
15
+ def enable
16
+ @enable
17
+ end
18
+
19
+ def threshold=(threshold)
20
+ @threshold = threshold
21
+ end
22
+
23
+ def threshold
24
+ @threshold
25
+ end
26
+
27
+ def post_to_url=(post_to_url)
28
+ @post_to_url = post_to_url
29
+ end
30
+
31
+ def post_to_url
32
+ @post_to_url
33
+ end
34
+
35
+ def to_json(*)
36
+ {
37
+ 'enable' => self.enable,
38
+ 'threshold' => self.threshold,
39
+ 'post_to_url' => self.post_to_url
40
+ }.delete_if { |_, value| value.to_s.strip == '' }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,53 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class SubscriptionTracking
5
+ def initialize(enable: nil, text: nil, html: nil, substitution_tag: nil)
6
+ @enable = enable
7
+ @text = text
8
+ @html = html
9
+ @substitution_tag = substitution_tag
10
+ end
11
+
12
+ def enable=(enable)
13
+ @enable = enable
14
+ end
15
+
16
+ def enable
17
+ @enable
18
+ end
19
+
20
+ def text=(text)
21
+ @text = text
22
+ end
23
+
24
+ def text
25
+ @text
26
+ end
27
+
28
+ def html=(html)
29
+ @html = html
30
+ end
31
+
32
+ def html
33
+ @html
34
+ end
35
+
36
+ def substitution_tag=(substitution_tag)
37
+ @substitution_tag = substitution_tag
38
+ end
39
+
40
+ def substitution_tag
41
+ @substitution_tag
42
+ end
43
+
44
+ def to_json(*)
45
+ {
46
+ 'enable' => self.enable,
47
+ 'text' => self.text,
48
+ 'html' => self.html,
49
+ 'substitution_tag' => self.substitution_tag
50
+ }.delete_if { |_, value| value.to_s.strip == '' }
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,24 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class Substitution
5
+ def initialize(key: nil, value: nil)
6
+ @substitution = {}
7
+ (key.nil? || value.nil?) ? @substitution = nil : @substitution[key] = value
8
+ end
9
+
10
+ def substitution=(substitution)
11
+ @substitution = substitution
12
+ end
13
+
14
+ def substitution
15
+ @substitution
16
+ end
17
+
18
+ def to_json(*)
19
+ {
20
+ 'substitution' => self.substitution
21
+ }.delete_if { |_, value| value.to_s.strip == '' }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,53 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class TrackingSettings
5
+ def initialize
6
+ @click_tracking = nil
7
+ @open_tracking = nil
8
+ @subscription_tracking = nil
9
+ @ganalytics = nil
10
+ end
11
+
12
+ def click_tracking=(click_tracking)
13
+ @click_tracking = click_tracking
14
+ end
15
+
16
+ def click_tracking
17
+ @click_tracking.nil? ? nil : @click_tracking.to_json
18
+ end
19
+
20
+ def open_tracking=(open_tracking)
21
+ @open_tracking = open_tracking
22
+ end
23
+
24
+ def open_tracking
25
+ @open_tracking.nil? ? nil : @open_tracking.to_json
26
+ end
27
+
28
+ def subscription_tracking=(subscription_tracking)
29
+ @subscription_tracking = subscription_tracking
30
+ end
31
+
32
+ def subscription_tracking
33
+ @subscription_tracking.nil? ? nil : @subscription_tracking.to_json
34
+ end
35
+
36
+ def ganalytics=(ganalytics)
37
+ @ganalytics = ganalytics
38
+ end
39
+
40
+ def ganalytics
41
+ @ganalytics.nil? ? nil : @ganalytics.to_json
42
+ end
43
+
44
+ def to_json(*)
45
+ {
46
+ 'click_tracking' => self.click_tracking,
47
+ 'open_tracking' => self.open_tracking,
48
+ 'subscription_tracking' => self.subscription_tracking,
49
+ 'ganalytics' => self.ganalytics
50
+ }.delete_if { |_, value| value.to_s.strip == '' }
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,28 @@
1
+ # This is used for getting scopes
2
+ require 'yaml'
3
+
4
+ module SendGrid
5
+ class Scope
6
+ SCOPES = YAML.load_file(File.dirname(__FILE__) + '/scopes.yml').freeze
7
+
8
+ class << self
9
+ def admin_permissions
10
+ SCOPES.values.map(&:values).flatten
11
+ end
12
+
13
+ def read_only_permissions
14
+ SCOPES.map { |_, v| v[:read] }.flatten
15
+ end
16
+
17
+ SCOPES.each_key do |endpoint|
18
+ define_method "#{endpoint}_read_only_permissions" do
19
+ SCOPES[endpoint][:read]
20
+ end
21
+
22
+ define_method "#{endpoint}_full_access_permissions" do
23
+ SCOPES[endpoint].values.flatten
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end