sendgrid-ruby 5.3.0 → 6.7.0

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 (143) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/pr-lint.yml +15 -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 +261 -8
  8. data/CODE_OF_CONDUCT.md +57 -25
  9. data/CONTRIBUTING.md +24 -71
  10. data/Dockerfile +14 -0
  11. data/FIRST_TIMERS.md +53 -0
  12. data/Gemfile +0 -1
  13. data/LICENSE +21 -0
  14. data/Makefile +14 -0
  15. data/PULL_REQUEST_TEMPLATE.md +31 -0
  16. data/README.md +39 -43
  17. data/Rakefile +3 -4
  18. data/TROUBLESHOOTING.md +41 -21
  19. data/UPGRADE.md +5 -0
  20. data/USAGE.md +1231 -1122
  21. data/examples/accesssettings/accesssettings.rb +9 -12
  22. data/examples/alerts/alerts.rb +8 -11
  23. data/examples/apikeys/apikeys.rb +12 -15
  24. data/examples/asm/asm.rb +27 -30
  25. data/examples/browsers/browsers.rb +0 -3
  26. data/examples/campaigns/campaigns.rb +29 -32
  27. data/examples/categories/categories.rb +0 -3
  28. data/examples/clients/clients.rb +1 -4
  29. data/examples/contactdb/contactdb.rb +63 -66
  30. data/examples/dataresidency/setregion.rb +48 -0
  31. data/examples/devices/devices.rb +0 -3
  32. data/examples/emailactivity/emailactivity.rb +52 -0
  33. data/examples/geo/geo.rb +0 -3
  34. data/examples/helpers/eventwebhook/example.rb +16 -0
  35. data/examples/helpers/mail/example.rb +30 -19
  36. data/examples/helpers/settings/example.rb +1 -1
  37. data/examples/helpers/stats/example.rb +4 -4
  38. data/examples/ips/ips.rb +31 -21
  39. data/examples/mail/mail.rb +73 -76
  40. data/examples/mailboxproviders/mailboxproviders.rb +0 -3
  41. data/examples/mailsettings/mailsettings.rb +21 -24
  42. data/examples/partnersettings/partnersettings.rb +3 -6
  43. data/examples/scopes/scopes.rb +49 -5
  44. data/examples/{whitelabel/whitelabel.rb → senderauthentication/senderauthentication.rb} +68 -71
  45. data/examples/senders/senders.rb +28 -31
  46. data/examples/stats/stats.rb +0 -3
  47. data/examples/subusers/subusers.rb +17 -20
  48. data/examples/suppression/suppression.rb +23 -26
  49. data/examples/templates/templates.rb +29 -31
  50. data/examples/trackingsettings/trackingsettings.rb +14 -17
  51. data/examples/user/user.rb +41 -44
  52. data/lib/rack/sendgrid_webhook_verification.rb +55 -0
  53. data/lib/sendgrid/base_interface.rb +57 -0
  54. data/lib/sendgrid/helpers/eventwebhook/eventwebhook.rb +50 -0
  55. data/lib/sendgrid/helpers/inbound/README.md +26 -9
  56. data/lib/sendgrid/helpers/inbound/app.rb +15 -3
  57. data/lib/sendgrid/helpers/inbound/public/index.html +2 -2
  58. data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +2 -2
  59. data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +2 -2
  60. data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +2 -2
  61. data/lib/sendgrid/helpers/inbound/send.rb +5 -5
  62. data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
  63. data/lib/sendgrid/helpers/mail/README.md +4 -4
  64. data/lib/sendgrid/helpers/mail/asm.rb +4 -18
  65. data/lib/sendgrid/helpers/mail/attachment.rb +30 -38
  66. data/lib/sendgrid/helpers/mail/bcc_settings.rb +4 -18
  67. data/lib/sendgrid/helpers/mail/bypass_list_management.rb +6 -18
  68. data/lib/sendgrid/helpers/mail/category.rb +2 -12
  69. data/lib/sendgrid/helpers/mail/click_tracking.rb +4 -18
  70. data/lib/sendgrid/helpers/mail/content.rb +4 -18
  71. data/lib/sendgrid/helpers/mail/custom_arg.rb +4 -10
  72. data/lib/sendgrid/helpers/mail/email.rb +10 -20
  73. data/lib/sendgrid/helpers/mail/footer.rb +5 -27
  74. data/lib/sendgrid/helpers/mail/ganalytics.rb +9 -55
  75. data/lib/sendgrid/helpers/mail/header.rb +4 -10
  76. data/lib/sendgrid/helpers/mail/mail.rb +37 -87
  77. data/lib/sendgrid/helpers/mail/mail_settings.rb +7 -25
  78. data/lib/sendgrid/helpers/mail/open_tracking.rb +4 -18
  79. data/lib/sendgrid/helpers/mail/personalization.rb +38 -27
  80. data/lib/sendgrid/helpers/mail/section.rb +4 -10
  81. data/lib/sendgrid/helpers/mail/spam_check.rb +5 -27
  82. data/lib/sendgrid/helpers/mail/subscription_tracking.rb +6 -36
  83. data/lib/sendgrid/helpers/mail/substitution.rb +4 -10
  84. data/lib/sendgrid/helpers/mail/tracking_settings.rb +6 -20
  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 +3 -3
  88. data/lib/sendgrid/helpers/settings/settings.rb +1 -1
  89. data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +3 -5
  90. data/lib/sendgrid/helpers/stats/metrics.rb +5 -7
  91. data/lib/sendgrid/helpers/stats/stats_response.rb +1 -3
  92. data/lib/sendgrid/sendgrid.rb +21 -0
  93. data/lib/sendgrid/twilio_email.rb +21 -0
  94. data/lib/sendgrid/version.rb +1 -1
  95. data/lib/sendgrid-ruby.rb +7 -1
  96. data/mail_helper_v3.md +21 -21
  97. data/sendgrid-ruby.gemspec +12 -12
  98. data/spec/fixtures/event_webhook.rb +22 -0
  99. data/spec/rack/sendgrid_webhook_verification_spec.rb +142 -0
  100. data/spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb +105 -0
  101. data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
  102. data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +3 -3
  103. data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +3 -3
  104. data/spec/sendgrid/helpers/settings/settings_spec.rb +2 -2
  105. data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +3 -3
  106. data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +3 -3
  107. data/spec/sendgrid/helpers/stats/email_stats_spec.rb +22 -23
  108. data/spec/sendgrid/helpers/stats/metrics_spec.rb +19 -20
  109. data/spec/sendgrid/helpers/stats/stats_response_spec.rb +22 -23
  110. data/spec/sendgrid/sendgrid_spec.rb +11 -0
  111. data/spec/sendgrid/twilio_email_spec.rb +11 -0
  112. data/spec/spec_helper.rb +3 -1
  113. data/static/img/github-fork.png +0 -0
  114. data/static/img/github-sign-up.png +0 -0
  115. data/test/sendgrid/helpers/mail/test_attachment.rb +33 -0
  116. data/test/sendgrid/helpers/mail/test_category.rb +0 -2
  117. data/test/sendgrid/helpers/mail/test_data_residency.rb +44 -0
  118. data/test/sendgrid/helpers/mail/test_email.rb +17 -10
  119. data/test/sendgrid/helpers/mail/test_mail.rb +126 -119
  120. data/test/sendgrid/helpers/mail/test_personalizations.rb +145 -92
  121. data/test/sendgrid/permissions/test_scopes.rb +36 -0
  122. data/test/sendgrid/test_sendgrid-ruby.rb +1961 -1979
  123. data/twilio_sendgrid_logo.png +0 -0
  124. data/use-cases/README.md +17 -0
  125. data/use-cases/domain-authentication.md +5 -0
  126. data/use-cases/email-statistics.md +52 -0
  127. data/use-cases/legacy-templates.md +98 -0
  128. data/use-cases/personalizations.md +34 -0
  129. data/use-cases/sms.md +39 -0
  130. data/use-cases/transactional-templates.md +111 -0
  131. data/use-cases/twilio-email.md +13 -0
  132. data/use-cases/twilio-setup.md +54 -0
  133. metadata +99 -45
  134. data/.codeclimate.yml +0 -21
  135. data/.github/ISSUE_TEMPLATE +0 -17
  136. data/.github/PULL_REQUEST_TEMPLATE +0 -24
  137. data/.travis.yml +0 -29
  138. data/LICENSE.txt +0 -22
  139. data/USE_CASES.md +0 -147
  140. data/docker/Dockerfile +0 -12
  141. data/docker/README.md +0 -30
  142. data/lib/sendgrid/client.rb +0 -35
  143. data/test/prism.sh +0 -42
