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=, connection_cache, #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



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bronto/delivery.rb', line 45

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
35
36
37
38
39
40
41
42
43
# File 'lib/bronto/delivery.rb', line 26

def to_hash
  start_val = if start.is_a?(String)
    start
  elsif start.respond_to?(:strftime)
    start.strftime("%Y-%m-%dT%H:%M:%S.%6N%:z")
  else
    start
  end

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