Module: SendGrid4r::REST::Whitelabel::Domains

Includes:
Request
Included in:
API
Defined in:
lib/sendgrid4r/rest/whitelabel/domains.rb

Overview

SendGrid Web API v3 Whitelabel Domains

Defined Under Namespace

Classes: Dns, Domain, Record, Result, ValidationResult, ValidationResults

Constant Summary

Constants included from Request

Request::BASE_URL

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Request

#create_args, #delete, #execute, #finish, #get, #patch, #post, #process_array_params, #process_url_params, #put

Class Method Details

.create_dns(resp) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 56

def self.create_dns(resp)
  return resp if resp.nil?
  Dns.new(
    Domains.create_record(resp['mail_cname']),
    Domains.create_record(resp['spf']),
    Domains.create_record(resp['dkim1']),
    Domains.create_record(resp['dkim2']),
    Domains.create_record(resp['mail_server']),
    Domains.create_record(resp['subdomain_spf']),
    Domains.create_record(resp['domain_spf']),
    Domains.create_record(resp['dkim'])
  )
end

.create_domain(resp) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 38

def self.create_domain(resp)
  return resp if resp.nil?
  Domain.new(
    resp['id'],
    resp['domain'],
    resp['subdomain'],
    resp['username'],
    resp['user_id'],
    resp['ips'],
    resp['custom_spf'],
    resp['default'],
    resp['legacy'],
    resp['automatic_security'],
    resp['valid'],
    Domains.create_dns(resp['dns'])
  )
end

.create_domains(resp) ⇒ Object



33
34
35
36
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 33

def self.create_domains(resp)
  return resp if resp.nil?
  resp.map { |domain| Domains.create_domain(domain) }
end

.create_record(resp) ⇒ Object



70
71
72
73
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 70

def self.create_record(resp)
  return resp if resp.nil?
  Record.new(resp['host'], resp['type'], resp['data'], resp['valid'])
end

.create_result(resp) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 84

def self.create_result(resp)
  return resp if resp.nil?
  Result.new(
    resp['id'],
    resp['valid'],
    Domains.create_validation_results(resp['validation_results'])
  )
end

.create_validation_result(resp) ⇒ Object



105
106
107
108
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 105

def self.create_validation_result(resp)
  return resp if resp.nil?
  ValidationResult.new(resp['valid'], resp['reason'])
end

.create_validation_results(resp) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 93

def self.create_validation_results(resp)
  return resp if resp.nil?
  ValidationResults.new(
    Domains.create_validation_result(resp['mail_cname']),
    Domains.create_validation_result(resp['dkim1']),
    Domains.create_validation_result(resp['dkim2']),
    Domains.create_validation_result(resp['mail_server']),
    Domains.create_validation_result(resp['subdomain_spf']),
    Domains.create_validation_result(resp['dkim'])
  )
end

.url(id = nil, ip = nil) ⇒ Object



26
27
28
29
30
31
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 26

def self.url(id = nil, ip = nil)
  url = "#{BASE_URL}/whitelabel/domains"
  url = "#{url}/#{id}" unless id.nil?
  url = "#{url}/ips/#{ip}" unless ip.nil?
  url
end

Instance Method Details

#add_ip_to_wl_domain(id:, ip:, &block) ⇒ Object



169
170
171
172
173
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 169

def add_ip_to_wl_domain(id:, ip:, &block)
  params = { ip: ip }
  resp = post(@auth, "#{Domains.url(id)}/ips", params, &block)
  finish(resp, @raw_resp) { |r| Domains.create_domain(r) }
end

#associate_wl_domain(id:, username:, &block) ⇒ Object



195
196
197
198
199
200
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 195

def associate_wl_domain(id:, username:, &block)
  endpoint = "#{Domains.url(id)}/subuser"
  params = { username: username }
  resp = post(@auth, endpoint, params, &block)
  finish(resp, @raw_resp) { |r| Domains.create_domain(r) }
end