data/examples/ips/ips.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  require 'sendgrid-ruby'
2
2
 
3
-
4
3
  sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
4
 
6
-
7
5
  ##################################################
8
6
  # Retrieve all IP addresses #
9
7
  # GET /ips #
@@ -18,11 +16,24 @@ puts response.headers
18
16
  # Retrieve all assigned IPs #
19
17
  # GET /ips/assigned #
20
18
 
21
- response = sg.client.ips.assigned.get()
19
+ response = sg.client.ips.assigned.get
22
20
  puts response.status_code
23
21
  puts response.body
24
22
  puts response.headers
25
23
 
24
+ ##################################################
25
+ # Retrieve unassigned IPs #
26
+ # GET /ips #
27
+
28
+ params = {}
29
+ response = sg.client.ips.get(query_params: params)
30
+ all_ips = JSON.parse(response.body)
31
+ unassigned_ips = all_ips.select { |ip| ip.subusers.empty? }
32
+ puts response.status_code
33
+ puts response.body
34
+ puts unassigned_ips
35
+ puts response.headers
36
+
26
37
  ##################################################
27
38
  # Create an IP pool. #
28
39
  # POST /ips/pools #
@@ -39,7 +50,7 @@ puts response.headers
39
50
  # Retrieve all IP pools. #
