Module: SendGrid4r::REST::MarketingCampaigns::Contacts::Segments
- Includes:
- Request
- Included in:
- API
- Defined in:
- lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb
Overview
SendGrid Web API v3 Contacts - Segments
Defined Under Namespace
Classes: Condition, Segment, Segments
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_condition(resp) ⇒ Object
24
25
26
27
28
29
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb', line 24
def self.create_condition(resp)
return resp if resp.nil?
Condition.new(
resp['field'], resp['value'], resp['operator'], resp['and_or']
)
end
|
.create_segment(resp) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb', line 31
def self.create_segment(resp)
return resp if resp.nil?
conditions = resp['conditions'].map do |condition|
Contacts::Segments.create_condition(condition)
end
Segment.new(
resp['id'],
resp['name'],
resp['list_id'],
conditions,
resp['recipient_count']
)
end
|
.create_segments(resp) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb', line 45
def self.create_segments(resp)
return resp if resp.nil?
segments = resp['segments'].map do |segment|
Contacts::Segments.create_segment(segment)
end
Segments.new(segments)
end
|
.url(segment_id = nil) ⇒ Object
18
19
20
21
22
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb', line 18
def self.url(segment_id = nil)
url = "#{BASE_URL}/contactdb/segments"
url = "#{url}/#{segment_id}" unless segment_id.nil?
url
end
|
Instance Method Details
#delete_segment(segment_id:, &block) ⇒ Object
74
75
76
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb', line 74
def delete_segment(segment_id:, &block)
delete(@auth, Contacts::Segments.url(segment_id), &block)
end
|
#get_recipients_on_segment(segment_id:, &block) ⇒ Object
78
79
80
81
82
83
84
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb', line 78
def get_recipients_on_segment(segment_id:, &block)
endpoint = "#{Contacts::Segments.url(segment_id)}/recipients"
resp = get(@auth, endpoint, nil, &block)
finish(resp, @raw_resp) do |r|
Contacts::Recipients.create_recipients(r)
end
end
|
#get_segment(segment_id:, &block) ⇒ Object
63
64
65
66
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb', line 63
def get_segment(segment_id:, &block)
resp = get(@auth, Contacts::Segments.url(segment_id), &block)
finish(resp, @raw_resp) { |r| Contacts::Segments.create_segment(r) }
end
|
#get_segments(&block) ⇒ Object
#patch_segment(segment_id:, params:, &block) ⇒ Object
68
69
70
71
72
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb', line 68
def patch_segment(segment_id:, params:, &block)
endpoint = Contacts::Segments.url(segment_id)
resp = patch(@auth, endpoint, params, &block)
finish(resp, @raw_resp) { |r| Contacts::Segments.create_segment(r) }
end
|
#post_segment(params:, &block) ⇒ Object
53
54
55
56
|
# File 'lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb', line 53
def post_segment(params:, &block)
resp = post(@auth, Contacts::Segments.url, params.to_h, &block)
finish(resp, @raw_resp) { |r| Contacts::Segments.create_segment(r) }
end
|