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, #finish, #get, #patch, #post, #process_array_params, #process_url_params, #put

Class Method Details

.create_block(resp) ⇒ Object



23
24
25
26
27
# File 'lib/sendgrid4r/rest/blocks.rb', line 23

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



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

def self.create_blocks(resp)
  return resp if resp.nil?
  resp.map { |block| Blocks.create_block(block) }
end

.url(email = nil) ⇒ Object



12
13
14
15
16
# File 'lib/sendgrid4r/rest/blocks.rb', line 12

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



56
57
58
59
# File 'lib/sendgrid4r/rest/blocks.rb', line 56

def delete_block(email:, &block)
  params = { email: email }
  delete(@auth, Blocks.url(email), params, &block)
end

#delete_blocks(delete_all: nil, emails: nil, &block) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/sendgrid4r/rest/blocks.rb', line 41

def delete_blocks(delete_all: nil, emails: nil, &block)
  if delete_all
    payload = { delete_all: delete_all }
  else
    payload = { emails: emails }
  end
  delete(@auth, Blocks.url, nil, payload, &block)
end

#get_block(email:, &block) ⇒ Object



50
51
52
53
54
# File 'lib/sendgrid4r/rest/blocks.rb', line 50

def get_block(email:, &block)
  params = { email: email }
  resp = get(@auth, Blocks.url(email), params, &block)
  finish(resp, @raw_resp) { |r| Blocks.create_blocks(r) }
end

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



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

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, Blocks.url, params, &block)
  finish(resp, @raw_resp) { |r| Blocks.create_blocks(r) }
end