40
51
  # GET /ips/pools #
41
52
 
42
- response = sg.client.ips.pools.get()
53
+ response = sg.client.ips.pools.get
43
54
  puts response.status_code
44
55
  puts response.body
45
56
  puts response.headers
@@ -51,7 +62,7 @@ puts response.headers
51
62
  data = JSON.parse('{
52
63
  "name": "new_pool_name"
53
64
  }')
54
- pool_name = "test_url_param"
65
+ pool_name = 'test_url_param'
55
66
  response = sg.client.ips.pools._(pool_name).put(request_body: data)
56
67
  puts response.status_code
57
68
  puts response.body
@@ -61,8 +72,8 @@ puts response.headers
61
72
  # Retrieve all IPs in a specified pool. #
62
73
  # GET /ips/pools/{pool_name} #
63
74
 
64
- pool_name = "test_url_param"
65
- response = sg.client.ips.pools._(pool_name).get()
75
+ pool_name = 'test_url_param'
76
+ response = sg.client.ips.pools._(pool_name).get
66
77
  puts response.status_code
67
78
  puts response.body
68
79
  puts response.headers
@@ -71,8 +82,8 @@ puts response.headers
71
82
  # Delete an IP pool. #
72
83
  # DELETE /ips/pools/{pool_name} #
73
84
 
74
- pool_name = "test_url_param"
75
- response = sg.client.ips.pools._(pool_name).delete()
85
+ pool_name = 'test_url_param'
86
+ response = sg.client.ips.pools._(pool_name).delete
76
87
  puts response.status_code
77
88
  puts response.body
78
89
  puts response.headers
@@ -84,7 +95,7 @@ puts response.headers
84
95
  data = JSON.parse('{
85
96
  "ip": "0.0.0.0"
86
97
  }')
87
- pool_name = "test_url_param"
98
+ pool_name = 'test_url_param'
88
99
  response = sg.client.ips.pools._(pool_name).ips.post(request_body: data)
89
100
  puts response.status_code
90
101
  puts response.body
@@ -94,9 +105,9 @@ puts response.headers
94
105
  # Remove an IP address from a pool. #
95
106
  # DELETE /ips/pools/{pool_name}/ips/{ip} #
96
107
 
97
- pool_name = "test_url_param"
98
- ip = "test_url_param"
99
- response = sg.client.ips.pools._(pool_name).ips._(ip).delete()
108
+ pool_name = 'test_url_param'
109
+ ip = 'test_url_param'
110
+ response = sg.client.ips.pools._(pool_name).ips._(ip).delete
100
111
  puts response.status_code
101
112
  puts response.body
102
113
  puts response.headers
@@ -117,7 +128,7 @@ puts response.headers
117
128
  # Retrieve all IPs currently in warmup #
118
129
  # GET /ips/warmup #
119
130
 
120
- response = sg.client.ips.warmup.get()
131
+ response = sg.client.ips.warmup.get
121
132
  puts response.status_code
