sendgrid4r 0.5.0 → 1.0.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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/.env.example +6 -8
  3. data/.rubocop.yml +1 -1
  4. data/README.md +0 -2
  5. data/lib/sendgrid4r/rest/api.rb +6 -0
  6. data/lib/sendgrid4r/rest/api_keys/api_keys.rb +5 -5
  7. data/lib/sendgrid4r/rest/asm/global_suppressions.rb +3 -3
  8. data/lib/sendgrid4r/rest/asm/groups.rb +4 -4
  9. data/lib/sendgrid4r/rest/asm/suppressions.rb +4 -4
  10. data/lib/sendgrid4r/rest/categories/categories.rb +1 -1
  11. data/lib/sendgrid4r/rest/contacts/custom_fields.rb +3 -3
  12. data/lib/sendgrid4r/rest/contacts/lists.rb +10 -10
  13. data/lib/sendgrid4r/rest/contacts/recipients.rb +10 -10
  14. data/lib/sendgrid4r/rest/contacts/segments.rb +5 -5
  15. data/lib/sendgrid4r/rest/ips/addresses.rb +3 -3
  16. data/lib/sendgrid4r/rest/ips/pools.rb +4 -4
  17. data/lib/sendgrid4r/rest/ips/warmup.rb +6 -6
  18. data/lib/sendgrid4r/rest/request.rb +2 -2
  19. data/lib/sendgrid4r/rest/subusers/subusers.rb +63 -3
  20. data/lib/sendgrid4r/rest/templates/templates.rb +14 -9
  21. data/lib/sendgrid4r/rest/templates/versions.rb +12 -10
  22. data/lib/sendgrid4r/rest/whitelabel/domains.rb +257 -0
  23. data/lib/sendgrid4r/rest/whitelabel/ips.rb +140 -0
  24. data/lib/sendgrid4r/rest/whitelabel/links.rb +185 -0
  25. data/lib/sendgrid4r/version.rb +1 -1
  26. data/sendgrid4r.gemspec +1 -1
  27. data/spec/client_spec.rb +93 -1
  28. data/spec/rest/api_keys/api_keys_spec.rb +23 -55
  29. data/spec/rest/asm/global_suppressions_spec.rb +40 -68
  30. data/spec/rest/asm/groups_spec.rb +31 -82
  31. data/spec/rest/asm/suppressions_spec.rb +33 -76
  32. data/spec/rest/categories/categories_spec.rb +8 -27
  33. data/spec/rest/contacts/custom_fields_spec.rb +18 -71
  34. data/spec/rest/contacts/lists_spec.rb +64 -187
  35. data/spec/rest/contacts/recipients_spec.rb +41 -196
  36. data/spec/rest/contacts/reserved_fields_spec.rb +2 -20
  37. data/spec/rest/contacts/segments_spec.rb +47 -33
  38. data/spec/rest/email_activity/email_activity_spec.rb +8 -21
  39. data/spec/rest/ips/addresses_spec.rb +18 -77
  40. data/spec/rest/ips/pools_spec.rb +21 -80
  41. data/spec/rest/ips/warmup_spec.rb +11 -58
  42. data/spec/rest/settings/enforced_tls_spec.rb +3 -40
  43. data/spec/rest/settings/mail_spec.rb +21 -294
  44. data/spec/rest/settings/partner_spec.rb +6 -79
  45. data/spec/rest/settings/tracking_spec.rb +10 -147
  46. data/spec/rest/stats/advanced_spec.rb +13 -135
  47. data/spec/rest/stats/category_spec.rb +5 -48
  48. data/spec/rest/stats/global_spec.rb +3 -5
  49. data/spec/rest/stats/parse_spec.rb +1 -24
  50. data/spec/rest/stats/subuser_spec.rb +6 -49
  51. data/spec/rest/subusers/subusers_spec.rb +156 -81
  52. data/spec/rest/templates/templates_spec.rb +32 -81
  53. data/spec/rest/templates/versions_spec.rb +50 -28
  54. data/spec/rest/whitelabel/domains_spec.rb +637 -0
  55. data/spec/rest/whitelabel/ips_spec.rb +231 -0
  56. data/spec/rest/whitelabel/links_spec.rb +359 -0
  57. metadata +22 -8
