Module: SendGrid4r::REST::Sm::GlobalUnsubscribes

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

Overview

SendGrid Web API v3 Suppression Management - Global Unsubscribes

Defined Under Namespace

Classes: Unsubscribe

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



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

def self.create_supressions(resp)
  return resp if resp.nil?
  resp.map do |suppression|
    created = Time.at(suppression['created'])
    Unsubscribe.new(created, suppression['email'])
  end
end

.url(email_address = nil) ⇒ Object



13
14
15
16
17
# File 'lib/sendgrid4r/rest/sm/global_unsubscribes.rb', line 13

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

.url_unsubscribesObject



19
20
21
# File 'lib/sendgrid4r/rest/sm/global_unsubscribes.rb', line 19

def self.url_unsubscribes
  "#{BASE_URL}/suppression/unsubscribes"
end

Instance Method Details

#delete_global_suppressed_email(email_address:, &block) ⇒ Object Also known as: delete_global_unsubscribe



58
59
60
# File 'lib/sendgrid4r/rest/sm/global_unsubscribes.rb', line 58

def delete_global_suppressed_email(email_address:, &block)
  delete(@auth, Sm::GlobalUnsubscribes.url(email_address), &block)
end

#get_global_suppressed_email(email_address:, &block) ⇒ Object Also known as: get_global_unsubscribe



53
54
55
56
# File 'lib/sendgrid4r/rest/sm/global_unsubscribes.rb', line 53

def get_global_suppressed_email(email_address:, &block)
  resp = get(@auth, Sm::GlobalUnsubscribes.url(email_address), &block)
  finish(resp, @raw_resp) { |r| Sm.create_recipient_email(r) }
end

#get_global_unsubscribes(start_time: nil, end_time: nil, limit: nil, offset: nil, &block) ⇒ Object



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

def get_global_unsubscribes(
  start_time: nil, end_time: nil, limit: nil, offset: nil, &block
)
  params = {}
  params[:start_time] = start_time.to_i unless start_time.nil?
  params[:end_time] = end_time.to_i unless end_time.nil?
  params[:limit] = limit.to_i unless limit.nil?
  params[:offset] = offset.to_i unless offset.nil?
  endpoint = Sm::GlobalUnsubscribes.url_unsubscribes
  resp = get(@auth, endpoint, params, &block)
  finish(resp, @raw_resp) do |r|
    Sm::GlobalUnsubscribes.create_supressions(r)
  end
end

#post_global_suppressed_emails(recipient_emails:, &block) ⇒ Object Also known as: post_global_unsubscribes



46
47
48
49
50
51
# File 'lib/sendgrid4r/rest/sm/global_unsubscribes.rb', line 46

def post_global_suppressed_emails(recipient_emails:, &block)
  params = { recipient_emails: recipient_emails }
  endpoint = Sm::GlobalUnsubscribes.url
  resp = post(@auth, endpoint, params, &block)
  finish(resp, @raw_resp) { |r| Sm.create_recipient_emails(r) }
end