Class: Bronto::Delivery

Inherits:
Base show all
Defined in:
lib/bronto/delivery.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#api_key, #errors, #id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

api, api_key, api_key=, #create, create, destroy, #destroy, plural_class_name, #reload, #request, request, save, #save, session_expired, update, #update

Constructor Details

#initialize(options = {}) ⇒ Delivery

Returns a new instance of Delivery.



21
22
23
24
# File 'lib/bronto/delivery.rb', line 21

def initialize(options = {})
  super(options)
  self.recipients = []
end

Instance Attribute Details

#authenticationObject

Returns the value of attribute authentication.



3
4
5
# File 'lib/bronto/delivery.rb', line 3

def authentication
  @authentication
end

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/bronto/delivery.rb', line 3

def content
  @content
end

#fieldsObject

Returns the value of attribute fields.



3
4
5
# File 'lib/bronto/delivery.rb', line 3

def fields
  @fields
end

#from_emailObject

Returns the value of attribute from_email.



3
4
5
# File 'lib/bronto/delivery.rb', line 3

def from_email
  @from_email
end

#from_nameObject

Returns the value of attribute from_name.



3
4
5
# File 'lib/bronto/delivery.rb', line 3

def from_name
  @from_name
end

#message_idObject

Returns the value of attribute message_id.



3
4
5
# File 'lib/bronto/delivery.rb', line 3

def message_id
  @message_id
end

#recipientsObject

Returns the value of attribute recipients.



3
4
5
# File 'lib/bronto/delivery.rb', line 3

def recipients
  @recipients
end

#reply_emailObject

Returns the value of attribute reply_email.



3
4
5
# File 'lib/bronto/delivery.rb', line 3

def reply_email
  @reply_email
end

#reply_trackingObject

Returns the value of attribute reply_tracking.



3
4
5
# File 'lib/bronto/delivery.rb', line 3

def reply_tracking
  @reply_tracking
end

#startObject

Returns the value of attribute start.



3
4
5
# File 'lib/bronto/delivery.rb', line 3

def start
  @start
end

#statusObject

Returns the value of attribute status.



3
4
5
# File 'lib/bronto/delivery.rb', line 3

def status
  @status
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/bronto/delivery.rb', line 3

def type
  @type
end

Class Method Details

.find(filter = Bronto::Filter.new, page_number = 1, include_recipients = false, include_content = false, api_key = nil) ⇒ Object

Finds contacts based on the ‘filter` (Bronto::Filter object).

  • ‘page_number` is the page of contacts to request. Bronto doesn’t specify how many contacts are returned per page,

    only that you should keep increasing the number until no more contacts are returned.
    
  • ‘fields` can be an array of field IDs or an array of Field objects.

  • ‘include_lists` determines whether to include the list IDs each contact belongs to.



11
12
13
14
15
16
17
18
19
# File 'lib/bronto/delivery.rb', line 11

def self.find(filter = Bronto::Filter.new, page_number = 1, include_recipients = false, include_content = false, api_key = nil)
  body = { filter: filter.to_hash, page_number: page_number, include_recipients: include_recipients,
      include_content: include_content }
  api_key = api_key || self.api_key

  resp = request(:read, body)

  Array.wrap(resp[:return]).map { |hash| new(hash) }
end

Instance Method Details

#add_recipient(*args) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bronto/delivery.rb', line 36

def add_recipient(*args)
  type = id = nil

  type, id = if args.is_a? Array and args.length == 2
    args
  else
    [args.first.class.to_s.split("::").last.downcase, args.first.id]
  end

  self.recipients << { id: id, type: type }
end

#to_hashObject



26
27
28
29
30
31
32
33
34
# File 'lib/bronto/delivery.rb', line 26

def to_hash
  hash = {
    id: id, start: start, message_id: message_id, from_email: from_email, from_name: from_name,
    reply_email: reply_email, recipients: recipients, fields: fields, authentication: authentication,
    reply_tracking: reply_tracking
  }
  hash.each { |k,v| hash.delete(k) if v.blank? }
  hash
end