#delete_wl_domain(id:, &block) ⇒ Object



158
159
160
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 158

def delete_wl_domain(id:, &block)
  delete(@auth, Domains.url(id), &block)
end

#disassociate_wl_domain(username:, &block) ⇒ Object



190
191
192
193
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 190

def disassociate_wl_domain(username:, &block)
  params = { username: username }
  delete(@auth, "#{Domains.url}/subuser", params, &block)
end

#get_associated_wl_domain(username:, &block) ⇒ Object



184
185
186
187
188
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 184

def get_associated_wl_domain(username:, &block)
  params = { username: username }
  resp = get(@auth, "#{Domains.url}/subuser", params, &block)
  finish(resp, @raw_resp) { |r| Domains.create_domain(r) }
end

#get_default_wl_domain(domain: nil, &block) ⇒ Object



162
163
164
165
166
167
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 162

def get_default_wl_domain(domain: nil, &block)
  params = {}
  params[:domain] = domain unless domain.nil?
  resp = get(@auth, "#{Domains.url}/default", params, &block)
  finish(resp, @raw_resp) { |r| Domains.create_domain(r) }
end

#get_wl_domain(id:, &block) ⇒ Object



145
146
147
148
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 145

def get_wl_domain(id:, &block)
  resp = get(@auth, Domains.url(id), nil, &block)
  finish(resp, @raw_resp) { |r| Domains.create_domain(r) }
end

#get_wl_domains(limit: nil, offset: nil, exclude_subusers: nil, username: nil, domain: nil, &block) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 110

def get_wl_domains(
  limit: nil, offset: nil, exclude_subusers: nil, username: nil,
  domain: nil, &block
)
  params = {}
  params[:limit] = limit unless limit.nil?
  params[:offset] = offset unless offset.nil?
  unless exclude_subusers.nil?
    params[:exclude_subusers] = exclude_subusers
  end
  params[:username] = username unless username.nil?
  params[:domain] = domain unless domain.nil?
  resp = get(@auth, Domains.url, params, &block)
  finish(resp, @raw_resp) { |r| Domains.create_domains(r) }
end

#patch_wl_domain(id:, custom_spf: nil, default: nil, &block) ⇒ Object



150
151
152
153
154
155
156
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 150

def patch_wl_domain(id:, custom_spf: nil, default: nil, &block)
  params = {}
  params[:custom_spf] = custom_spf unless custom_spf.nil?
  params[:default] = default unless default.nil?
  resp = patch(@auth, Domains.url(id), params, &block)
  finish(resp, @raw_resp) { |r| Domains.create_domain(r) }
end

#post_wl_domain(domain:, subdomain:, username: nil, ips: nil, automatic_security: nil, custom_spf: nil, default: nil, &block) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 126

def post_wl_domain(
  domain:, subdomain:, username: nil, ips: nil, automatic_security: nil,
  custom_spf: nil, default: nil, &block
)
  params = {
    domain: domain,
    subdomain: subdomain
  }
  params[:username] = username unless username.nil?
  params[:ips] = ips unless ips.nil?
  unless automatic_security.nil?
    params[:automatic_security] = automatic_security
  end
  params[:custom_spf] = custom_spf unless custom_spf.nil?
  params[:default] = default unless default.nil?
  resp = post(@auth, Domains.url, params, &block)
  finish(resp, @raw_resp) { |r| Domains.create_domain(r) }
end

#remove_ip_from_wl_domain(id:, ip:, &block) ⇒ Object



175
176
177
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 175

def remove_ip_from_wl_domain(id:, ip:, &block)
  delete(@auth, Domains.url(id, ip), &block)
end

#validate_wl_domain(id:, &block) ⇒ Object



179
180
181
182
# File 'lib/sendgrid4r/rest/whitelabel/domains.rb', line 179

def validate_wl_domain(id:, &block)
  resp = post(@auth, "#{Domains.url(id)}/validate", &block)
  finish(resp, @raw_resp) { |r| Domains.create_result(r) }
end