Module: SendGrid4r::REST::Ips::Addresses

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

Overview

SendGrid Web API v3 Ip Management - Pools

Defined Under Namespace

Classes: Address

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_address(resp) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sendgrid4r/rest/ips/addresses.rb', line 23

def self.create_address(resp)
  return resp if resp.nil?
  Address.new(
    resp['ip'],
    resp['pools'],
    resp['warmup'],
    resp['start_date'].nil? ? nil : Time.at(resp['start_date']),
    resp['subusers'],
    resp['rdns'],
    resp['pool_name']
  )
end

.create_addresses(resp) ⇒ Object



18
19
20
21
# File 'lib/sendgrid4r/rest/ips/addresses.rb', line 18

def self.create_addresses(resp)
  return resp if resp.nil?
  resp.map { |address| Ips::Addresses.create_address(address) }
end

.url(ip = nil) ⇒ Object



36
37
38
39
40
# File 'lib/sendgrid4r/rest/ips/addresses.rb', line 36

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

Instance Method Details

#delete_ip_from_pool(pool_name:, ip:, &block) ⇒ Object



62
63
64
# File 'lib/sendgrid4r/rest/ips/addresses.rb', line 62

def delete_ip_from_pool(pool_name:, ip:, &block)
  delete(@auth, Ips::Pools.url(pool_name, :ips, ip), &block)
end

#get_ip(ip:, &block) ⇒ Object



57
58
59
60
# File 'lib/sendgrid4r/rest/ips/addresses.rb', line 57

def get_ip(ip:, &block)
  resp = get(@auth, Ips::Addresses.url(ip), &block)
  finish(resp, @raw_resp) { |r| Ips::Addresses.create_address(r) }
end

#get_ips(&block) ⇒ Object



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

def get_ips(&block)
  resp = get(@auth, Ips::Addresses.url, &block)
  finish(resp, @raw_resp) { |r| Ips::Addresses.create_addresses(r) }
end

#get_ips_assigned(&block) ⇒ Object



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

def get_ips_assigned(&block)
  resp = get(@auth, Ips::Addresses.url(:assigned), &block)
  finish(resp, @raw_resp) { |r| Ips::Addresses.create_addresses(r) }
end

#post_ip_to_pool(pool_name:, ip:, &block) ⇒ Object



42
43
44
45
# File 'lib/sendgrid4r/rest/ips/addresses.rb', line 42

def post_ip_to_pool(pool_name:, ip:, &block)
  resp = post(@auth, Ips::Pools.url(pool_name, :ips), ip: ip, &block)
  finish(resp, @raw_resp) { |r| Ips::Addresses.create_address(r) }
end