sendgrid-ruby 1.1.6 → 6.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +5 -5
  2. data/.env_sample +1 -3
  3. data/.github/ISSUE_TEMPLATE/config.yml +10 -0
  4. data/.github/workflows/test-and-deploy.yml +120 -0
  5. data/.gitignore +3 -0
  6. data/.rubocop.yml +5 -27
  7. data/.rubocop_todo.yml +127 -0
  8. data/CHANGELOG.md +417 -1
  9. data/CODE_OF_CONDUCT.md +73 -0
  10. data/CONTRIBUTING.md +202 -0
  11. data/Dockerfile +14 -0
  12. data/FIRST_TIMERS.md +79 -0
  13. data/Gemfile +4 -4
  14. data/ISSUE_TEMPLATE.md +30 -0
  15. data/LICENSE +21 -0
  16. data/Makefile +14 -0
  17. data/PULL_REQUEST_TEMPLATE.md +31 -0
  18. data/README.md +153 -229
  19. data/Rakefile +9 -3
  20. data/TROUBLESHOOTING.md +151 -0
  21. data/UPGRADE.md +5 -0
  22. data/USAGE.md +5144 -0
  23. data/config.ru +4 -0
  24. data/examples/accesssettings/accesssettings.rb +80 -0
  25. data/examples/alerts/alerts.rb +59 -0
  26. data/examples/apikeys/apikeys.rb +81 -0
  27. data/examples/asm/asm.rb +170 -0
  28. data/examples/browsers/browsers.rb +13 -0
  29. data/examples/campaigns/campaigns.rb +150 -0
  30. data/examples/categories/categories.rb +33 -0
  31. data/examples/clients/clients.rb +24 -0
  32. data/examples/contactdb/contactdb.rb +392 -0
  33. data/examples/devices/devices.rb +13 -0
  34. data/examples/emailactivity/emailactivity.rb +52 -0
  35. data/examples/geo/geo.rb +13 -0
  36. data/examples/helpers/eventwebhook/example.rb +16 -0
  37. data/examples/helpers/mail/example.rb +158 -0
  38. data/examples/helpers/settings/example.rb +23 -0
  39. data/examples/helpers/stats/example.rb +42 -0
  40. data/examples/ips/ips.rb +164 -0
  41. data/examples/mail/mail.rb +170 -0
  42. data/examples/mailboxproviders/mailboxproviders.rb +13 -0
  43. data/examples/mailsettings/mailsettings.rb +216 -0
  44. data/examples/partnersettings/partnersettings.rb +36 -0
  45. data/examples/scopes/scopes.rb +59 -0
  46. data/examples/senderauthentication/senderauthentication.rb +307 -0
  47. data/examples/senders/senders.rb +95 -0
  48. data/examples/stats/stats.rb +13 -0
  49. data/examples/subusers/subusers.rb +166 -0
  50. data/examples/suppression/suppression.rb +198 -0
  51. data/examples/templates/templates.rb +127 -0
  52. data/examples/trackingsettings/trackingsettings.rb +107 -0
  53. data/examples/user/user.rb +290 -0
  54. data/gemfiles/Sinatra_1.gemfile +6 -0
  55. data/gemfiles/Sinatra_2.gemfile +6 -0
  56. data/lib/rack/sendgrid_webhook_verification.rb +55 -0
  57. data/lib/sendgrid/base_interface.rb +40 -0
  58. data/lib/sendgrid/helpers/eventwebhook/eventwebhook.rb +50 -0
  59. data/lib/sendgrid/helpers/inbound/README.md +98 -0
  60. data/lib/sendgrid/helpers/inbound/app.rb +32 -0
  61. data/lib/sendgrid/helpers/inbound/config.yml +26 -0
  62. data/lib/sendgrid/helpers/inbound/public/index.html +10 -0
  63. data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +58 -0
  64. data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +57 -0
  65. data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +298 -0
  66. data/lib/sendgrid/helpers/inbound/send.rb +26 -0
  67. data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
  68. data/lib/sendgrid/helpers/mail/README.md +14 -0
  69. data/lib/sendgrid/helpers/mail/asm.rb +19 -0
  70. data/lib/sendgrid/helpers/mail/attachment.rb +55 -0
  71. data/lib/sendgrid/helpers/mail/bcc_settings.rb +19 -0
  72. data/lib/sendgrid/helpers/mail/bypass_list_management.rb +31 -0
  73. data/lib/sendgrid/helpers/mail/category.rb +18 -0
  74. data/lib/sendgrid/helpers/mail/click_tracking.rb +19 -0
  75. data/lib/sendgrid/helpers/mail/content.rb +19 -0
  76. data/lib/sendgrid/helpers/mail/custom_arg.rb +18 -0
  77. data/lib/sendgrid/helpers/mail/email.rb +32 -0
  78. data/lib/sendgrid/helpers/mail/footer.rb +21 -0
  79. data/lib/sendgrid/helpers/mail/ganalytics.rb +28 -0
  80. data/lib/sendgrid/helpers/mail/header.rb +18 -0
  81. data/lib/sendgrid/helpers/mail/mail.rb +122 -0
  82. data/lib/sendgrid/helpers/mail/mail_settings.rb +45 -0
  83. data/lib/sendgrid/helpers/mail/open_tracking.rb +19 -0
  84. data/lib/sendgrid/helpers/mail/personalization.rb +93 -0
  85. data/lib/sendgrid/helpers/mail/section.rb +18 -0
  86. data/lib/sendgrid/helpers/mail/spam_check.rb +21 -0
  87. data/lib/sendgrid/helpers/mail/subscription_tracking.rb +23 -0
  88. data/lib/sendgrid/helpers/mail/substitution.rb +18 -0
  89. data/lib/sendgrid/helpers/mail/tracking_settings.rb +39 -0
  90. data/lib/sendgrid/helpers/permissions/scope.rb +28 -0
  91. data/lib/sendgrid/helpers/permissions/scopes.yml +309 -0
  92. data/lib/sendgrid/helpers/settings/README.md +14 -0
  93. data/lib/sendgrid/helpers/settings/mail_settings_dto.rb +13 -0
  94. data/lib/sendgrid/helpers/settings/partner_settings_dto.rb +13 -0
  95. data/lib/sendgrid/helpers/settings/settings.rb +28 -0
  96. data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +22 -0
  97. data/lib/sendgrid/helpers/settings/user_settings_dto.rb +13 -0
  98. data/lib/sendgrid/helpers/stats/email_stats.rb +46 -0
  99. data/lib/sendgrid/helpers/stats/metrics.rb +33 -0
  100. data/lib/sendgrid/helpers/stats/stats_response.rb +29 -0
  101. data/lib/sendgrid/sendgrid.rb +21 -0
  102. data/lib/sendgrid/twilio_email.rb +21 -0
  103. data/lib/sendgrid/version.rb +1 -1
  104. data/lib/sendgrid-ruby.rb +32 -7
  105. data/mail_helper_v3.md +390 -0
  106. data/sendgrid-ruby.gemspec +16 -20
  107. data/spec/fixtures/event_webhook.rb +22 -0
  108. data/spec/rack/sendgrid_webhook_verification_spec.rb +142 -0
  109. data/spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb +105 -0
  110. data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
  111. data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +32 -0
  112. data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +24 -0
  113. data/spec/sendgrid/helpers/settings/settings_spec.rb +25 -0
  114. data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +27 -0
  115. data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +24 -0
  116. data/spec/sendgrid/helpers/stats/email_stats_spec.rb +111 -0
  117. data/spec/sendgrid/helpers/stats/metrics_spec.rb +45 -0
  118. data/spec/sendgrid/helpers/stats/stats_response_spec.rb +75 -0
  119. data/spec/sendgrid/sendgrid_spec.rb +11 -0
  120. data/spec/sendgrid/twilio_email_spec.rb +11 -0
  121. data/spec/spec_helper.rb +12 -1
  122. data/static/img/github-fork.png +0 -0
  123. data/static/img/github-sign-up.png +0 -0
  124. data/test/sendgrid/helpers/mail/test_attachment.rb +33 -0
  125. data/test/sendgrid/helpers/mail/test_category.rb +25 -0
  126. data/test/sendgrid/helpers/mail/test_email.rb +41 -0
  127. data/test/sendgrid/helpers/mail/test_mail.rb +260 -0
  128. data/test/sendgrid/helpers/mail/test_personalizations.rb +214 -0
  129. data/test/sendgrid/permissions/test_scopes.rb +36 -0
  130. data/test/sendgrid/test_sendgrid-ruby.rb +2729 -0
  131. data/twilio_sendgrid_logo.png +0 -0
  132. data/use-cases/README.md +17 -0
  133. data/use-cases/domain-authentication.md +5 -0
  134. data/use-cases/email-statistics.md +52 -0
  135. data/use-cases/legacy-templates.md +98 -0
  136. data/use-cases/personalizations.md +34 -0
  137. data/use-cases/sms.md +39 -0
  138. data/use-cases/transactional-templates.md +111 -0
  139. data/use-cases/twilio-email.md +13 -0
  140. data/use-cases/twilio-setup.md +54 -0
  141. metadata +187 -112
  142. data/.rspec +0 -2
  143. data/.travis.yml +0 -20
  144. data/FETCH_HEAD +0 -0
  145. data/Guardfile +0 -10
  146. data/LICENSE.txt +0 -22
  147. data/example.rb +0 -41
  148. data/lib/sendgrid/client.rb +0 -62
  149. data/lib/sendgrid/exceptions.rb +0 -7
  150. data/lib/sendgrid/mail.rb +0 -182
  151. data/lib/sendgrid/recipient.rb +0 -29
  152. data/lib/sendgrid/response.rb +0 -14
  153. data/lib/sendgrid/template.rb +0 -26
  154. data/lib/sendgrid/template_mailer.rb +0 -59
  155. data/spec/lib/sendgrid/client_spec.rb +0 -87
  156. data/spec/lib/sendgrid/mail_spec.rb +0 -151
  157. data/spec/lib/sendgrid/recipient_spec.rb +0 -91
  158. data/spec/lib/sendgrid/template_mailer_spec.rb +0 -86
  159. data/spec/lib/sendgrid/template_spec.rb +0 -61
  160. data/spec/lib/sendgrid_spec.rb +0 -7