122
133
  puts response.body
123
134
  puts response.headers
@@ -126,8 +137,8 @@ puts response.headers
126
137
  # Retrieve warmup status for a specific IP address #
127
138
  # GET /ips/warmup/{ip_address} #
128
139
 
129
- ip_address = "test_url_param"
130
- response = sg.client.ips.warmup._(ip_address).get()
140
+ ip_address = 'test_url_param'
141
+ response = sg.client.ips.warmup._(ip_address).get
131
142
  puts response.status_code
132
143
  puts response.body
133
144
  puts response.headers
@@ -136,8 +147,8 @@ puts response.headers
136
147
  # Remove an IP from warmup #
137
148
  # DELETE /ips/warmup/{ip_address} #
138
149
 
139
- ip_address = "test_url_param"
140
- response = sg.client.ips.warmup._(ip_address).delete()
150
+ ip_address = 'test_url_param'
151
+ response = sg.client.ips.warmup._(ip_address).delete
141
152
  puts response.status_code
142
153
  puts response.body
143
154
  puts response.headers
@@ -146,9 +157,8 @@ puts response.headers
146
157
  # Retrieve all IP pools an IP address belongs to #
147
158
  # GET /ips/{ip_address} #
148
159
 
149
- ip_address = "test_url_param"
150
- response = sg.client.ips._(ip_address).get()
160
+ ip_address = 'test_url_param'
161
+ response = sg.client.ips._(ip_address).get
151
162
  puts response.status_code
152
163
  puts response.body
153
164
  puts response.headers
154
-
@@ -1,14 +1,12 @@
1
1
  require 'sendgrid-ruby'
2
2
 
3
-
4
3
  sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
4
 
6
-
7
5
  ##################################################
8
6
  # Create a batch ID #
9
7
  # POST /mail/batch #
10
8
 
11
- response = sg.client.mail.batch.post()
9
+ response = sg.client.mail.batch.post
12
10
  puts response.status_code
13
11
  puts response.body
14
12
  puts response.headers
@@ -17,8 +15,8 @@ puts response.headers
17
15
  # Validate batch ID #
18
16
  # GET /mail/batch/{batch_id} #
19
17
 
20
- batch_id = "test_url_param"
21
- response = sg.client.mail.batch._(batch_id).get()
18
+ batch_id = 'test_url_param'
19
+ response = sg.client.mail.batch._(batch_id).get
22
20
  puts response.status_code
23
21
  puts response.body
24
22
  puts response.headers
@@ -26,148 +24,147 @@ puts response.headers
26
24
  ##################################################
27
25
  # v3 Mail Send #
28
26
  # POST /mail/send #
29
- # This endpoint has a helper, check it out [here](https://github.com/sendgrid/sendgrid-ruby/blob/master/lib/helpers/mail/README.md).
27
+ # This endpoint has a helper, check it out [here](https://github.com/sendgrid/sendgrid-ruby/blob/HEAD/lib/sendgrid/helpers/mail/README.md).
30
28
 
