Module: SendGrid4r::REST::Sm::Suppressions

Includes:
Request
Included in:
API
Defined in:
lib/sendgrid4r/rest/sm/suppressions.rb

Overview

SendGrid Web API v3 Suppression Management - Suppressions

Defined Under Namespace

Classes: Group, Groups, Suppression

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



30
31
32
33
34
35
36
37
38
39
# File 'lib/sendgrid4r/rest/sm/suppressions.rb', line 30

def self.create_group(resp)
  return resp if resp.nil?
  Group.new(
    resp['id'],
    resp['name'],
    resp['description'],
    resp['suppressed'],
    resp['is_default']
  )
end

.create_groups(resp) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/sendgrid4r/rest/sm/suppressions.rb', line 22

def self.create_groups(resp)
  return resp if resp.nil?
  suppressions = resp['suppressions'].map do |suppression|
    Sm::Suppressions.create_group(suppression)
  end
  Groups.new(suppressions)
end

.create_suppression(resp) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/sendgrid4r/rest/sm/suppressions.rb', line 51

def self.create_suppression(resp)
  return resp if resp.nil?
  created_at = Time.at(resp['created_at'])
  Suppression.new(
    resp['email'],
    resp['group_id'],
    resp['group_name'],
    created_at
  )
end

.suppressions_url(email = nil) ⇒ Object



45
46
47
48
49
# File 'lib/sendgrid4r/rest/sm/suppressions.rb', line 45

def self.suppressions_url(email = nil)
  url = "#{BASE_URL}/asm/suppressions"
  url = "#{url}/#{email}" unless email.nil?
  url
end

.url(group_id, email_address = nil) ⇒ Object



16
17
18
19
20
# File 'lib/sendgrid4r/rest/sm/suppressions.rb', line 16

def self.url(group_id, email_address = nil)
  url = "#{BASE_URL}/asm/groups/#{group_id}/suppressions"
  url = "#{url}/#{email_address}" unless email_address.nil?
  url
end

Instance Method Details

#delete_suppressed_email(group_id:, email_address:, &block) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/sendgrid4r/rest/sm/suppressions.rb', line 96

def delete_suppressed_email(group_id:, email_address:, &block)
  delete(
    @auth,
    Sm::Suppressions.url(group_id, email_address),
    &block
  )
end

#get_groups_by_email(email_address:, &block) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/sendgrid4r/rest/sm/suppressions.rb', line 72

def get_groups_by_email(email_address:, &block)
  endpoint = Sm::Suppressions.suppressions_url(email_address)
  resp = get(@auth, endpoint, &block)
  finish(resp, @raw_resp) do |r|
    Sm::Suppressions.create_groups(r)
  end
end

#get_suppressed_emails(group_id:, &block) ⇒ Object



90
91
92
93
94
# File 'lib/sendgrid4r/rest/sm/suppressions.rb', line 90

def get_suppressed_emails(group_id:, &block)
  endpoint = Sm::Suppressions.url(group_id)
  resp = get(@auth, endpoint, &block)
  finish(resp, @raw_resp) { |r| r }
end

#get_suppressions(&block) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/sendgrid4r/rest/sm/suppressions.rb', line 62

def get_suppressions(&block)
  endpoint = Sm::Suppressions.suppressions_url
  resp = get(@auth, endpoint, &block)
  finish(resp, @raw_resp) do |r|
    r.map do |suppression|
      Sm::Suppressions.create_suppression(suppression)
    end
  end
end

#post_suppressed_emails(group_id:, recipient_emails:, &block) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/sendgrid4r/rest/sm/suppressions.rb', line 80

def post_suppressed_emails(group_id:, recipient_emails:, &block)
  resp = post(
    @auth,
    Sm::Suppressions.url(group_id),
    recipient_emails: recipient_emails,
    &block
  )
  finish(resp, @raw_resp) { |r| Sm.create_recipient_emails(r) }
end

#search_suppressed_emails(group_id:, recipient_emails:, &block) ⇒ Object



104
105
106
107
108
109
110
111
112
# File 'lib/sendgrid4r/rest/sm/suppressions.rb', line 104

def search_suppressed_emails(group_id:, recipient_emails:, &block)
  resp = post(
    @auth,
    Sm::Suppressions.url(group_id, :search),
    recipient_emails: recipient_emails,
    &block
  )
  finish(resp, @raw_resp) { |r| r }
end