@@ -0,0 +1,28 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class Ganalytics
5
+ attr_accessor :enable, :utm_source, :utm_medium, :utm_term, :utm_content, :utm_name, :utm_campaign
6
+
7
+ def initialize(enable: nil, utm_source: nil, utm_medium: nil, utm_term: nil, utm_content: nil, utm_campaign: nil, utm_name: nil)
8
+ @enable = enable
9
+ @utm_source = utm_source
10
+ @utm_medium = utm_medium
11
+ @utm_term = utm_term
12
+ @utm_content = utm_content
13
+ @utm_campaign = utm_campaign
14
+ @utm_name = utm_name
15
+ end
16
+
17
+ def to_json(*)
18
+ {
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
25
+ }.delete_if { |_, value| value.to_s.strip == '' }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class Header
5
+ attr_accessor :header
6
+
7
+ def initialize(key: nil, value: nil)
8
+ @header = {}
9
+ key.nil? || value.nil? ? @header = nil : @header[key] = value
10
+ end
11
+
12
+ def to_json(*)
13
+ {
14
+ 'header' => header
15
+ }.delete_if { |_, value| value.to_s.strip == '' }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,122 @@
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
+ attr_accessor :subject, :ip_pool_name, :template_id, :send_at, :batch_id
8
+ attr_reader :personalizations, :contents, :attachments, :categories, :sections, :headers, :custom_args
9
+ attr_writer :from, :asm, :mail_settings, :tracking_settings, :reply_to
10
+
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
14
+ @from = nil
15
+ @subject = nil
16
+ @personalizations = []
17
+ @contents = []
18
+ @attachments = []
19
+ @template_id = nil
20
+ @sections = {}
21
+ @headers = {}
22
+ @categories = []
23
+ @custom_args = {}
24
+ @send_at = nil
25
+ @batch_id = nil
26
+ @asm = nil
27
+ @ip_pool_name = nil
28
+ @mail_settings = nil
29
+ @tracking_settings = nil
30
+ @reply_to = nil
31
+
32
+ return if from_email.nil? && subj.nil? && to_email.nil? && cont.nil?
33
+
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
+ end
41
+
42
+ def from
43
+ @from.nil? ? nil : @from.to_json
44
+ end
45
+
46
+ def add_personalization(personalization)
47
+ @personalizations << personalization.to_json
48
+ end
49
+
50
+ def add_content(content)
51
+ @contents << content.to_json
52
+ end
53
+
54
+ def check_for_secrets(patterns)
55
+ contents = @contents.map { |content| content['value'] }.join(' ')
56
+ patterns.each do |pattern|
57
+ raise SecurityError, 'Content contains sensitive information.' if contents.match(pattern)
58
+ end
59
+ end
60
+
61
+ def add_attachment(attachment)
62
+ @attachments << attachment.to_json
63
+ end
64
+
65
+ def add_category(category)
66
+ @categories << category.name
67
+ end
68
+
69
+ def add_section(section)
70
+ section = section.to_json
71
+ @sections = @sections.merge(section['section'])
72
+ end
73
+
74
+ def add_header(header)
75
+ header = header.to_json
76
+ @headers = @headers.merge(header['header'])
77
+ end
78
+
79
+ def add_custom_arg(custom_arg)
80
+ custom_arg = custom_arg.to_json
81
+ @custom_args = @custom_args.merge(custom_arg['custom_arg'])
82
+ end
83
+
84
+ def asm
85
+ @asm.nil? ? nil : @asm.to_json
86
+ end
87
+
88
+ def mail_settings
89
+ @mail_settings.nil? ? nil : @mail_settings.to_json
90
+ end
91
+
92
+ def tracking_settings
93
+ @tracking_settings.nil? ? nil : @tracking_settings.to_json
94
+ end
95
+
96
+ def reply_to
97
+ @reply_to.nil? ? nil : @reply_to.to_json
98
+ end
99
+
100
+ def to_json(*)
101
+ {
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 == {} }
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,45 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class MailSettings
5
+ attr_writer :sandbox_mode, :footer, :bcc, :spam_check, :bypass_list_management
6
+
7
+ def initialize
8
+ @bcc = nil
9
+ @bypass_list_management = nil
10
+ @footer = nil
11
+ @sandbox_mode = nil
12
+ @spam_check = nil
13
+ end
14
+
15
+ def sandbox_mode
16
+ @sandbox_mode.nil? ? nil : @sandbox_mode.to_json
17
+ end
18
+
19
+ def bypass_list_management
20
+ @bypass_list_management.nil? ? nil : @bypass_list_management.to_json
21
+ end
22
+
23
+ def footer
24
+ @footer.nil? ? nil : @footer.to_json
25
+ end
26
+
27
+ def bcc
28
+ @bcc.nil? ? nil : @bcc.to_json
29
+ end
30
+
31
+ def spam_check
32
+ @spam_check.nil? ? nil : @spam_check.to_json
33
+ end
34
+
35
+ def to_json(*)
36
+ {
37
+ 'bcc' => bcc,
38
+ 'bypass_list_management' => bypass_list_management,
39
+ 'footer' => footer,
40
+ 'sandbox_mode' => sandbox_mode,
41
+ 'spam_check' => spam_check
42
+ }.delete_if { |_, value| value.to_s.strip == '' }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,19 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class OpenTracking
5
+ attr_accessor :enable, :substitution_tag
6
+
7
+ def initialize(enable: nil, substitution_tag: nil)
8
+ @enable = enable
9
+ @substitution_tag = substitution_tag
10
+ end
11
+
12
+ def to_json(*)
13
+ {
14
+ 'enable' => enable,
15
+ 'substitution_tag' => substitution_tag
16
+ }.delete_if { |_, value| value.to_s.strip == '' }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,93 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class Personalization
5
+ attr_reader :tos, :from, :ccs, :bccs, :headers, :substitutions, :custom_args,
6
+ :dynamic_template_data
7
+
8
+ attr_accessor :send_at, :subject
9
+
10
+ def initialize
11
+ @tos = []
12
+ @from = nil
13
+ @ccs = []
14
+ @bccs = []
15
+ @subject = nil
16
+ @headers = {}
17
+ @substitutions = {}
18
+ @custom_args = {}
19
+ @dynamic_template_data = {}
20
+ @send_at = nil
21
+ end
22
+
23
+ def add_to(to)
24
+ raise DuplicatePersonalizationError if duplicate?(to)
25
+
26
+ @tos << to.to_json
27
+ end
28
+
29
+ def add_from(from)
30
+ @from = from.to_json
31
+ end
32
+
33
+ def add_cc(cc)
34
+ raise DuplicatePersonalizationError if duplicate?(cc)
35
+
36
+ @ccs << cc.to_json
37
+ end
38
+
39
+ def add_bcc(bcc)
40
+ raise DuplicatePersonalizationError if duplicate?(bcc)
41
+
42
+ @bccs << bcc.to_json
43
+ end
44
+
45
+ def add_header(header)
46
+ header = header.to_json
47
+ @headers = @headers.merge(header['header'])
48
+ end
49
+
50
+ def add_substitution(substitution)
51
+ substitution = substitution.to_json
52
+ @substitutions = @substitutions.merge(substitution['substitution'])
53
+ end
54
+
55
+ def add_custom_arg(custom_arg)
56
+ custom_arg = custom_arg.to_json
57
+ @custom_args = @custom_args.merge(custom_arg['custom_arg'])
58
+ end
59
+
60
+ def add_dynamic_template_data(dynamic_template_data)
61
+ @dynamic_template_data.merge!(dynamic_template_data)
62
+ end
63
+
64
+ def to_json(*)
65
+ {
66
+ 'to' => tos,
67
+ 'from' => from,
68
+ 'cc' => ccs,
69
+ 'bcc' => bccs,
70
+ 'subject' => subject,
71
+ 'headers' => headers,
72
+ 'substitutions' => substitutions,
73
+ 'custom_args' => custom_args,
74
+ 'dynamic_template_data' => dynamic_template_data,
75
+ 'send_at' => send_at
76
+ }.delete_if { |_, value| value.to_s.strip == '' || value == [] || value == {} }
77
+ end
78
+
79
+ private
80
+
81
+ def duplicate?(addition)
82
+ additional_email = addition.email.downcase
83
+
84
+ [@tos, @ccs, @bccs].flatten.each do |elm|
85
+ return true if elm&.dig('email')&.downcase == additional_email
86
+ end
87
+
88
+ false
89
+ end
90
+ end
91
+
92
+ class DuplicatePersonalizationError < StandardError; end
93
+ end
@@ -0,0 +1,18 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class Section
5
+ attr_accessor :section
6
+
7
+ def initialize(key: nil, value: nil)
8
+ @section = {}
9
+ key.nil? || value.nil? ? @section = nil : @section[key] = value
10
+ end
11
+
12
+ def to_json(*)
13
+ {
14
+ 'section' => section
15
+ }.delete_if { |_, value| value.to_s.strip == '' }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class SpamCheck
5
+ attr_accessor :enable, :threshold, :post_to_url
6
+
7
+ def initialize(enable: nil, threshold: nil, post_to_url: nil)
8
+ @enable = enable
9
+ @threshold = threshold
10
+ @post_to_url = post_to_url
11
+ end
12
+
13
+ def to_json(*)
14
+ {
15
+ 'enable' => enable,
16
+ 'threshold' => threshold,
17
+ 'post_to_url' => post_to_url
18
+ }.delete_if { |_, value| value.to_s.strip == '' }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class SubscriptionTracking
5
+ attr_accessor :enable, :text, :html, :substitution_tag
6
+
7
+ def initialize(enable: nil, text: nil, html: nil, substitution_tag: nil)
8
+ @enable = enable
9
+ @text = text
10
+ @html = html
11
+ @substitution_tag = substitution_tag
12
+ end
13
+
14
+ def to_json(*)
15
+ {
16
+ 'enable' => enable,
17
+ 'text' => text,
18
+ 'html' => html,
19
+ 'substitution_tag' => substitution_tag
20
+ }.delete_if { |_, value| value.to_s.strip == '' }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class Substitution
5
+ attr_accessor :substitution
6
+
7
+ def initialize(key: nil, value: nil)
8
+ @substitution = {}
9
+ key.nil? || value.nil? ? @substitution = nil : @substitution[key] = value
10
+ end
11
+
12
+ def to_json(*)
13
+ {
14
+ 'substitution' => substitution
15
+ }.delete_if { |_, value| value.to_s.strip == '' }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,39 @@
1
+ require 'json'
2
+
3
+ module SendGrid
4
+ class TrackingSettings
5
+ attr_writer :click_tracking, :open_tracking, :subscription_tracking, :ganalytics
6
+
7
+ def initialize
8
+ @click_tracking = nil
9
+ @open_tracking = nil
10
+ @subscription_tracking = nil
11
+ @ganalytics = nil
12
+ end
13
+
14
+ def click_tracking
15
+ @click_tracking.nil? ? nil : @click_tracking.to_json
16
+ end
17
+
18
+ def open_tracking
19
+ @open_tracking.nil? ? nil : @open_tracking.to_json
20
+ end
21
+
22
+ def subscription_tracking
23
+ @subscription_tracking.nil? ? nil : @subscription_tracking.to_json
24
+ end
25
+
26
+ def ganalytics
27
+ @ganalytics.nil? ? nil : @ganalytics.to_json
28
+ end
29
+
30
+ def to_json(*)
31
+ {
32
+ 'click_tracking' => click_tracking,
33
+ 'open_tracking' => open_tracking,
34
+ 'subscription_tracking' => subscription_tracking,
35
+ 'ganalytics' => ganalytics
36
+ }.delete_if { |_, value| value.to_s.strip == '' }
37
+ end
38
+ end
39
+ 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