31
29
  data = JSON.parse('{
32
30
  "asm": {
33
- "group_id": 1,
31
+ "group_id": 1,
34
32
  "groups_to_display": [
35
- 1,
36
- 2,
33
+ 1,
34
+ 2,
37
35
  3
38
36
  ]
39
- },
37
+ },
40
38
  "attachments": [
41
39
  {
42
- "content": "[BASE64 encoded content block here]",
43
- "content_id": "ii_139db99fdb5c3704",
44
- "disposition": "inline",
45
- "filename": "file1.jpg",
46
- "name": "file1",
40
+ "content": "[BASE64 encoded content block here]",
41
+ "content_id": "ii_139db99fdb5c3704",
42
+ "disposition": "inline",
43
+ "filename": "file1.jpg",
44
+ "name": "file1",
47
45
  "type": "jpg"
48
46
  }
49
- ],
50
- "batch_id": "[YOUR BATCH ID GOES HERE]",
47
+ ],
48
+ "batch_id": "[YOUR BATCH ID GOES HERE]",
51
49
  "categories": [
52
- "category1",
50
+ "category1",
53
51
  "category2"
54
- ],
52
+ ],
55
53
  "content": [
56
54
  {
57
- "type": "text/html",
55
+ "type": "text/html",
58
56
  "value": "<html><p>Hello, world!</p><img src=[CID GOES HERE]></img></html>"
59
57
  }
60
- ],
58
+ ],
61
59
  "custom_args": {
62
- "New Argument 1": "New Value 1",
63
- "activationAttempt": "1",
60
+ "New Argument 1": "New Value 1",
61
+ "activationAttempt": "1",
64
62
  "customerAccountNumber": "[CUSTOMER ACCOUNT NUMBER GOES HERE]"
65
- },
63
+ },
66
64
  "from": {
67
- "email": "sam.smith@example.com",
65
+ "email": "sam.smith@example.com",
68
66
  "name": "Sam Smith"
69
- },
70
- "headers": {},
71
- "ip_pool_name": "[YOUR POOL NAME GOES HERE]",
67
+ },
68
+ "headers": {},
69
+ "ip_pool_name": "[YOUR POOL NAME GOES HERE]",
72
70
  "mail_settings": {
73
71
  "bcc": {
74
- "email": "ben.doe@example.com",
72
+ "email": "ben.doe@example.com",
75
73
  "enable": true
76
- },
74
+ },
77
75
  "bypass_list_management": {
78
76
  "enable": true
79
- },
77
+ },
80
78
  "footer": {
81
- "enable": true,
82
- "html": "<p>Thanks</br>The SendGrid Team</p>",
83
- "text": "Thanks,/n The SendGrid Team"
84
- },
79
+ "enable": true,
80
+ "html": "<p>Thanks</br>The Twilio SendGrid Team</p>",
81
+ "text": "Thanks,/n The Twilio SendGrid Team"
82
+ },
85
83
  "sandbox_mode": {
86
84
  "enable": false
87
- },
85
+ },
88
86
  "spam_check": {
89
- "enable": true,
90
- "post_to_url": "http://example.com/compliance",
87
+ "enable": true,
88
+ "post_to_url": "http://example.com/compliance",
91
89
  "threshold": 3
92
90
  }
93
- },
91
+ },
94
92
  "personalizations": [
95
93
  {
96
94
  "bcc": [
97
95
  {
98
- "email": "sam.doe@example.com",
96
+ "email": "sam.doe@example.com",
99
97
  "name": "Sam Doe"
100
98
  }
101
- ],
99
+ ],
102
100
  "cc": [
103
101
  {
104
- "email": "jane.doe@example.com",
102
+ "email": "jane.doe@example.com",
105
103
  "name": "Jane Doe"
106
104
  }
107
- ],
105
+ ],
108
106
  "custom_args": {
109
- "New Argument 1": "New Value 1",
110
- "activationAttempt": "1",
107
+ "New Argument 1": "New Value 1",
108
+ "activationAttempt": "1",
111
109
  "customerAccountNumber": "[CUSTOMER ACCOUNT NUMBER GOES HERE]"
112
- },
110
+ },
113
111
  "headers": {
114
- "X-Accept-Language": "en",
112
+ "X-Accept-Language": "en",
115
113
  "X-Mailer": "MyApp"
116
- },
117
- "send_at": 1409348513,
118
- "subject": "Hello, World!",
114
+ },
115
+ "send_at": 1409348513,
116
+ "subject": "Hello, World!",
119
117
  "substitutions": {
120
- "id": "substitutions",
118
+ "id": "substitutions",
121
119
  "type": "object"
122
- },
120
+ },
123
121
  "to": [
124
122
  {
125
- "email": "john.doe@example.com",
123
+ "email": "john.doe@example.com",
126
124
  "name": "John Doe"
127
125
  }
128
126
  ]
129
127
  }
