Class: Crm::MailingDelivery

Inherits:
Object
  • Object
show all
Includes:
Core::Mixins::AttributeProvider, Core::Mixins::Inspectable
Defined in:
lib/crm/mailing_delivery.rb

Overview

MailingDelivery represents a mailing delivery.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Core::Mixins::AttributeProvider

#[], #attributes, #initialize, #method_missing, #methods, #raw, #respond_to_missing?

Methods included from Core::Mixins::Inspectable

#inspect

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Crm::Core::Mixins::AttributeProvider

Class Method Details

.all(mailing_id, since: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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 = {}) ⇒ self

Creates or updates a mailing delivery.

Examples:

Crm::MailingDelivery.create(mailing.id, "[email protected]", {
  custom_data: {
    salutation: 'Hello You',
  },
})

Parameters:

  • mailing_id (String)

    the mailing ID

  • id (String)

    the email address

  • attributes (Hash{String, Symbol => String}) (defaults to: {})

    the new attributes.

Returns:

  • (self)

    the created or updated mailing delivery.



38
39
40
# 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) ⇒ MailingDelivery

Returns the requested mailing delivery.

Examples:

d = Crm::MailingDelivery.find(mailing.id, "[email protected]")
# => #<Crm::MailingDelivery mailing_id="94933088cec0014575ff920ee9830cfb", id="[email protected]">

Parameters:

  • mailing_id (String)

    the mailing ID

  • id (String)

    the email address

Returns:

Raises:



50
51
52
53
54
55
# 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

Instance Method Details

#deleteObject

Deletes the mailing delivery.

Raises:



62
63
64
65
# File 'lib/crm/mailing_delivery.rb', line 62

def delete
  Core::RestApi.instance.delete(path, nil, if_match_header)
  nil
end

#reloadObject



81
82
83
# File 'lib/crm/mailing_delivery.rb', line 81

def reload
  load_attributes(Core::RestApi.instance.get(path))
end

#update(attributes = {}) ⇒ self

Updates the attributes of this mailing delivery.

Examples:

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

Parameters:

  • attributes (Hash{String, Symbol => String}) (defaults to: {})

    the new attributes.

Returns:

  • (self)

    the updated mailing delivery.



77
78
79
# File 'lib/crm/mailing_delivery.rb', line 77

def update(attributes = {})
  load_attributes(Core::RestApi.instance.put(path, attributes, if_match_header))
end