Module: SendGrid4r::REST::Blocks
- Includes:
- Request
- Included in:
- API
- Defined in:
- lib/sendgrid4r/rest/blocks.rb
Overview
SendGrid Web API v3 Blocks
Defined Under Namespace
Classes: Block
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, #get, #patch, #post, #process_array_params, #process_url_params, #put
Class Method Details
.create_block(resp) ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/sendgrid4r/rest/blocks.rb', line 30
def self.create_block(resp)
return resp if resp.nil?
created = Time.at(resp['created']) unless resp['created'].nil?
Block.new(
created,
resp['email'],
resp['reason'],
resp['status']
)
end
|
.create_blocks(resp) ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'lib/sendgrid4r/rest/blocks.rb', line 21
def self.create_blocks(resp)
return resp if resp.nil?
blocks = []
resp.each do |block|
blocks.push(SendGrid4r::REST::Blocks.create_block(block))
end
blocks
end
|
.url(email = nil) ⇒ Object
15
16
17
18
19
|
# File 'lib/sendgrid4r/rest/blocks.rb', line 15
def self.url(email = nil)
url = "#{BASE_URL}/suppression/blocks"
url = "#{url}/#{email}" unless email.nil?
url
end
|
Instance Method Details
#delete_block(email:, &block) ⇒ Object
72
73
74
75
76
77
|
# File 'lib/sendgrid4r/rest/blocks.rb', line 72
def delete_block(email:, &block)
endpoint = SendGrid4r::REST::Blocks.url(email)
params = {}
params['email'] = email
delete(@auth, endpoint, params, &block)
end
|
#delete_blocks(delete_all: nil, emails: nil, &block) ⇒ Object
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/sendgrid4r/rest/blocks.rb', line 53
def delete_blocks(delete_all: nil, emails: nil, &block)
endpoint = SendGrid4r::REST::Blocks.url
payload = {}
if delete_all == true
payload['delete_all'] = delete_all
else
payload['emails'] = emails
end
delete(@auth, endpoint, nil, payload, &block)
end
|
#get_block(email:, &block) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/sendgrid4r/rest/blocks.rb', line 64
def get_block(email:, &block)
endpoint = SendGrid4r::REST::Blocks.url(email)
params = {}
params['email'] = email
resp = get(@auth, endpoint, params, &block)
SendGrid4r::REST::Blocks.create_blocks(resp)
end
|
#get_blocks(start_time: nil, end_time: nil, limit: nil, offset: nil, &block) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/sendgrid4r/rest/blocks.rb', line 41
def get_blocks(
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?
resp = get(@auth, SendGrid4r::REST::Blocks.url, params, &block)
SendGrid4r::REST::Blocks.create_blocks(resp)
end
|