Module: SendGrid4r::REST::MarketingCampaigns::Contacts::Lists
- Includes:
- Request
- Included in:
- API
- Defined in:
- lib/sendgrid4r/rest/marketing_campaigns/contacts/lists.rb
Overview
SendGrid Web API v3 Contacts - Lists
Defined Under Namespace
Classes: List, Lists
Constant Summary
Constants included
from Request
Request::BASE_URL
Class Method Summary
collapse
Instance Method Summary
collapse
-
#delete_list(list_id:, &block) ⇒ Object
-
#delete_lists(list_ids:, &block) ⇒ Object
-
#delete_recipient_from_list(list_id:, recipient_id:, &block) ⇒ Object
-
#get_list(list_id:, &block) ⇒ Object
-
#get_lists(&block) ⇒ Object
-
#get_recipients_from_list(list_id:, page: nil, page_size: nil, &block) ⇒ Object
-
#patch_list(list_id:, name:, &block) ⇒ Object
-
#post_list(name:, &block) ⇒ Object
-
#post_recipient_to_list(list_id:, recipient_id:, &block) ⇒ Object
-
#post_recipients_to_list(list_id:, recipients:, &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_list(resp) ⇒ Object
27
28
29
30
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/lists.rb', line 27
def self.create_list(resp)
return resp if resp.nil?
List.new(resp['id'], resp['name'], resp['recipient_count'])
end
|
.create_lists(resp) ⇒ Object
32
33
34
35
36
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/lists.rb', line 32
def self.create_lists(resp)
return resp if resp.nil?
lists = resp['lists'].map { |list| Contacts::Lists.create_list(list) }
Lists.new(lists)
end
|
.recipients_url(list_id, recipient_id = nil) ⇒ Object
21
22
23
24
25
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/lists.rb', line 21
def self.recipients_url(list_id, recipient_id = nil)
url = "#{Contacts::Lists.url(list_id)}/recipients"
url = "#{url}/#{recipient_id}" unless recipient_id.nil?
url
end
|
.url(list_id = nil) ⇒ Object
15
16
17
18
19
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/lists.rb', line 15
def self.url(list_id = nil)
url = "#{BASE_URL}/contactdb/lists"
url = "#{url}/#{list_id}" unless list_id.nil?
url
end
|
Instance Method Details
#delete_list(list_id:, &block) ⇒ Object
62
63
64
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/lists.rb', line 62
def delete_list(list_id:, &block)
delete(@auth, Contacts::Lists.url(list_id), &block)
end
|
#delete_lists(list_ids:, &block) ⇒ Object
95
96
97
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/lists.rb', line 95
def delete_lists(list_ids:, &block)
delete(@auth, "#{BASE_URL}/contactdb/lists", nil, list_ids, &block)
end
|
#delete_recipient_from_list(list_id:, recipient_id:, &block) ⇒ Object
90
91
92
93
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/lists.rb', line 90
def delete_recipient_from_list(list_id:, recipient_id:, &block)
endpoint = Contacts::Lists.recipients_url(list_id, recipient_id)
delete(@auth, endpoint, &block)
end
|
#get_list(list_id:, &block) ⇒ Object
50
51
52
53
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/lists.rb', line 50
def get_list(list_id:, &block)
resp = get(@auth, Contacts::Lists.url(list_id), &block)
finish(resp, @raw_resp) { |r| Contacts::Lists.create_list(r) }
end
|
#get_lists(&block) ⇒ Object
45
46
47
48
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/lists.rb', line 45
def get_lists(&block)
resp = get(@auth, Contacts::Lists.url, &block)
finish(resp, @raw_resp) { |r| Contacts::Lists.create_lists(r) }
end
|
#get_recipients_from_list(list_id:, page: nil, page_size: nil, &block) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/lists.rb', line 72
def get_recipients_from_list(
list_id:, page: nil, page_size: nil, &block
)
params = {}
params['page'] = page unless page.nil?
params['page_size'] = page_size unless page_size.nil?
endpoint = Contacts::Lists.recipients_url(list_id)
resp = get(@auth, endpoint, params, &block)
finish(resp, @raw_resp) do |r|
Contacts::Recipients.create_recipients(r)
end
end
|
#patch_list(list_id:, name:, &block) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/lists.rb', line 55
def patch_list(list_id:, name:, &block)
params = {}
params['name'] = name
resp = patch(@auth, Contacts::Lists.url(list_id), params, &block)
finish(resp, @raw_resp) { |r| Contacts::Lists.create_list(r) }
end
|
#post_list(name:, &block) ⇒ Object
38
39
40
41
42
43
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/lists.rb', line 38
def post_list(name:, &block)
params = {}
params['name'] = name
resp = post(@auth, Contacts::Lists.url, params, &block)
finish(resp, @raw_resp) { |r| Contacts::Lists.create_list(r) }
end
|
#post_recipient_to_list(list_id:, recipient_id:, &block) ⇒ Object
85
86
87
88
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/lists.rb', line 85
def post_recipient_to_list(list_id:, recipient_id:, &block)
endpoint = Contacts::Lists.recipients_url(list_id, recipient_id)
post(@auth, endpoint, &block)
end
|
#post_recipients_to_list(list_id:, recipients:, &block) ⇒ Object
67
68
69
70
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/lists.rb', line 67
def post_recipients_to_list(list_id:, recipients:, &block)
endpoint = "#{Contacts::Lists.url(list_id)}/recipients"
post(@auth, endpoint, recipients, &block)
end
|