130
- ],
128
+ ],
131
129
  "reply_to": {
132
- "email": "sam.smith@example.com",
130
+ "email": "sam.smith@example.com",
133
131
  "name": "Sam Smith"
134
- },
132
+ },
135
133
  "sections": {
136
134
  "section": {
137
- ":sectionName1": "section 1 text",
135
+ ":sectionName1": "section 1 text",
138
136
  ":sectionName2": "section 2 text"
139
137
  }
140
- },
141
- "send_at": 1409348513,
142
- "subject": "Hello, World!",
143
- "template_id": "[YOUR TEMPLATE ID GOES HERE]",
138
+ },
139
+ "send_at": 1409348513,
140
+ "subject": "Hello, World!",
141
+ "template_id": "[YOUR TEMPLATE ID GOES HERE]",
144
142
  "tracking_settings": {
145
143
  "click_tracking": {
146
- "enable": true,
144
+ "enable": true,
147
145
  "enable_text": true
148
- },
146
+ },
149
147
  "ganalytics": {
150
- "enable": true,
151
- "utm_campaign": "[NAME OF YOUR REFERRER SOURCE]",
152
- "utm_content": "[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]",
153
- "utm_medium": "[NAME OF YOUR MARKETING MEDIUM e.g. email]",
154
- "utm_name": "[NAME OF YOUR CAMPAIGN]",
148
+ "enable": true,
149
+ "utm_campaign": "[NAME OF YOUR REFERRER SOURCE]",
150
+ "utm_content": "[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]",
151
+ "utm_medium": "[NAME OF YOUR MARKETING MEDIUM e.g. email]",
152
+ "utm_name": "[NAME OF YOUR CAMPAIGN]",
155
153
  "utm_term": "[IDENTIFY PAID KEYWORDS HERE]"
156
- },
154
+ },
157
155
  "open_tracking": {
158
- "enable": true,
156
+ "enable": true,
159
157
  "substitution_tag": "%opentrack"
160
- },
158
+ },
161
159
  "subscription_tracking": {
162
- "enable": true,
163
- "html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.",
164
- "substitution_tag": "<%click here%>",
160
+ "enable": true,
161
+ "html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.",
162
+ "substitution_tag": "<%click here%>",
165
163
  "text": "If you would like to unsubscribe and stop receiveing these emails <% click here %>."
166
164
  }
167
165
  }
168
166
  }')
169
- response = sg.client.mail._("send").post(request_body: data)
167
+ response = sg.client.mail._('send').post(request_body: data)
170
168
  puts response.status_code
171
169
  puts response.body
172
170
  puts response.headers
173
-
@@ -1,9 +1,7 @@
1
1
  require 'sendgrid-ruby'
2
2
 
3
-
4
3
  sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
4
 
6
-
7
5
  ##################################################
8
6
  # Retrieve email statistics by mailbox provider. #
9
7
  # GET /mailbox_providers/stats #
@@ -13,4 +11,3 @@ response = sg.client.mailbox_providers.stats.get(query_params: params)
13
11
  puts response.status_code
14
12
  puts response.body
15
13
  puts response.headers
16
-
@@ -1,9 +1,7 @@
1
1
  require 'sendgrid-ruby'
2
2
 
3
-
4
3
  sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
4
 
6
-
7
5
  ##################################################
8
6
  # Retrieve all mail settings #
9
7
  # GET /mail_settings #
@@ -19,9 +17,9 @@ puts response.headers
19
17
  # PATCH /mail_settings/address_whitelist #
20
18
 
21
19
  data = JSON.parse('{
22
- "enabled": true,
20
+ "enabled": true,
23
21
  "list": [
24
- "email1@example.com",
22
+ "email1@example.com",
25
23
  "example.com"
26
24
  ]
27
25
  }')
@@ -34,7 +32,7 @@ puts response.headers
34
32
  # Retrieve address whitelist mail settings #
35
33
  # GET /mail_settings/address_whitelist #
36
34
 
37
- response = sg.client.mail_settings.address_whitelist.get()
35
+ response = sg.client.mail_settings.address_whitelist.get
38
36
  puts response.status_code
39
37
  puts response.body
40
38
  puts response.headers
@@ -44,7 +42,7 @@ puts response.headers
44
42
  # PATCH /mail_settings/bcc #
45
43
 
46
44
  data = JSON.parse('{
47
- "email": "email@example.com",
45
+ "email": "email@example.com",
48
46
  "enabled": false
49
47
  }')
50
48
  response = sg.client.mail_settings.bcc.patch(request_body: data)
@@ -56,7 +54,7 @@ puts response.headers
56
54
  # Retrieve all BCC mail settings #
57
55
  # GET /mail_settings/bcc #
58
56
 
59
- response = sg.client.mail_settings.bcc.get()
57
+ response = sg.client.mail_settings.bcc.get
60
58
  puts response.status_code
61
59
  puts response.body
62
60
  puts response.headers
@@ -66,8 +64,8 @@ puts response.headers
66
64
  # PATCH /mail_settings/bounce_purge #
