sendgrid-ruby 1.1.6 → 6.6.2

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