@@ -39,8 +39,8 @@ module SendGrid4r
39
39
  url
40
40
  end
41
41
 
42
- def post_version(temp_id, version, &block)
43
- endpoint = SendGrid4r::REST::Templates::Versions.url(temp_id)
42
+ def post_version(template_id:, version:, &block)
43
+ endpoint = SendGrid4r::REST::Templates::Versions.url(template_id)
44
44
  resp = post(
45
45
  @auth,
46
46
  endpoint,
@@ -50,35 +50,37 @@ module SendGrid4r
50
50
  SendGrid4r::REST::Templates::Versions.create_version(resp)
51
51
  end
52
52
 
53
- def activate_version(temp_id, ver_id, &block)
54
- url = SendGrid4r::REST::Templates::Versions.url(temp_id, ver_id)
53
+ def activate_version(template_id:, version_id:, &block)
54
+ url = SendGrid4r::REST::Templates::Versions.url(
55
+ template_id, version_id
56
+ )
55
57
  resp = post(@auth, "#{url}/activate", &block)
56
58
  SendGrid4r::REST::Templates::Versions.create_version(resp)
57
59
  end
58
60
 
59
- def get_version(temp_id, ver_id, &block)
61
+ def get_version(template_id:, version_id:, &block)
60
62
  resp = get(
61
63
  @auth,
62
- SendGrid4r::REST::Templates::Versions.url(temp_id, ver_id),
64
+ SendGrid4r::REST::Templates::Versions.url(template_id, version_id),
63
65
  &block
64
66
  )
65
67
  SendGrid4r::REST::Templates::Versions.create_version(resp)
66
68
  end
67
69
 
68
- def patch_version(temp_id, ver_id, version, &block)
70
+ def patch_version(template_id:, version_id:, version:, &block)
69
71
  resp = patch(
70
72
  @auth,
71
- SendGrid4r::REST::Templates::Versions.url(temp_id, ver_id),
73
+ SendGrid4r::REST::Templates::Versions.url(template_id, version_id),
72
74
  remove_uneditable_keys(version.to_h),
73
75
  &block
74
76
  )
75
77
  SendGrid4r::REST::Templates::Versions.create_version(resp)
76
78
  end
77
79
 
78
- def delete_version(temp_id, ver_id, &block)
80
+ def delete_version(template_id:, version_id:, &block)
79
81
  delete(
80
82
  @auth,
81
- SendGrid4r::REST::Templates::Versions.url(temp_id, ver_id),
83
+ SendGrid4r::REST::Templates::Versions.url(template_id, version_id),
82
84
  &block
83
85
  )
84
86
  end
@@ -0,0 +1,257 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ require 'sendgrid4r/rest/request'
5
+
6
+ module SendGrid4r
7
+ module REST
8
+ #
9
+ # SendGrid Web API v3 Whitelabel
10
+ #
11
+ module Whitelabel
12
+ #
13
+ # SendGrid Web API v3 Whitelabel Domains
14
+ #
15
+ module Domains
16
+ include SendGrid4r::REST::Request
17
+
18
+ Domain = Struct.new(
19
+ :id, :domain, :subdomain, :username, :user_id, :ips, :custom_spf,
20
+ :default, :legacy, :automatic_security, :valid, :dns
21
+ )
22
+ Dns = Struct.new(
23
+ # automatic_security:true
24
+ :mail_cname, :spf, :dkim1, :dkim2,
25
+ # automatic_security:false
26
+ :mail_server, :subdomain_spf, :domain_spf, :dkim
27
+ )
28
+ Record = Struct.new(:host, :type, :data, :valid)
29
+
30
+ def self.url(id = nil, ip = nil)
31
+ url = "#{BASE_URL}/whitelabel/domains"
32
+ url = "#{url}/#{id}" unless id.nil?
33
+ url = "#{url}/ips/#{ip}" unless ip.nil?
34
+ url
35
+ end
36
+
37
+ def self.create_domains(resp)
38
+ return resp if resp.nil?
39
+ domains = []
40
+ resp.each do |domain|
41
+ domains.push(
42
+ SendGrid4r::REST::Whitelabel::Domains.create_domain(domain)
43
+ )
44
+ end
45
+ domains
46
+ end
47
+
48
+ def self.create_domain(resp)
49
+ return resp if resp.nil?
50
+ Domain.new(
51
+ resp['id'],
52
+ resp['domain'],
53
+ resp['subdomain'],
54
+ resp['username'],
55
+ resp['user_id'],
56
+ resp['ips'],
57
+ resp['custom_spf'],
58
+ resp['default'],
59
+ resp['legacy'],
60
+ resp['automatic_security'],
61
+ resp['valid'],
62
+ SendGrid4r::REST::Whitelabel::Domains.create_dns(resp['dns'])
63
+ )
64
+ end
65
+
66
+ def self.create_dns(resp)
67
+ return resp if resp.nil?
68
+ Dns.new(
69
+ SendGrid4r::REST::Whitelabel::Domains.create_record(
70
+ resp['mail_cname']),
71
+ SendGrid4r::REST::Whitelabel::Domains.create_record(
72
+ resp['spf']),
73
+ SendGrid4r::REST::Whitelabel::Domains.create_record(
74
+ resp['dkim1']),
75
+ SendGrid4r::REST::Whitelabel::Domains.create_record(
76
+ resp['dkim2']),
77
+ SendGrid4r::REST::Whitelabel::Domains.create_record(
78
+ resp['mail_server']),
79
+ SendGrid4r::REST::Whitelabel::Domains.create_record(
80
+ resp['subdomain_spf']),
81
+ SendGrid4r::REST::Whitelabel::Domains.create_record(
82
+ resp['domain_spf']),
83
+ SendGrid4r::REST::Whitelabel::Domains.create_record(
84
+ resp['dkim'])
85
+ )
86
+ end
87
+
88
+ def self.create_record(resp)
89
+ return resp if resp.nil?
90
+ Record.new(resp['host'], resp['type'], resp['data'], resp['valid'])
91
+ end
92
+
93
+ Result = Struct.new(:id, :valid, :validation_results)
94
+ ValidationResults = Struct.new(
95
+ # automatic_security:true
96
+ :mail_cname, :spf, :dkim1, :dkim2,
97
+ # automatic_security:false
98
+ :mail_server, :subdomain_spf, :domain_spf, :dkim
99
+ )
100
+ ValidationResult = Struct.new(:valid, :reason)
101
+
102
+ def self.create_result(resp)
103
+ return resp if resp.nil?
104
+ Result.new(
105
+ resp['id'],
106
+ resp['valid'],
107
+ SendGrid4r::REST::Whitelabel::Domains.create_validation_results(
108
+ resp['validation_results']
109
+ )
110
+ )
111
+ end
112
+
113
+ def self.create_validation_results(resp)
114
+ return resp if resp.nil?
115
+ ValidationResults.new(
116
+ SendGrid4r::REST::Whitelabel::Domains.create_validation_result(
117
+ resp['mail_cname']),
118
+ SendGrid4r::REST::Whitelabel::Domains.create_validation_result(
119
+ resp['dkim1']),
120
+ SendGrid4r::REST::Whitelabel::Domains.create_validation_result(
121
+ resp['dkim2']),
122
+ SendGrid4r::REST::Whitelabel::Domains.create_validation_result(
123
+ resp['spf']),
124
+ SendGrid4r::REST::Whitelabel::Domains.create_validation_result(
125
+ resp['mail_server']),
126
+ SendGrid4r::REST::Whitelabel::Domains.create_validation_result(
127
+ resp['subdomain_spf']),
128
+ SendGrid4r::REST::Whitelabel::Domains.create_validation_result(
129
+ resp['domain_spf']),
130
+ SendGrid4r::REST::Whitelabel::Domains.create_validation_result(
131
+ resp['dkim'])
132
+ )
133
+ end
134
+
135
+ def self.create_validation_result(resp)
136
+ return resp if resp.nil?
137
+ ValidationResult.new(resp['valid'], resp['reason'])
138
+ end
139
+
140
+ def get_wl_domains(
141
+ limit: nil, offset: nil, exclude_subusers: nil, username: nil,
142
+ domain: nil, &block
143
+ )
144
+ params = {}
145
+ params['limit'] = limit unless limit.nil?
146
+ params['offset'] = offset unless offset.nil?
147
+ unless exclude_subusers.nil?
148
+ params['exclude_subusers'] = exclude_subusers
149
+ end
150
+ params['username'] = username unless username.nil?
151
+ params['domain'] = domain unless domain.nil?
152
+ endpoint = SendGrid4r::REST::Whitelabel::Domains.url
153
+ resp = get(@auth, endpoint, params, &block)
154
+ SendGrid4r::REST::Whitelabel::Domains.create_domains(resp)
155
+ end
156
+
157
+ def post_wl_domain(
158
+ domain:, subdomain:, username: nil, ips: nil, automatic_security: nil,
159
+ custom_spf: nil, default: nil, &block
160
+ )
161
+ params = {}
162
+ params['domain'] = domain
163
+ params['subdomain'] = subdomain
164
+ params['username'] = username unless username.nil?
165
+ params['ips'] = ips unless ips.nil?
166
+ unless automatic_security.nil?
167
+ params['automatic_security'] = automatic_security
168
+ end
169
+ params['custom_spf'] = custom_spf unless custom_spf.nil?
170
+ params['default'] = default unless default.nil?
171
+ endpoint = SendGrid4r::REST::Whitelabel::Domains.url
172
+ resp = post(@auth, endpoint, params, &block)
173
+ SendGrid4r::REST::Whitelabel::Domains.create_domain(resp)
174
+ end
175
+
176
+ def get_wl_domain(id:, &block)
177
+ endpoint = SendGrid4r::REST::Whitelabel::Domains.url(id)
178
+ resp = get(@auth, endpoint, nil, &block)
179
+ SendGrid4r::REST::Whitelabel::Domains.create_domain(resp)
180
+ end
181
+
182
+ def patch_wl_domain(
183
+ id:, custom_spf: nil, default: nil, &block
184
+ )
185
+ params = {}
186
+ params['custom_spf'] = custom_spf unless custom_spf.nil?
187
+ params['default'] = default unless default.nil?
188
+ endpoint = SendGrid4r::REST::Whitelabel::Domains.url(id)
189
+ resp = patch(@auth, endpoint, params, &block)
190
+ SendGrid4r::REST::Whitelabel::Domains.create_domain(resp)
191
+ end
192
+
193
+ def delete_wl_domain(id:, &block)
194
+ endpoint = SendGrid4r::REST::Whitelabel::Domains.url(id)
195
+ delete(@auth, endpoint, &block)
196
+ end
197
+
198
+ def get_default_wl_domain(domain: nil, &block)
199
+ params = {}
200
+ params['domain'] = domain unless domain.nil?
201
+ endpoint = SendGrid4r::REST::Whitelabel::Domains.url
202
+ endpoint = "#{endpoint}/default"
203
+ resp = get(@auth, endpoint, params, &block)
204
+ SendGrid4r::REST::Whitelabel::Domains.create_domain(resp)
205
+ end
206
+
207
+ def add_ip_to_wl_domain(id:, ip:, &block)
208
+ endpoint = SendGrid4r::REST::Whitelabel::Domains.url(id)
209
+ endpoint = "#{endpoint}/ips"
210
+ params = {}
211
+ params['ip'] = ip
212
+ resp = post(@auth, endpoint, params, &block)
213
+ SendGrid4r::REST::Whitelabel::Domains.create_domain(resp)
214
+ end
215
+
216
+ def remove_ip_from_wl_domain(id:, ip:, &block)
217
+ endpoint = SendGrid4r::REST::Whitelabel::Domains.url(id, ip)
218
+ resp = delete(@auth, endpoint, &block)
219
+ SendGrid4r::REST::Whitelabel::Domains.create_domain(resp)
220
+ end
221
+
222
+ def validate_wl_domain(id:, &block)
223
+ endpoint = SendGrid4r::REST::Whitelabel::Domains.url(id)
224
+ endpoint = "#{endpoint}/validate"
225
+ resp = post(@auth, endpoint, &block)
226
+ SendGrid4r::REST::Whitelabel::Domains.create_result(resp)
227
+ end
228
+
229
+ def get_associated_wl_domain(username:, &block)
230
+ endpoint = SendGrid4r::REST::Whitelabel::Domains.url
231
+ endpoint = "#{endpoint}/subuser"
232
+ params = {}
233
+ params['username'] = username
234
+ resp = get(@auth, endpoint, params, &block)
235
+ SendGrid4r::REST::Whitelabel::Domains.create_domain(resp)
236
+ end
237
+
238
+ def disassociate_wl_domain(username:, &block)
239
+ endpoint = SendGrid4r::REST::Whitelabel::Domains.url
240
+ endpoint = "#{endpoint}/subuser"
241
+ params = {}
242
+ params['username'] = username
243
+ delete(@auth, endpoint, params, &block)
244
+ end
245
+
246
+ def associate_wl_domain(id:, username:, &block)
247
+ endpoint = SendGrid4r::REST::Whitelabel::Domains.url(id)
248
+ endpoint = "#{endpoint}/subuser"
249
+ params = {}
250
+ params['username'] = username
251
+ resp = post(@auth, endpoint, params, &block)
252
+ SendGrid4r::REST::Whitelabel::Domains.create_domain(resp)
253
+ end
254
+ end
255
+ end
256
+ end
257
+ end
@@ -0,0 +1,140 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ require 'sendgrid4r/rest/request'
5
+
6
+ module SendGrid4r
7
+ module REST
8
+ #
9
+ # SendGrid Web API v3 Whitelabel
10
+ #
11
+ module Whitelabel
12
+ #
13
+ # SendGrid Web API v3 Whitelabel Ips
14
+ #
15
+ module Ips
16
+ include SendGrid4r::REST::Request
17
+
18
+ Ip = Struct.new(
19
+ :id, :ip, :rdns, :users, :subdomain, :domain, :valid, :legacy,
20
+ :a_record
21
+ )
22
+ User = Struct.new(:username, :user_id)
23
+ ARecord = Struct.new(:host, :type, :data, :valid)
24
+
25
+ def self.url(id = nil)
26
+ url = "#{BASE_URL}/whitelabel/ips"
27
+ url = "#{url}/#{id}" unless id.nil?
28
+ url
29
+ end
30
+
31
+ def self.create_ips(resp)
32
+ return resp if resp.nil?
33
+ ips = []
34
+ resp.each do |ip|
35
+ ips.push(
36
+ SendGrid4r::REST::Whitelabel::Ips.create_ip(ip)
37
+ )
38
+ end
39
+ ips
40
+ end
41
+
42
+ def self.create_ip(resp)
43
+ return resp if resp.nil?
44
+ Ip.new(
45
+ resp['id'],
46
+ resp['ip'],
47
+ resp['rdns'],
48
+ SendGrid4r::REST::Whitelabel::Ips.create_users(resp['users']),
49
+ resp['subdomain'],
50
+ resp['domain'],
51
+ resp['valid'],
52
+ resp['legacy'],
53
+ SendGrid4r::REST::Whitelabel::Ips.create_a_record(resp['a_record'])
54
+ )
55
+ end
56
+
57
+ def self.create_users(resp)
58
+ return resp if resp.nil?
59
+ users = []
60
+ resp.each do |user|
61
+ users.push(SendGrid4r::REST::Whitelabel::Ips.create_a_record(user))
62
+ end
63
+ users
64
+ end
65
+
66
+ def self.create_a_record(resp)
67
+ return resp if resp.nil?
68
+ ARecord.new(resp['host'], resp['type'], resp['data'], resp['valid'])
69
+ end
70
+
71
+ Result = Struct.new(:id, :valid, :validation_results)
72
+ ValidationResults = Struct.new(:a_record)
73
+ ValidationResult = Struct.new(:valid, :reason)
74
+
75
+ def self.create_result(resp)
76
+ return resp if resp.nil?
77
+ Result.new(
78
+ resp['id'],
79
+ resp['valid'],
80
+ SendGrid4r::REST::Whitelabel::Ips.create_validation_results(
81
+ resp['validation_results']
82
+ )
83
+ )
84
+ end
85
+
86
+ def self.create_validation_results(resp)
87
+ return resp if resp.nil?
88
+ ValidationResults.new(
89
+ SendGrid4r::REST::Whitelabel::Ips.create_validation_result(
90
+ resp['a_record']
91
+ )
92
+ )
93
+ end
94
+
95
+ def self.create_validation_result(resp)
96
+ return resp if resp.nil?
97
+ ValidationResult.new(resp['valid'], resp['reason'])
98
+ end
99
+
100
+ def get_wl_ips(ip: nil, limit: nil, offset: nil, &block)
101
+ params = {}
102
+ params['ip'] = ip unless ip.nil?
103
+ params['limit'] = limit unless limit.nil?
104
+ params['offset'] = offset unless offset.nil?
105
+ endpoint = SendGrid4r::REST::Whitelabel::Ips.url
106
+ resp = get(@auth, endpoint, params, &block)
107
+ SendGrid4r::REST::Whitelabel::Ips.create_ips(resp)
108
+ end
109
+
110
+ def post_wl_ip(ip:, subdomain:, domain:, &block)
111
+ params = {}
112
+ params['ip'] = ip
113
+ params['subdomain'] = subdomain
114
+ params['domain'] = domain
115
+ endpoint = SendGrid4r::REST::Whitelabel::Ips.url
116
+ resp = post(@auth, endpoint, params, &block)
117
+ SendGrid4r::REST::Whitelabel::Ips.create_ip(resp)
118
+ end
119
+
120
+ def get_wl_ip(id:, &block)
121
+ endpoint = SendGrid4r::REST::Whitelabel::Ips.url(id)
122
+ resp = get(@auth, endpoint, nil, &block)
123
+ SendGrid4r::REST::Whitelabel::Ips.create_ip(resp)
124
+ end
125
+
126
+ def delete_wl_ip(id:, &block)
127
+ endpoint = SendGrid4r::REST::Whitelabel::Ips.url(id)
128
+ delete(@auth, endpoint, &block)
129
+ end
130
+
131
+ def validate_wl_ip(id:, &block)
132
+ endpoint = SendGrid4r::REST::Whitelabel::Ips.url(id)
133
+ endpoint = "#{endpoint}/validate"
134
+ resp = post(@auth, endpoint, &block)
135
+ SendGrid4r::REST::Whitelabel::Ips.create_result(resp)
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,185 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ require 'sendgrid4r/rest/request'
5
+
6
+ module SendGrid4r
7
+ module REST
8
+ #
9
+ # SendGrid Web API v3 Whitelabel
10
+ #
11
+ module Whitelabel
12
+ #
13
+ # SendGrid Web API v3 Whitelabel Links
14
+ #
15
+ module Links
16
+ include SendGrid4r::REST::Request
17
+
18
+ Link = Struct.new(
19
+ :id, :domain, :subdomain, :username, :user_id, :default,
20
+ :valid, :legacy, :dns
21
+ )
22
+ Dns = Struct.new(:domain_cname, :owner_cname)
23
+ Record = Struct.new(:host, :type, :data, :valid)
24
+
25
+ def self.url(id = nil)
26
+ url = "#{BASE_URL}/whitelabel/links"
27
+ url = "#{url}/#{id}" unless id.nil?
28
+ url
29
+ end
30
+
31
+ def self.create_links(resp)
32
+ return resp if resp.nil?
33
+ links = []
34
+ resp.each do |link|
35
+ links.push(
36
+ SendGrid4r::REST::Whitelabel::Links.create_link(link)
37
+ )
38
+ end
39
+ links
40
+ end
41
+
42
+ def self.create_link(resp)
43
+ return resp if resp.nil?
44
+ Link.new(
45
+ resp['id'],
46
+ resp['domain'],
47
+ resp['subdomain'],
48
+ resp['username'],
49
+ resp['user_id'],
50
+ resp['default'],
51
+ resp['valid'],
52
+ resp['legacy'],
53
+ SendGrid4r::REST::Whitelabel::Links.create_dns(resp['dns'])
54
+ )
55
+ end
56
+
57
+ def self.create_dns(resp)
58
+ return resp if resp.nil?
59
+ Dns.new(
60
+ SendGrid4r::REST::Whitelabel::Links.create_record(
61
+ resp['domain_cname']
62
+ ),
63
+ SendGrid4r::REST::Whitelabel::Links.create_record(
64
+ resp['owner_cname']
65
+ )
66
+ )
67
+ end
68
+
69
+ def self.create_record(resp)
70
+ return resp if resp.nil?
71
+ Record.new(resp['host'], resp['type'], resp['data'], resp['valid'])
72
+ end
73
+
74
+ Result = Struct.new(:id, :valid, :validation_results)
75
+ ValidationResults = Struct.new(:domain_cname, :owner_cname)
76
+ ValidationResult = Struct.new(:valid, :reason)
77
+
78
+ def self.create_result(resp)
79
+ return resp if resp.nil?
80
+ Result.new(
81
+ resp['id'],
82
+ resp['valid'],
83
+ SendGrid4r::REST::Whitelabel::Links.create_validation_results(
84
+ resp['validation_results']
85
+ )
86
+ )
87
+ end
88
+
89
+ def self.create_validation_results(resp)
90
+ return resp if resp.nil?
91
+ ValidationResults.new(
92
+ SendGrid4r::REST::Whitelabel::Links.create_validation_result(
93
+ resp['domain_cname']
94
+ ),
95
+ SendGrid4r::REST::Whitelabel::Links.create_validation_result(
96
+ resp['owner_cname']
97
+ )
98
+ )
99
+ end
100
+
101
+ def self.create_validation_result(resp)
102
+ return resp if resp.nil?
103
+ ValidationResult.new(resp['valid'], resp['reason'])
104
+ end
105
+
106
+ def get_wl_links(&block)
107
+ endpoint = SendGrid4r::REST::Whitelabel::Links.url
108
+ resp = get(@auth, endpoint, nil, &block)
109
+ SendGrid4r::REST::Whitelabel::Links.create_links(resp)
110
+ end
111
+
112
+ def post_wl_link(subdomain:, domain:, default: nil, &block)
113
+ params = {}
114
+ params['subdomain'] = subdomain
115
+ params['domain'] = domain
116
+ params['default'] = default unless default.nil?
117
+ endpoint = SendGrid4r::REST::Whitelabel::Links.url
118
+ resp = post(@auth, endpoint, params, &block)
119
+ SendGrid4r::REST::Whitelabel::Links.create_link(resp)
120
+ end
121
+
122
+ def get_wl_link(id:, &block)
123
+ endpoint = SendGrid4r::REST::Whitelabel::Links.url(id)
124
+ resp = get(@auth, endpoint, nil, &block)
125
+ SendGrid4r::REST::Whitelabel::Links.create_link(resp)
126
+ end
127
+
128
+ def patch_wl_link(id:, default:, &block)
129
+ endpoint = SendGrid4r::REST::Whitelabel::Links.url(id)
130
+ params = {}
131
+ params['default'] = default
132
+ resp = patch(@auth, endpoint, params, &block)
133
+ SendGrid4r::REST::Whitelabel::Links.create_link(resp)
134
+ end
135
+
136
+ def delete_wl_link(id:, &block)
137
+ endpoint = SendGrid4r::REST::Whitelabel::Links.url(id)
138
+ delete(@auth, endpoint, &block)
139
+ end
140
+
141
+ def get_default_wl_link(domain: nil, &block)
142
+ params = {}
143
+ params['domain'] = domain unless domain.nil?
144
+ endpoint = SendGrid4r::REST::Whitelabel::Links.url
145
+ endpoint = "#{endpoint}/default"
146
+ resp = get(@auth, endpoint, params, &block)
147
+ SendGrid4r::REST::Whitelabel::Links.create_link(resp)
148
+ end
149
+
150
+ def validate_wl_link(id:, &block)
151
+ endpoint = SendGrid4r::REST::Whitelabel::Links.url(id)
152
+ endpoint = "#{endpoint}/validate"
153
+ resp = post(@auth, endpoint, &block)
154
+ SendGrid4r::REST::Whitelabel::Links.create_result(resp)
155
+ end
156
+
157
+ def get_associated_wl_link(username:, &block)
158
+ endpoint = SendGrid4r::REST::Whitelabel::Links.url
159
+ endpoint = "#{endpoint}/subuser"
160
+ params = {}
161
+ params['username'] = username
162
+ resp = get(@auth, endpoint, params, &block)
163
+ SendGrid4r::REST::Whitelabel::Links.create_link(resp)
164
+ end
165
+
166
+ def disassociate_wl_link(username:, &block)
167
+ endpoint = SendGrid4r::REST::Whitelabel::Links.url
168
+ endpoint = "#{endpoint}/subuser"
169
+ params = {}
170
+ params['username'] = username
171
+ delete(@auth, endpoint, params, &block)
172
+ end
173
+
174
+ def associate_wl_link(id:, username:, &block)
175
+ endpoint = SendGrid4r::REST::Whitelabel::Links.url(id)
176
+ endpoint = "#{endpoint}/subuser"
177
+ params = {}
178
+ params['username'] = username
179
+ resp = post(@auth, endpoint, params, &block)
180
+ SendGrid4r::REST::Whitelabel::Links.create_link(resp)
181
+ end
182
+ end
183
+ end
184
+ end
185
+ end
@@ -2,5 +2,5 @@
2
2
  # SendGrid API v3 wrapper implementation.
3
3
  #
4
4
  module SendGrid4r
5
- VERSION = '0.5.0'
5
+ VERSION = '1.0.0'
6
6
  end
data/sendgrid4r.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency('rest-client', '1.7.2')
21
+ spec.add_dependency('rest-client', '>=1.8.0', '<1.9.0')
22
22
  spec.add_development_dependency('rubocop', '>=0.29.0', '<0.30.0')
23
23
  spec.add_development_dependency('bundler', '>=1.6.0', '<1.8.0')
24
24
  spec.add_development_dependency('rspec', '3.1.0')