Module: SendGrid4r::REST::MarketingCampaigns
- Includes:
- Request
- Included in:
- API
- Defined in:
- lib/sendgrid4r/rest/marketing_campaigns/senders.rb,
lib/sendgrid4r/rest/marketing_campaigns/contacts/lists.rb,
lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb,
lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb,
lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb,
lib/sendgrid4r/rest/marketing_campaigns/contacts/custom_fields.rb,
lib/sendgrid4r/rest/marketing_campaigns/contacts/reserved_fields.rb
Overview
SendGrid Web API v3 MarketingCampaigns
Defined Under Namespace
Modules: Contacts
Classes: Address, Campaign, Campaigns, Sender, Verified
Constant Summary
Constants included
from Request
Request::BASE_URL
Class Method Summary
collapse
Instance Method Summary
collapse
-
#delete_campaign(campaign_id:, &block) ⇒ Object
-
#delete_sender(sender_id:, &block) ⇒ Object
-
#get_campaign(campaign_id:, &block) ⇒ Object
-
#get_campaigns(&block) ⇒ Object
-
#get_schedule_time_campaign(campaign_id:, &block) ⇒ Object
-
#get_sender(sender_id:, &block) ⇒ Object
-
#get_senders(&block) ⇒ Object
-
#patch_campaign(campaign_id:, params:, &block) ⇒ Object
-
#patch_sender(sender_id:, params:, &block) ⇒ Object
-
#post_campaign(params:, &block) ⇒ Object
-
#post_sender(params:, &block) ⇒ Object
-
#reschedule_campaign(campaign_id:, send_at:, &block) ⇒ Object
-
#resend_sender_verification(sender_id:, &block) ⇒ Object
-
#schedule_campaign(campaign_id:, send_at:, &block) ⇒ Object
-
#send_campaign(campaign_id:, &block) ⇒ Object
-
#test_campaign(campaign_id:, to:, &block) ⇒ Object
-
#unschedule_campaign(campaign_id:, &block) ⇒ Object
Methods included from Request
#create_args, #delete, #execute, #finish, #get, #patch, #post, #process_array_params, #process_url_params, #put
Class Method Details
.create_address(resp) ⇒ Object
51
52
53
54
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/senders.rb', line 51
def self.create_address(resp)
return resp if resp.nil?
Address.new(resp['email'], resp['name'])
end
|
.create_campaign(resp) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb', line 18
def self.create_campaign(resp)
return resp if resp.nil?
send_at = Time.at(resp['send_at']) unless resp['send_at'].nil?
Campaign.new(
resp['id'], resp['title'], resp['subject'], resp['sender_id'],
resp['list_ids'], resp['segment_ids'], resp['categories'],
resp['suppression_group_id'], resp['custom_unsubscribe_url'],
resp['ip_pool'], resp['html_content'], resp['plain_content'],
send_at, resp['status']
)
end
|
.create_campaigns(resp) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb', line 30
def self.create_campaigns(resp)
return resp if resp.nil?
result = resp['result'].map do |campaign|
MarketingCampaigns.create_campaign(campaign)
end
Campaigns.new(result)
end
|
.create_sender(resp) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/senders.rb', line 31
def self.create_sender(resp)
return resp if resp.nil?
from = MarketingCampaigns.create_address(resp['from'])
reply_to = MarketingCampaigns.create_address(resp['reply_to'])
verified = MarketingCampaigns.create_verified(resp['verified'])
Sender.new(
resp['id'], resp['nickname'], from, reply_to, resp['address'],
resp['address_2'], resp['city'], resp['state'], resp['zip'],
resp['country'], verified, Time.at(resp['updated_at']),
Time.at(resp['created_at']), resp['locked']
)
end
|
.create_senders(resp) ⇒ Object
44
45
46
47
48
49
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/senders.rb', line 44
def self.create_senders(resp)
return resp if resp.nil?
resp.map do |sender|
MarketingCampaigns.create_sender(sender)
end
end
|
.create_verified(resp) ⇒ Object
56
57
58
59
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/senders.rb', line 56
def self.create_verified(resp)
return resp if resp.nil?
Verified.new(resp['status'], resp['reason'])
end
|
.url(campaign_id = nil) ⇒ Object
38
39
40
41
42
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb', line 38
def self.url(campaign_id = nil)
url = "#{BASE_URL}/campaigns"
url = "#{url}/#{campaign_id}" unless campaign_id.nil?
url
end
|
.url_sender(sender_id = nil) ⇒ Object
61
62
63
64
65
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/senders.rb', line 61
def self.url_sender(sender_id = nil)
url = "#{BASE_URL}/senders"
url = "#{url}/#{sender_id}" unless sender_id.nil?
url
end
|
Instance Method Details
#delete_campaign(campaign_id:, &block) ⇒ Object
62
63
64
65
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb', line 62
def delete_campaign(campaign_id:, &block)
endpoint = MarketingCampaigns.url(campaign_id)
delete(@auth, endpoint, &block)
end
|
#delete_sender(sender_id:, &block) ⇒ Object
85
86
87
88
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/senders.rb', line 85
def delete_sender(sender_id:, &block)
endpoint = MarketingCampaigns.url_sender(sender_id)
delete(@auth, endpoint, &block)
end
|
#get_campaign(campaign_id:, &block) ⇒ Object
56
57
58
59
60
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb', line 56
def get_campaign(campaign_id:, &block)
endpoint = MarketingCampaigns.url(campaign_id)
resp = get(@auth, endpoint, &block)
finish(resp, @raw_resp) { |r| MarketingCampaigns.create_campaign(r) }
end
|
#get_campaigns(&block) ⇒ Object
#get_schedule_time_campaign(campaign_id:, &block) ⇒ Object
98
99
100
101
102
103
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb', line 98
def get_schedule_time_campaign(campaign_id:, &block)
endpoint = MarketingCampaigns.url(campaign_id)
endpoint = "#{endpoint}/schedules"
resp = get(@auth, endpoint, &block)
finish(resp, @raw_resp) { |r| MarketingCampaigns.create_campaign(r) }
end
|
#get_sender(sender_id:, &block) ⇒ Object
#get_senders(&block) ⇒ Object
#patch_campaign(campaign_id:, params:, &block) ⇒ Object
67
68
69
70
71
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb', line 67
def patch_campaign(campaign_id:, params:, &block)
endpoint = MarketingCampaigns.url(campaign_id)
resp = patch(@auth, endpoint, params.to_h, &block)
finish(resp, @raw_resp) { |r| MarketingCampaigns.create_campaign(r) }
end
|
#patch_sender(sender_id:, params:, &block) ⇒ Object
79
80
81
82
83
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/senders.rb', line 79
def patch_sender(sender_id:, params:, &block)
endpoint = MarketingCampaigns.url_sender(sender_id)
resp = patch(@auth, endpoint, params.to_h, &block)
finish(resp, @raw_resp) { |r| MarketingCampaigns.create_sender(r) }
end
|
#post_campaign(params:, &block) ⇒ Object
44
45
46
47
48
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb', line 44
def post_campaign(params:, &block)
endpoint = MarketingCampaigns.url
resp = post(@auth, endpoint, params, &block)
finish(resp, @raw_resp) { |r| MarketingCampaigns.create_campaign(r) }
end
|
#post_sender(params:, &block) ⇒ Object
#reschedule_campaign(campaign_id:, send_at:, &block) ⇒ Object
89
90
91
92
93
94
95
96
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb', line 89
def reschedule_campaign(campaign_id:, send_at:, &block)
endpoint = MarketingCampaigns.url(campaign_id)
endpoint = "#{endpoint}/schedules"
payload = {}
payload['send_at'] = send_at.to_i
resp = patch(@auth, endpoint, payload, &block)
finish(resp, @raw_resp) { |r| MarketingCampaigns.create_campaign(r) }
end
|
#resend_sender_verification(sender_id:, &block) ⇒ Object
90
91
92
93
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/senders.rb', line 90
def resend_sender_verification(sender_id:, &block)
endpoint = MarketingCampaigns.url_sender(sender_id)
post(@auth, "#{endpoint}/resend_verification", nil, &block)
end
|
#schedule_campaign(campaign_id:, send_at:, &block) ⇒ Object
80
81
82
83
84
85
86
87
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb', line 80
def schedule_campaign(campaign_id:, send_at:, &block)
endpoint = MarketingCampaigns.url(campaign_id)
endpoint = "#{endpoint}/schedules"
payload = {}
payload['send_at'] = send_at.to_i
resp = post(@auth, endpoint, payload, &block)
finish(resp, @raw_resp) { |r| MarketingCampaigns.create_campaign(r) }
end
|
#send_campaign(campaign_id:, &block) ⇒ Object
73
74
75
76
77
78
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb', line 73
def send_campaign(campaign_id:, &block)
endpoint = MarketingCampaigns.url(campaign_id)
endpoint = "#{endpoint}/schedules/now"
resp = post(@auth, endpoint, nil, &block)
finish(resp, @raw_resp) { |r| MarketingCampaigns.create_campaign(r) }
end
|
#test_campaign(campaign_id:, to:, &block) ⇒ Object
111
112
113
114
115
116
117
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb', line 111
def test_campaign(campaign_id:, to:, &block)
endpoint = MarketingCampaigns.url(campaign_id)
endpoint = "#{endpoint}/schedules/test"
payload = {}
payload['to'] = to
post(@auth, endpoint, payload, &block)
end
|
#unschedule_campaign(campaign_id:, &block) ⇒ Object
105
106
107
108
109
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb', line 105
def unschedule_campaign(campaign_id:, &block)
endpoint = MarketingCampaigns.url(campaign_id)
endpoint = "#{endpoint}/schedules"
delete(@auth, endpoint, &block)
end
|