module SendGrid4r::REST::MarketingCampaigns::Contacts::Recipients

SendGrid Web API v3 Contacts - Recipients

Constants

Count
Error
Recipient
Recipients
Result

Public Class Methods

create_error(resp) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb, line 141
def self.create_error(resp)
  return resp if resp.nil?
  Error.new(resp['error_indices'], resp['message'])
end
create_recipient(resp) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb, line 28
def self.create_recipient(resp)
  return resp if resp.nil?
  custom_fields = []
  custom_fields = resp['custom_fields'].map do |field|
    Contacts::CustomFields.create_field(field)
  end unless resp['custom_fields'].nil?
  Recipient.new(
    Time.at(resp['created_at']), custom_fields,
    resp['email'], resp['first_name'], resp['id'],
    resp['last_clicked'], resp['last_emailed'],
    resp['last_name'], resp['last_opened'],
    Time.at(resp['updated_at'])
  )
end
create_recipient_count(resp) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb, line 51
def self.create_recipient_count(resp)
  return resp if resp.nil?
  Count.new(resp['recipient_count'])
end
create_recipients(resp) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb, line 43
def self.create_recipients(resp)
  return resp if resp.nil?
  recipients = resp['recipients'].map do |recipient|
    Contacts::Recipients.create_recipient(recipient)
  end
  Recipients.new(recipients)
end
create_result(resp) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb, line 128
def self.create_result(resp)
  return resp if resp.nil?
  errors = resp['errors'].map do |error|
    Contacts::Recipients.create_error(error)
  end unless resp['errors'].nil?
  Result.new(
    resp['error_count'], resp['error_indices'], resp['new_count'],
    resp['persisted_recipients'], resp['updated_count'], errors
  )
end
url(recipient_id = nil) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb, line 56
def self.url(recipient_id = nil)
  url = "#{BASE_URL}/contactdb/recipients"
  url = "#{url}/#{recipient_id}" unless recipient_id.nil?
  url
end

Public Instance Methods

delete_recipient(recipient_id:, &block) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb, line 93
def delete_recipient(recipient_id:, &block)
  delete(@auth, Contacts::Recipients.url(recipient_id), &block)
end
delete_recipients(recipient_ids:, &block) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb, line 72
def delete_recipients(recipient_ids:, &block)
  delete(@auth, Contacts::Recipients.url, nil, recipient_ids, &block)
end
get_lists_recipient_belong(recipient_id:, &block) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb, line 97
def get_lists_recipient_belong(recipient_id:, &block)
  resp = get(
    @auth, "#{Contacts::Recipients.url(recipient_id)}/lists", &block
  )
  finish(resp, @raw_resp) { |r| Contacts::Lists.create_lists(r) }
end
get_recipient(recipient_id:, &block) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb, line 86
def get_recipient(recipient_id:, &block)
  resp = get(@auth, Contacts::Recipients.url(recipient_id), &block)
  finish(resp, @raw_resp) do |r|
    Contacts::Recipients.create_recipient(r)
  end
end
get_recipients(page: nil, page_size: nil, &block) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb, line 76
def get_recipients(page: nil, page_size: nil, &block)
  params = {}
  params['page_size'] = page_size unless page_size.nil?
  params['page'] = page unless page.nil?
  resp = get(@auth, Contacts::Recipients.url, params, &block)
  finish(resp, @raw_resp) do |r|
    Contacts::Recipients.create_recipients(r)
  end
end
get_recipients_count(&block) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb, line 104
def get_recipients_count(&block)
  resp = get(@auth, "#{Contacts::Recipients.url}/count", &block)
  finish(resp, @raw_resp) do |r|
    Contacts::Recipients.create_recipient_count(r).recipient_count
  end
end
patch_recipients(params:, &block) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb, line 67
def patch_recipients(params:, &block)
  resp = patch(@auth, Contacts::Recipients.url, params, &block)
  finish(resp, @raw_resp) { |r| Contacts::Recipients.create_result(r) }
end
post_recipients(params:, &block) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb, line 62
def post_recipients(params:, &block)
  resp = post(@auth, Contacts::Recipients.url, params, &block)
  finish(resp, @raw_resp) { |r| Contacts::Recipients.create_result(r) }
end
search_recipients(params:, &block) click to toggle source
# File lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb, line 111
def search_recipients(params:, &block)
  endpoint = "#{Contacts::Recipients.url}/search"
  resp = get(@auth, endpoint, params, &block)
  finish(resp, @raw_resp) do |r|
    Contacts::Recipients.create_recipients(r)
  end
end