67
65
 
68
66
  data = JSON.parse('{
69
- "enabled": true,
70
- "hard_bounces": 5,
67
+ "enabled": true,
68
+ "hard_bounces": 5,
71
69
  "soft_bounces": 5
72
70
  }')
73
71
  response = sg.client.mail_settings.bounce_purge.patch(request_body: data)
@@ -79,7 +77,7 @@ puts response.headers
79
77
  # Retrieve bounce purge mail settings #
80
78
  # GET /mail_settings/bounce_purge #
81
79
 
82
- response = sg.client.mail_settings.bounce_purge.get()
80
+ response = sg.client.mail_settings.bounce_purge.get
83
81
  puts response.status_code
84
82
  puts response.body
85
83
  puts response.headers
@@ -89,8 +87,8 @@ puts response.headers
89
87
  # PATCH /mail_settings/footer #
90
88
 
91
89
  data = JSON.parse('{
92
- "enabled": true,
93
- "html_content": "...",
90
+ "enabled": true,
91
+ "html_content": "...",
94
92
  "plain_content": "..."
95
93
  }')
96
94
  response = sg.client.mail_settings.footer.patch(request_body: data)
@@ -102,7 +100,7 @@ puts response.headers
102
100
  # Retrieve footer mail settings #
103
101
  # GET /mail_settings/footer #
104
102
 
105
- response = sg.client.mail_settings.footer.get()
103
+ response = sg.client.mail_settings.footer.get
106
104
  puts response.status_code
107
105
  puts response.body
108
106
  puts response.headers
@@ -112,7 +110,7 @@ puts response.headers
112
110
  # PATCH /mail_settings/forward_bounce #
113
111
 
114
112
  data = JSON.parse('{
115
- "email": "example@example.com",
113
+ "email": "example@example.com",
116
114
  "enabled": true
117
115
  }')
118
116
  response = sg.client.mail_settings.forward_bounce.patch(request_body: data)
@@ -124,7 +122,7 @@ puts response.headers
124
122
  # Retrieve forward bounce mail settings #
125
123
  # GET /mail_settings/forward_bounce #
126
124
 
127
- response = sg.client.mail_settings.forward_bounce.get()
125
+ response = sg.client.mail_settings.forward_bounce.get
128
126
  puts response.status_code
129
127
  puts response.body
130
128
  puts response.headers
@@ -134,7 +132,7 @@ puts response.headers
134
132
  # PATCH /mail_settings/forward_spam #
135
133
 
136
134
  data = JSON.parse('{
137
- "email": "",
135
+ "email": "",
138
136
  "enabled": false
139
137
  }')
140
138
  response = sg.client.mail_settings.forward_spam.patch(request_body: data)
@@ -146,7 +144,7 @@ puts response.headers
146
144
  # Retrieve forward spam mail settings #
147
145
  # GET /mail_settings/forward_spam #
148
146
 
149
- response = sg.client.mail_settings.forward_spam.get()
147
+ response = sg.client.mail_settings.forward_spam.get
150
148
  puts response.status_code
151
149
  puts response.body
152
150
  puts response.headers
@@ -167,7 +165,7 @@ puts response.headers
167
165
  # Retrieve plain content mail settings #
168
166
  # GET /mail_settings/plain_content #
169
167
 
170
- response = sg.client.mail_settings.plain_content.get()
168
+ response = sg.client.mail_settings.plain_content.get
171
169
  puts response.status_code
172
170
  puts response.body
173
171
  puts response.headers
@@ -177,8 +175,8 @@ puts response.headers
177
175
  # PATCH /mail_settings/spam_check #
178
176
 
179
177
  data = JSON.parse('{
180
- "enabled": true,
181
- "max_score": 5,
178
+ "enabled": true,
179
+ "max_score": 5,
182
180
  "url": "url"
183
181
  }')
184
182
  response = sg.client.mail_settings.spam_check.patch(request_body: data)
@@ -190,7 +188,7 @@ puts response.headers
190
188
  # Retrieve spam check mail settings #
191
189
  # GET /mail_settings/spam_check #
192
190
 
193
- response = sg.client.mail_settings.spam_check.get()
191
+ response = sg.client.mail_settings.spam_check.get
194
192
  puts response.status_code
195
193
  puts response.body
196
194
  puts response.headers
