class Crm::MailingDelivery

MailingDelivery represents a mailing delivery. @api public

Public Class Methods

all(mailing_id, since: nil) click to toggle source
# File lib/crm/mailing_delivery.rb, line 10
def self.all(mailing_id, since: nil)
  path = ['mailings', mailing_id, 'mailing_deliveries'].compact.join('/')
  params = {}
  case since
  when Time
    params[:since] = since.utc.xmlschema
  when String
    params[:since] = since
  when nil
    # ignore
  else
    raise "unknown class of since param: #{since.class}"
  end
  Core::RestApi.instance.get(path, params).map {|attrs| new({'mailing_id' => mailing_id}.merge(attrs))}
end
create(mailing_id, id, attributes = {}) click to toggle source

Creates or updates a mailing delivery. @example

Crm::MailingDelivery.create(mailing.id, "abc@example.com", {
  custom_data: {
    salutation: 'Hello You',
  },
})

@param mailing_id [String] the mailing ID @param id [String] the email address @param attributes [Hash{String, Symbol => String}] the new attributes. @return [self] the created or updated mailing delivery. @api public

# File lib/crm/mailing_delivery.rb, line 38
def self.create(mailing_id, id, attributes = {})
  new({'mailing_id' => mailing_id, 'id' => id}).update(attributes)
end
find(mailing_id, id) click to toggle source

Returns the requested mailing delivery. @example

d = Crm::MailingDelivery.find(mailing.id, "abc@example.com")
# => #<Crm::MailingDelivery mailing_id="94933088cec0014575ff920ee9830cfb", id="abc@example.com">

@param mailing_id [String] the mailing ID @param id [String] the email address @return [MailingDelivery] @api public

# File lib/crm/mailing_delivery.rb, line 50
def self.find(mailing_id, id)
  raise Crm::Errors::ResourceNotFound.new("Items could not be found.", [mailing_id]) if mailing_id.blank?
  raise Crm::Errors::ResourceNotFound.new("Items could not be found.", [id]) if id.blank?

  new({'mailing_id' => mailing_id, 'id' => id}).reload
end

Public Instance Methods

delete() click to toggle source

Deletes the mailing delivery.

@raise [Errors::ResourceConflict] if the item has been changed concurrently.

{Core::BasicResource#reload Reload} it, review the changes and retry.

@api public

# File lib/crm/mailing_delivery.rb, line 62
def delete
  Core::RestApi.instance.delete(path, nil, if_match_header)
  nil
end
reload() click to toggle source
# File lib/crm/mailing_delivery.rb, line 81
def reload
  load_attributes(Core::RestApi.instance.get(path))
end
update(attributes = {}) click to toggle source

Updates the attributes of this mailing delivery. @example

mailing_delivery.update({
  custom_data: {
    salutation: 'Hello You',
  },
})

@param attributes [Hash{String, Symbol => String}] the new attributes. @return [self] the updated mailing delivery. @api public

# File lib/crm/mailing_delivery.rb, line 77
def update(attributes = {})
  load_attributes(Core::RestApi.instance.put(path, attributes, if_match_header))
end

Private Instance Methods

if_match_header() click to toggle source
# File lib/crm/mailing_delivery.rb, line 91
def if_match_header
  {'If-Match' => self['version']}
end
path() click to toggle source
# File lib/crm/mailing_delivery.rb, line 87
def path
  ['mailings', mailing_id, 'mailing_deliveries', id].compact.join('/')
end