module SendGrid4r::REST::MarketingCampaigns::Contacts::Segments

SendGrid Web API v3 Contacts - Segments

Constants

Condition
Segment
Segments

Public Class Methods

create_condition(resp) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb, line 23
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) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb, line 30
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) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb, line 44
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) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb, line 17
def self.url(segment_id = nil)
  url = "#{BASE_URL}/contactdb/segments"
  url = "#{url}/#{segment_id}" unless segment_id.nil?
  url
end

Public Instance Methods

delete_segment(segment_id:, &block) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb, line 73
def delete_segment(segment_id:, &block)
  delete(@auth, Contacts::Segments.url(segment_id), &block)
end
get_recipients_on_segment(segment_id:, &block) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb, line 77
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) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb, line 62
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) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb, line 57
def get_segments(&block)
  resp = get(@auth, Contacts::Segments.url, &block)
  finish(resp, @raw_resp) { |r| Contacts::Segments.create_segments(r) }
end
patch_segment(segment_id:, params:, &block) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb, line 67
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) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb, line 52
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