Sha256: 3a247ffd66adceae41f0f2927b9f94a1c56acc7d5185f549ae3643452a171927

Contents?: true

Size: 1.97 KB

Versions: 6

Compression:

Stored size: 1.97 KB

Contents

# -*- encoding: utf-8 -*-

module SendGrid4r
  module REST
    #
    # SendGrid Web API v3 Ip Management
    #
    module Ips
      #
      # SendGrid Web API v3 Ip Management - Pools
      #
      module Pools
        include SendGrid4r::REST::Request

        Pool = Struct.new(:pool_name, :name, :ips)

        def self.create_pools(resp)
          return resp if resp.nil?
          pools = []
          resp.each do |pool|
            pools.push(SendGrid4r::REST::Ips::Pools.create_pool(pool))
          end
          pools
        end

        def self.create_pool(resp)
          return resp if resp.nil?
          ips = []
          Array(resp['ips']).each { |ip| ips.push(ip) }
          Pool.new(resp['pool_name'], resp['name'], ips)
        end

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

        def post_pool(name:, &block)
          endpoint = SendGrid4r::REST::Ips::Pools.url
          resp = post(@auth, endpoint, name: name, &block)
          SendGrid4r::REST::Ips::Pools.create_pool(resp)
        end

        def get_pools(&block)
          resp = get(@auth, SendGrid4r::REST::Ips::Pools.url, &block)
          SendGrid4r::REST::Ips::Pools.create_pools(resp)
        end

        def get_pool(name:, &block)
          endpoint = SendGrid4r::REST::Ips::Pools.url(name)
          resp = get(@auth, endpoint, &block)
          SendGrid4r::REST::Ips::Pools.create_pool(resp)
        end

        def put_pool(name:, new_name:, &block)
          endpoint = SendGrid4r::REST::Ips::Pools.url(name)
          resp = put(@auth, endpoint, name: new_name, &block)
          SendGrid4r::REST::Ips::Pools.create_pool(resp)
        end

        def delete_pool(name:, &block)
          delete(@auth, SendGrid4r::REST::Ips::Pools.url(name), &block)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sendgrid4r-1.8.1 lib/sendgrid4r/rest/ips/pools.rb
sendgrid4r-1.8.0 lib/sendgrid4r/rest/ips/pools.rb
sendgrid4r-1.7.1 lib/sendgrid4r/rest/ips/pools.rb
sendgrid4r-1.7.0 lib/sendgrid4r/rest/ips/pools.rb
sendgrid4r-1.6.0 lib/sendgrid4r/rest/ips/pools.rb
sendgrid4r-1.5.1 lib/sendgrid4r/rest/ips/pools.rb