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,167 @@
1
+ require 'sendgrid-ruby'
2
+
3
+
4
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
+
6
+
7
+ ##################################################
8
+ # Retrieve all IP addresses #
9
+ # GET /ips #
10
+
11
+ params = JSON.parse('{"subuser": "test_string", "ip": "test_string", "limit": 1, "exclude_whitelabels": "true", "offset": 1}')
12
+ response = sg.client.ips.get(query_params: params)
13
+ puts response.status_code
14
+ puts response.body
15
+ puts response.headers
16
+
17
+ ##################################################
18
+ # Retrieve all assigned IPs #
19
+ # GET /ips/assigned #
20
+
21
+ response = sg.client.ips.assigned.get()
22
+ puts response.status_code
23
+ puts response.body
24
+ puts response.headers
25
+
26
+ ##################################################
27
+ # Retrieve unassigned IPs #
28
+ # GET /ips #
29
+
30
+ params = {}
31
+ response = sg.client.ips.get(query_params: params)
32
+ all_ips = JSON.parse(response.body)
33
+ unassigned_ips = all_ips.select {|ip| ip.subusers.empty?}
34
+ puts response.status_code
35
+ puts response.body
36
+ puts unassigned_ips
37
+ puts response.headers
38
+
39
+ ##################################################
40
+ # Create an IP pool. #
41
+ # POST /ips/pools #
42
+
43
+ data = JSON.parse('{
44
+ "name": "marketing"
45
+ }')
46
+ response = sg.client.ips.pools.post(request_body: data)
47
+ puts response.status_code
48
+ puts response.body
49
+ puts response.headers
50
+
51
+ ##################################################
52
+ # Retrieve all IP pools. #
53
+ # GET /ips/pools #
54
+
55
+ response = sg.client.ips.pools.get()
56
+ puts response.status_code
57
+ puts response.body
58
+ puts response.headers
59
+
60
+ ##################################################
61
+ # Update an IP pools name. #
62
+ # PUT /ips/pools/{pool_name} #
63
+
64
+ data = JSON.parse('{
65
+ "name": "new_pool_name"
66
+ }')
67
+ pool_name = "test_url_param"
68
+ response = sg.client.ips.pools._(pool_name).put(request_body: data)
69
+ puts response.status_code
70
+ puts response.body
71
+ puts response.headers
72
+
73
+ ##################################################
74
+ # Retrieve all IPs in a specified pool. #
75
+ # GET /ips/pools/{pool_name} #
76
+
77
+ pool_name = "test_url_param"
78
+ response = sg.client.ips.pools._(pool_name).get()
79
+ puts response.status_code
80
+ puts response.body
81
+ puts response.headers
82
+
83
+ ##################################################
84
+ # Delete an IP pool. #
85
+ # DELETE /ips/pools/{pool_name} #
86
+
87
+ pool_name = "test_url_param"
88
+ response = sg.client.ips.pools._(pool_name).delete()
89
+ puts response.status_code
90
+ puts response.body
91
+ puts response.headers
92
+
93
+ ##################################################
94
+ # Add an IP address to a pool #
95
+ # POST /ips/pools/{pool_name}/ips #
96
+
97
+ data = JSON.parse('{
98
+ "ip": "0.0.0.0"
99
+ }')
100
+ pool_name = "test_url_param"
101
+ response = sg.client.ips.pools._(pool_name).ips.post(request_body: data)
102
+ puts response.status_code
103
+ puts response.body
104
+ puts response.headers
105
+
106
+ ##################################################
107
+ # Remove an IP address from a pool. #
108
+ # DELETE /ips/pools/{pool_name}/ips/{ip} #
109
+
110
+ pool_name = "test_url_param"
111
+ ip = "test_url_param"
112
+ response = sg.client.ips.pools._(pool_name).ips._(ip).delete()
113
+ puts response.status_code
114
+ puts response.body
115
+ puts response.headers
116
+
117
+ ##################################################
118
+ # Add an IP to warmup #
119
+ # POST /ips/warmup #
120
+
121
+ data = JSON.parse('{
122
+ "ip": "0.0.0.0"
123
+ }')
124
+ response = sg.client.ips.warmup.post(request_body: data)
125
+ puts response.status_code
126
+ puts response.body
127
+ puts response.headers
128
+
129
+ ##################################################
130
+ # Retrieve all IPs currently in warmup #
131
+ # GET /ips/warmup #
132
+
133
+ response = sg.client.ips.warmup.get()
134
+ puts response.status_code
135
+ puts response.body
136
+ puts response.headers
137
+
138
+ ##################################################
139
+ # Retrieve warmup status for a specific IP address #
140
+ # GET /ips/warmup/{ip_address} #
141
+
142
+ ip_address = "test_url_param"
143
+ response = sg.client.ips.warmup._(ip_address).get()
144
+ puts response.status_code
145
+ puts response.body
146
+ puts response.headers
147
+
148
+ ##################################################
149
+ # Remove an IP from warmup #
150
+ # DELETE /ips/warmup/{ip_address} #
151
+
152
+ ip_address = "test_url_param"
153
+ response = sg.client.ips.warmup._(ip_address).delete()
154
+ puts response.status_code
155
+ puts response.body
156
+ puts response.headers
157
+
158
+ ##################################################
159
+ # Retrieve all IP pools an IP address belongs to #
160
+ # GET /ips/{ip_address} #
161
+
162
+ ip_address = "test_url_param"
163
+ response = sg.client.ips._(ip_address).get()
164
+ puts response.status_code
165
+ puts response.body
166
+ puts response.headers
167
+
@@ -0,0 +1,173 @@
1
+ require 'sendgrid-ruby'
2
+
3
+
4
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
+
6
+
7
+ ##################################################
8
+ # Create a batch ID #
9
+ # POST /mail/batch #
10
+
11
+ response = sg.client.mail.batch.post()
12
+ puts response.status_code
13
+ puts response.body
14
+ puts response.headers
15
+
16
+ ##################################################
17
+ # Validate batch ID #
18
+ # GET /mail/batch/{batch_id} #
19
+
20
+ batch_id = "test_url_param"
21
+ response = sg.client.mail.batch._(batch_id).get()
22
+ puts response.status_code
23
+ puts response.body
24
+ puts response.headers
25
+
26
+ ##################################################
27
+ # v3 Mail Send #
28
+ # 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).
30
+
31
+ data = JSON.parse('{
32
+ "asm": {
33
+ "group_id": 1,
34
+ "groups_to_display": [
35
+ 1,
36
+ 2,
37
+ 3
38
+ ]
39
+ },
40
+ "attachments": [
41
+ {
42
+ "content": "[BASE64 encoded content block here]",
43
+ "content_id": "ii_139db99fdb5c3704",
44
+ "disposition": "inline",
45
+ "filename": "file1.jpg",
46
+ "name": "file1",
47
+ "type": "jpg"
48
+ }
49
+ ],
50
+ "batch_id": "[YOUR BATCH ID GOES HERE]",
51
+ "categories": [
52
+ "category1",
53
+ "category2"
54
+ ],
55
+ "content": [
56
+ {
57
+ "type": "text/html",
58
+ "value": "<html><p>Hello, world!</p><img src=[CID GOES HERE]></img></html>"
59
+ }
60
+ ],
61
+ "custom_args": {
62
+ "New Argument 1": "New Value 1",
63
+ "activationAttempt": "1",
64
+ "customerAccountNumber": "[CUSTOMER ACCOUNT NUMBER GOES HERE]"
65
+ },
66
+ "from": {
67
+ "email": "sam.smith@example.com",
68
+ "name": "Sam Smith"
69
+ },
70
+ "headers": {},
71
+ "ip_pool_name": "[YOUR POOL NAME GOES HERE]",
72
+ "mail_settings": {
73
+ "bcc": {
74
+ "email": "ben.doe@example.com",
75
+ "enable": true
76
+ },
77
+ "bypass_list_management": {
78
+ "enable": true
79
+ },
80
+ "footer": {
81
+ "enable": true,
82
+ "html": "<p>Thanks</br>The Twilio SendGrid Team</p>",
83
+ "text": "Thanks,/n The Twilio SendGrid Team"
84
+ },
85
+ "sandbox_mode": {
86
+ "enable": false
87
+ },
88
+ "spam_check": {
89
+ "enable": true,
90
+ "post_to_url": "http://example.com/compliance",
91
+ "threshold": 3
92
+ }
93
+ },
94
+ "personalizations": [
95
+ {
96
+ "bcc": [
97
+ {
98
+ "email": "sam.doe@example.com",
99
+ "name": "Sam Doe"
100
+ }
101
+ ],
102
+ "cc": [
103
+ {
104
+ "email": "jane.doe@example.com",
105
+ "name": "Jane Doe"
106
+ }
107
+ ],
108
+ "custom_args": {
109
+ "New Argument 1": "New Value 1",
110
+ "activationAttempt": "1",
111
+ "customerAccountNumber": "[CUSTOMER ACCOUNT NUMBER GOES HERE]"
112
+ },
113
+ "headers": {
114
+ "X-Accept-Language": "en",
115
+ "X-Mailer": "MyApp"
116
+ },
117
+ "send_at": 1409348513,
118
+ "subject": "Hello, World!",
119
+ "substitutions": {
120
+ "id": "substitutions",
121
+ "type": "object"
122
+ },
123
+ "to": [
124
+ {
125
+ "email": "john.doe@example.com",
126
+ "name": "John Doe"
127
+ }
128
+ ]
129
+ }
130
+ ],
131
+ "reply_to": {
132
+ "email": "sam.smith@example.com",
133
+ "name": "Sam Smith"
134
+ },
135
+ "sections": {
136
+ "section": {
137
+ ":sectionName1": "section 1 text",
138
+ ":sectionName2": "section 2 text"
139
+ }
140
+ },
141
+ "send_at": 1409348513,
142
+ "subject": "Hello, World!",
143
+ "template_id": "[YOUR TEMPLATE ID GOES HERE]",
144
+ "tracking_settings": {
145
+ "click_tracking": {
146
+ "enable": true,
147
+ "enable_text": true
148
+ },
149
+ "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]",
155
+ "utm_term": "[IDENTIFY PAID KEYWORDS HERE]"
156
+ },
157
+ "open_tracking": {
158
+ "enable": true,
159
+ "substitution_tag": "%opentrack"
160
+ },
161
+ "subscription_tracking": {
162
+ "enable": true,
163
+ "html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.",
164
+ "substitution_tag": "<%click here%>",
165
+ "text": "If you would like to unsubscribe and stop receiveing these emails <% click here %>."
166
+ }
167
+ }
168
+ }')
169
+ response = sg.client.mail._("send").post(request_body: data)
170
+ puts response.status_code
171
+ puts response.body
172
+ puts response.headers
173
+
@@ -0,0 +1,16 @@
1
+ require 'sendgrid-ruby'
2
+
3
+
4
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
+
6
+
7
+ ##################################################
8
+ # Retrieve email statistics by mailbox provider. #
9
+ # GET /mailbox_providers/stats #
10
+
11
+ params = JSON.parse('{"end_date": "2016-04-01", "mailbox_providers": "test_string", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01"}')
12
+ response = sg.client.mailbox_providers.stats.get(query_params: params)
13
+ puts response.status_code
14
+ puts response.body
15
+ puts response.headers
16
+
@@ -0,0 +1,219 @@
1
+ require 'sendgrid-ruby'
2
+
3
+
4
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
+
6
+
7
+ ##################################################
8
+ # Retrieve all mail settings #
9
+ # GET /mail_settings #
10
+
11
+ params = JSON.parse('{"limit": 1, "offset": 1}')
12
+ response = sg.client.mail_settings.get(query_params: params)
13
+ puts response.status_code
14
+ puts response.body
15
+ puts response.headers
16
+
17
+ ##################################################
18
+ # Update address whitelist mail settings #
19
+ # PATCH /mail_settings/address_whitelist #
20
+
21
+ data = JSON.parse('{
22
+ "enabled": true,
23
+ "list": [
24
+ "email1@example.com",
25
+ "example.com"
26
+ ]
27
+ }')
28
+ response = sg.client.mail_settings.address_whitelist.patch(request_body: data)
29
+ puts response.status_code
30
+ puts response.body
31
+ puts response.headers
32
+
33
+ ##################################################
34
+ # Retrieve address whitelist mail settings #
35
+ # GET /mail_settings/address_whitelist #
36
+
37
+ response = sg.client.mail_settings.address_whitelist.get()
38
+ puts response.status_code
39
+ puts response.body
40
+ puts response.headers
41
+
42
+ ##################################################
43
+ # Update BCC mail settings #
44
+ # PATCH /mail_settings/bcc #
45
+
46
+ data = JSON.parse('{
47
+ "email": "email@example.com",
48
+ "enabled": false
49
+ }')
50
+ response = sg.client.mail_settings.bcc.patch(request_body: data)
51
+ puts response.status_code
52
+ puts response.body
53
+ puts response.headers
54
+
55
+ ##################################################
56
+ # Retrieve all BCC mail settings #
57
+ # GET /mail_settings/bcc #
58
+
59
+ response = sg.client.mail_settings.bcc.get()
60
+ puts response.status_code
61
+ puts response.body
62
+ puts response.headers
63
+
64
+ ##################################################
65
+ # Update bounce purge mail settings #
66
+ # PATCH /mail_settings/bounce_purge #
67
+
68
+ data = JSON.parse('{
69
+ "enabled": true,
70
+ "hard_bounces": 5,
71
+ "soft_bounces": 5
72
+ }')
73
+ response = sg.client.mail_settings.bounce_purge.patch(request_body: data)
74
+ puts response.status_code
75
+ puts response.body
76
+ puts response.headers
77
+
78
+ ##################################################
79
+ # Retrieve bounce purge mail settings #
80
+ # GET /mail_settings/bounce_purge #
81
+
82
+ response = sg.client.mail_settings.bounce_purge.get()
83
+ puts response.status_code
84
+ puts response.body
85
+ puts response.headers
86
+
87
+ ##################################################
88
+ # Update footer mail settings #
89
+ # PATCH /mail_settings/footer #
90
+
91
+ data = JSON.parse('{
92
+ "enabled": true,
93
+ "html_content": "...",
94
+ "plain_content": "..."
95
+ }')
96
+ response = sg.client.mail_settings.footer.patch(request_body: data)
97
+ puts response.status_code
98
+ puts response.body
99
+ puts response.headers
100
+
101
+ ##################################################
102
+ # Retrieve footer mail settings #
103
+ # GET /mail_settings/footer #
104
+
105
+ response = sg.client.mail_settings.footer.get()
106
+ puts response.status_code
107
+ puts response.body
108
+ puts response.headers
109
+
110
+ ##################################################
111
+ # Update forward bounce mail settings #
112
+ # PATCH /mail_settings/forward_bounce #
113
+
114
+ data = JSON.parse('{
115
+ "email": "example@example.com",
116
+ "enabled": true
117
+ }')
118
+ response = sg.client.mail_settings.forward_bounce.patch(request_body: data)
119
+ puts response.status_code
120
+ puts response.body
121
+ puts response.headers
122
+
123
+ ##################################################
124
+ # Retrieve forward bounce mail settings #
125
+ # GET /mail_settings/forward_bounce #
126
+
127
+ response = sg.client.mail_settings.forward_bounce.get()
128
+ puts response.status_code
129
+ puts response.body
130
+ puts response.headers
131
+
132
+ ##################################################
133
+ # Update forward spam mail settings #
134
+ # PATCH /mail_settings/forward_spam #
135
+
136
+ data = JSON.parse('{
137
+ "email": "",
138
+ "enabled": false
139
+ }')
140
+ response = sg.client.mail_settings.forward_spam.patch(request_body: data)
141
+ puts response.status_code
142
+ puts response.body
143
+ puts response.headers
144
+
145
+ ##################################################
146
+ # Retrieve forward spam mail settings #
147
+ # GET /mail_settings/forward_spam #
148
+
149
+ response = sg.client.mail_settings.forward_spam.get()
150
+ puts response.status_code
151
+ puts response.body
152
+ puts response.headers
153
+
154
+ ##################################################
155
+ # Update plain content mail settings #
156
+ # PATCH /mail_settings/plain_content #
157
+
158
+ data = JSON.parse('{
159
+ "enabled": false
160
+ }')
161
+ response = sg.client.mail_settings.plain_content.patch(request_body: data)
162
+ puts response.status_code
163
+ puts response.body
164
+ puts response.headers
165
+
166
+ ##################################################
167
+ # Retrieve plain content mail settings #
168
+ # GET /mail_settings/plain_content #
169
+
170
+ response = sg.client.mail_settings.plain_content.get()
171
+ puts response.status_code
172
+ puts response.body
173
+ puts response.headers
174
+
175
+ ##################################################
176
+ # Update spam check mail settings #
177
+ # PATCH /mail_settings/spam_check #
178
+
179
+ data = JSON.parse('{
180
+ "enabled": true,
181
+ "max_score": 5,
182
+ "url": "url"
183
+ }')
184
+ response = sg.client.mail_settings.spam_check.patch(request_body: data)
185
+ puts response.status_code
186
+ puts response.body
187
+ puts response.headers
188
+
189
+ ##################################################
190
+ # Retrieve spam check mail settings #
191
+ # GET /mail_settings/spam_check #
192
+
193
+ response = sg.client.mail_settings.spam_check.get()
194
+ puts response.status_code
195
+ puts response.body
196
+ puts response.headers
197
+
198
+ ##################################################
199
+ # Update template mail settings #
200
+ # PATCH /mail_settings/template #
201
+
202
+ data = JSON.parse('{
203
+ "enabled": true,
204
+ "html_content": "<% body %>"
205
+ }')
206
+ response = sg.client.mail_settings.template.patch(request_body: data)
207
+ puts response.status_code
208
+ puts response.body
209
+ puts response.headers
210
+
211
+ ##################################################
212
+ # Retrieve legacy template mail settings #
213
+ # GET /mail_settings/template #
214
+
215
+ response = sg.client.mail_settings.template.get()
216
+ puts response.status_code
217
+ puts response.body
218
+ puts response.headers
219
+
@@ -0,0 +1,39 @@
1
+ require 'sendgrid-ruby'
2
+
3
+
4
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
5
+
6
+
7
+ ##################################################
8
+ # Returns a list of all partner settings. #
9
+ # GET /partner_settings #
10
+
11
+ params = JSON.parse('{"limit": 1, "offset": 1}')
12
+ response = sg.client.partner_settings.get(query_params: params)
13
+ puts response.status_code
14
+ puts response.body
15
+ puts response.headers
16
+
17
+ ##################################################
18
+ # Updates New Relic partner settings. #
19
+ # PATCH /partner_settings/new_relic #
20
+
21
+ data = JSON.parse('{
22
+ "enable_subuser_statistics": true,
23
+ "enabled": true,
24
+ "license_key": ""
25
+ }')
26
+ response = sg.client.partner_settings.new_relic.patch(request_body: data)
27
+ puts response.status_code
28
+ puts response.body
29
+ puts response.headers
30
+
31
+ ##################################################
32
+ # Returns all New Relic partner settings. #
33
+ # GET /partner_settings/new_relic #
34
+
35
+ response = sg.client.partner_settings.new_relic.get()
36
+ puts response.status_code
37
+ puts response.body
38
+ puts response.headers
39
+
@@ -0,0 +1,61 @@
1
+ require_relative '../../lib/sendgrid-ruby.rb'
2
+
3
+ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
4
+
5
+ ##################################################
6
+ # Retrieve a list of scopes for which this user has access. #
7
+ # GET /scopes #
8
+
9
+ response = sg.client.scopes.get()
10
+ puts response.status_code
11
+ puts response.body
12
+ puts response.headers
13
+
14
+ ##################################################
15
+ # Update the name & scopes of an API Key #
16
+ # PUT /api_keys/{api_key_id} #
17
+
18
+
19
+ scopes = [
20
+ "user.profile.read",
21
+ "user.profile.update"
22
+ ]
23
+
24
+ data = {
25
+ "name": "A New Hope",
26
+ "scopes": scopes
27
+ }
28
+ api_key_id = "test_url_param"
29
+ response = sg.client.api_keys._(api_key_id).put(request_body: data)
30
+ puts response.status_code
31
+ puts response.body
32
+ puts response.headers
33
+
34
+ # The above method shows how to update the scopes
35
+ # To get various scopes that each of the endpoint has, use the following
36
+
37
+ # To get all admin permissions
38
+ scopes = SendGrid::Scope.admin_permissions
39
+
40
+ # To get all read only permissions
41
+ scopes = SendGrid::Scope.read_only_permissions
42
+
43
+ # There are two methods for each endpoints, namely
44
+ # {endpoint}_read_only_permissions and {endpoint}_full_access_permissions
45
+
46
+ # These are the endpoints :
47
+ # alerts, api_keys, asm_groups, billing, categories, credentials, stats, ips, mail_settings, mail,
48
+ # marketing_campaigns, partner_settings, scheduled_sends, subusers, suppression, teammates,
49
+ # templates, tracking_settings, user_settings, webhooks, whitelabel, access_settings
50
+
51
+ # read only permissions for alerts
52
+ scopes = SendGrid::Scope.alerts_read_only_permissions
53
+
54
+ # full access permissions for alerts
55
+ scopes = SendGrid::Scope.alerts_full_access_permissions
56
+
57
+ # read only permissions for billing
58
+ scopes = SendGrid::Scope.billing_read_only_permissions
59
+
60
+ # full access permissions for billing
61
+ scopes = SendGrid::Scope.billing_full_access_permissions