Module: SendGrid4r::REST::CancelScheduledSends

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

Overview

SendGrid Web API v3 CancelScheduledSends

Defined Under Namespace

Classes: ScheduledSend

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

.batch_url(batch_id = nil) ⇒ Object



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

def self.batch_url(batch_id = nil)
  url = "#{BASE_URL}/mail/batch"
  url = "#{url}/#{batch_id}" unless batch_id.nil?
  url
end

.create_scheduled_send(resp) ⇒ Object



31
32
33
34
# File 'lib/sendgrid4r/rest/cancel_scheduled_sends.rb', line 31

def self.create_scheduled_send(resp)
  return resp if resp.nil?
  ScheduledSend.new(resp['batch_id'], resp['status'])
end

.create_scheduled_sends(resp) ⇒ Object



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

def self.create_scheduled_sends(resp)
  return resp if resp.nil?
  resp.map do |scheduled_send|
    CancelScheduledSends.create_scheduled_send(scheduled_send)
  end
end

.scheduled_sends_url(batch_id = nil) ⇒ Object



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

def self.scheduled_sends_url(batch_id = nil)
  url = "#{BASE_URL}/user/scheduled_sends"
  url = "#{url}/#{batch_id}" unless batch_id.nil?
  url
end

Instance Method Details

#delete_scheduled_send(batch_id:, &block) ⇒ Object



73
74
75
76
# File 'lib/sendgrid4r/rest/cancel_scheduled_sends.rb', line 73

def delete_scheduled_send(batch_id:, &block)
  endpoint = CancelScheduledSends.scheduled_sends_url(batch_id)
  delete(@auth, endpoint, nil, &block)
end

#generate_batch_id(&block) ⇒ Object



36
37
38
39
40
41
# File 'lib/sendgrid4r/rest/cancel_scheduled_sends.rb', line 36

def generate_batch_id(&block)
  resp = post(@auth, CancelScheduledSends.batch_url, nil, &block)
  finish(resp, @raw_resp) do |r|
    CancelScheduledSends.create_scheduled_send(r)
  end
end

#get_scheduled_sends(batch_id: nil, &block) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/sendgrid4r/rest/cancel_scheduled_sends.rb', line 59

def get_scheduled_sends(batch_id: nil, &block)
  endpoint = CancelScheduledSends.scheduled_sends_url(batch_id)
  resp = get(@auth, endpoint, nil, nil, &block)
  finish(resp, @raw_resp) do |r|
    CancelScheduledSends.create_scheduled_sends(r)
  end
end

#patch_scheduled_send(batch_id:, status:, &block) ⇒ Object



67
68
69
70
71
# File 'lib/sendgrid4r/rest/cancel_scheduled_sends.rb', line 67

def patch_scheduled_send(batch_id:, status:, &block)
  endpoint = CancelScheduledSends.scheduled_sends_url(batch_id)
  payload = { status: status }
  patch(@auth, endpoint, payload, &block)
end

#post_scheduled_send(batch_id:, status:, &block) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/sendgrid4r/rest/cancel_scheduled_sends.rb', line 50

def post_scheduled_send(batch_id:, status:, &block)
  endpoint = CancelScheduledSends.scheduled_sends_url
  payload = { batch_id: batch_id, status: status }
  resp = post(@auth, endpoint, payload, &block)
  finish(resp, @raw_resp) do |r|
    CancelScheduledSends.create_scheduled_send(r)
  end
end

#validate_batch_id(batch_id:, &block) ⇒ Object



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

def validate_batch_id(batch_id:, &block)
  resp = get(@auth, CancelScheduledSends.batch_url(batch_id), nil, &block)
  finish(resp, @raw_resp) do |r|
    CancelScheduledSends.create_scheduled_send(r)
  end
end