Module: SendGrid4r::REST::Whitelabel::Ips

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

Overview

SendGrid Web API v3 Whitelabel Ips

Defined Under Namespace

Classes: ARecord, Ip, Result, User, 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_a_record(resp) ⇒ Object



52
53
54
55
# File 'lib/sendgrid4r/rest/whitelabel/ips.rb', line 52

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

.create_ip(resp) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sendgrid4r/rest/whitelabel/ips.rb', line 32

def self.create_ip(resp)
  return resp if resp.nil?
  Ip.new(
    resp['id'],
    resp['ip'],
    resp['rdns'],
    Ips.create_users(resp['users']),
    resp['subdomain'],
    resp['domain'],
    resp['valid'],
    resp['legacy'],
    Ips.create_a_record(resp['a_record'])
  )
end

.create_ips(resp) ⇒ Object



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

def self.create_ips(resp)
  return resp if resp.nil?
  resp.map { |ip| Ips.create_ip(ip) }
end

.create_result(resp) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/sendgrid4r/rest/whitelabel/ips.rb', line 61

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

.create_users(resp) ⇒ Object



47
48
49
50
# File 'lib/sendgrid4r/rest/whitelabel/ips.rb', line 47

def self.create_users(resp)
  return resp if resp.nil?
  resp.map { |user| Ips.create_a_record(user) }
end

.create_validation_result(resp) ⇒ Object



77
78
79
80
# File 'lib/sendgrid4r/rest/whitelabel/ips.rb', line 77

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

.create_validation_results(resp) ⇒ Object



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

def self.create_validation_results(resp)
  return resp if resp.nil?
  ValidationResults.new(
    Ips.create_validation_result(resp['a_record'])
  )
end

.url(id = nil) ⇒ Object



21
22
23
24
25
# File 'lib/sendgrid4r/rest/whitelabel/ips.rb', line 21

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

Instance Method Details

#delete_wl_ip(id:, &block) ⇒ Object



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

def delete_wl_ip(id:, &block)
  delete(@auth, Ips.url(id), &block)
end

#get_wl_ip(id:, &block) ⇒ Object



101
102
103
104
# File 'lib/sendgrid4r/rest/whitelabel/ips.rb', line 101

def get_wl_ip(id:, &block)
  resp = get(@auth, Ips.url(id), nil, &block)
  finish(resp, @raw_resp) { |r| Ips.create_ip(r) }
end

#get_wl_ips(ip: nil, limit: nil, offset: nil, &block) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/sendgrid4r/rest/whitelabel/ips.rb', line 82

def get_wl_ips(ip: nil, limit: nil, offset: nil, &block)
  params = {}
  params[:ip] = ip unless ip.nil?
  params[:limit] = limit unless limit.nil?
  params[:offset] = offset unless offset.nil?
  resp = get(@auth, Ips.url, params, &block)
  finish(resp, @raw_resp) { |r| Ips.create_ips(r) }
end

#post_wl_ip(ip:, subdomain:, domain:, &block) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/sendgrid4r/rest/whitelabel/ips.rb', line 91

def post_wl_ip(ip:, subdomain:, domain:, &block)
  params = {
    ip: ip,
    subdomain: subdomain,
    domain: domain
  }
  resp = post(@auth, Ips.url, params, &block)
  finish(resp, @raw_resp) { |r| Ips.create_ip(r) }
end

#validate_wl_ip(id:, &block) ⇒ Object



110
111
112
113
# File 'lib/sendgrid4r/rest/whitelabel/ips.rb', line 110

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