@@ -200,7 +198,7 @@ puts response.headers
200
198
  # PATCH /mail_settings/template #
201
199
 
202
200
  data = JSON.parse('{
203
- "enabled": true,
201
+ "enabled": true,
204
202
  "html_content": "<% body %>"
205
203
  }')
206
204
  response = sg.client.mail_settings.template.patch(request_body: data)
@@ -212,8 +210,7 @@ puts response.headers
212
210
  # Retrieve legacy template mail settings #
213
211
  # GET /mail_settings/template #
214
212
 
215
- response = sg.client.mail_settings.template.get()
213
+ response = sg.client.mail_settings.template.get
216
214
  puts response.status_code
217
215
  puts response.body
218
216
  puts response.headers
219
-
@@ -1,9 +1,7 @@
1
1
  require 'sendgrid-ruby'
2
2
 
3
-
4
3
  sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
4
 
6
-
7
5
  ##################################################
8
6
  # Returns a list of all partner settings. #
9
7
  # GET /partner_settings #
@@ -19,8 +17,8 @@ puts response.headers
19
17
  # PATCH /partner_settings/new_relic #
20
18
 
21
19
  data = JSON.parse('{
22
- "enable_subuser_statistics": true,
23
- "enabled": true,
20
+ "enable_subuser_statistics": true,
21
+ "enabled": true,
24
22
  "license_key": ""
25
23
  }')
26
24
  response = sg.client.partner_settings.new_relic.patch(request_body: data)
@@ -32,8 +30,7 @@ puts response.headers
32
30
  # Returns all New Relic partner settings. #
33
31
  # GET /partner_settings/new_relic #
34
32
 
35
- response = sg.client.partner_settings.new_relic.get()
33
+ response = sg.client.partner_settings.new_relic.get
36
34
  puts response.status_code
37
35
  puts response.body
38
36
  puts response.headers
39
-
@@ -1,15 +1,59 @@
1
- require 'sendgrid-ruby'
2
-
3
-
1
+ require_relative '../../lib/sendgrid-ruby'
4
2
  sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
3
 
6
-
7
4
  ##################################################
8
5
  # Retrieve a list of scopes for which this user has access. #
9
6
  # GET /scopes #
10
7
 
11
- response = sg.client.scopes.get()
8
+ response = sg.client.scopes.get
9
+ puts response.status_code
10
+ puts response.body
11
+ puts response.headers
12
+
13
+ ##################################################
14
+ # Update the name & scopes of an API Key #
15
+ # PUT /api_keys/{api_key_id} #
16
+
17
+ scopes = [
18
+ "user.profile.read",
19
+ "user.profile.update"
20
+ ]
21
+
22
+ data = {
23
+ "name": "A New Hope",
24
+ "scopes": scopes
25
+ }
26
+ api_key_id = "test_url_param"
27
+ response = sg.client.api_keys._(api_key_id).put(request_body: data)
12
28
  puts response.status_code
13
29
  puts response.body
14
30
  puts response.headers
15
31
 
32
+ # The above method shows how to update the scopes
33
+ # To get various scopes that each of the endpoint has, use the following
34
+
35
+ # To get all admin permissions
36
+ scopes = SendGrid::Scope.admin_permissions
37
+
38
+ # To get all read only permissions
39
+ scopes = SendGrid::Scope.read_only_permissions
40
+
41
+ # There are two methods for each endpoints, namely
42
+ # {endpoint}_read_only_permissions and {endpoint}_full_access_permissions
43
+
44
+ # These are the endpoints :
45
+ # alerts, api_keys, asm_groups, billing, categories, credentials, stats, ips, mail_settings, mail,
46
+ # marketing_campaigns, partner_settings, scheduled_sends, subusers, suppression, teammates,
47
+ # templates, tracking_settings, user_settings, webhooks, whitelabel, access_settings
48
+
49
+ # read only permissions for alerts
50
+ scopes = SendGrid::Scope.alerts_read_only_permissions
51
+
52
+ # full access permissions for alerts
53
+ scopes = SendGrid::Scope.alerts_full_access_permissions
54
+
55
+ # read only permissions for billing
56
+ scopes = SendGrid::Scope.billing_read_only_permissions
57
+
58
+ # full access permissions for billing
59
+ scopes = SendGrid::Scope.billing_full_access_permissions