Class: Bronto::List
Instance Attribute Summary collapse
-
#active_count ⇒ Object
Returns the value of attribute active_count.
-
#label ⇒ Object
Returns the value of attribute label.
-
#name ⇒ Object
Returns the value of attribute name.
-
#status ⇒ Object
Returns the value of attribute status.
-
#visibility ⇒ Object
Returns the value of attribute visibility.
Attributes inherited from Base
Class Method Summary collapse
-
.clear_lists(*lists) ⇒ Object
Removes all contacts from the given lists.
Instance Method Summary collapse
- #add_to_list(*contacts) ⇒ Object
-
#add_to_list!(*contacts) ⇒ Object
Adds the given contacts to this list.
-
#initialize(options = {}) ⇒ List
constructor
A new instance of List.
-
#remove_from_list(*contacts) ⇒ Object
Removes the given contacts from this list.
- #to_hash ⇒ Object
Methods inherited from Base
api, api_key, api_key=, #create, create, destroy, #destroy, find, plural_class_name, #reload, request, #request, save, #save, session_expired, update, #update
Constructor Details
#initialize(options = {}) ⇒ List
Returns a new instance of List.
17 18 19 20 |
# File 'lib/bronto/list.rb', line 17 def initialize( = {}) super() self.active_count ||= 0 end |
Instance Attribute Details
#active_count ⇒ Object
Returns the value of attribute active_count.
3 4 5 |
# File 'lib/bronto/list.rb', line 3 def active_count @active_count end |
#label ⇒ Object
Returns the value of attribute label.
3 4 5 |
# File 'lib/bronto/list.rb', line 3 def label @label end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/bronto/list.rb', line 3 def name @name end |
#status ⇒ Object
Returns the value of attribute status.
3 4 5 |
# File 'lib/bronto/list.rb', line 3 def status @status end |
#visibility ⇒ Object
Returns the value of attribute visibility.
3 4 5 |
# File 'lib/bronto/list.rb', line 3 def visibility @visibility end |
Class Method Details
.clear_lists(*lists) ⇒ Object
Removes all contacts from the given lists.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/bronto/list.rb', line 6 def self.clear_lists(*lists) lists = lists.flatten api_key = lists.first.is_a?(String) ? lists.shift : self.api_key resp = request(:clear, {list: lists.map { |l| { id: l.id } }}) lists.each { |l| l.reload } Array.wrap(resp[:return][:results]).select { |r| r[:is_error] }.count == 0 end |
Instance Method Details
#add_to_list(*contacts) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/bronto/list.rb', line 22 def add_to_list(*contacts) begin add_to_list!(contacts) rescue Bronto::Error => e false end end |
#add_to_list!(*contacts) ⇒ Object
Adds the given contacts to this list.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bronto/list.rb', line 31 def add_to_list!(*contacts) return false if !self.id.present? contacts = contacts.flatten # The block below is evaluated in a weird scope so we need to capture self as _self for use inside the block. _self = self resp = request("add_to_list", {list: { id: _self.id }, contacts: contacts.map { |c| { id: c.id } }}) errors = Array.wrap(resp[:return][:results]).select { |r| r[:is_error] } errors.each do |error| raise Bronto::Error.new(error[:error_code], error[:error_string]) end true end |
#remove_from_list(*contacts) ⇒ Object
Removes the given contacts from this list.
49 50 51 52 53 54 55 56 |
# File 'lib/bronto/list.rb', line 49 def remove_from_list(*contacts) return false if !self.id.present? contacts = contacts.flatten resp = request("remove_from_list", {list: self.to_hash, contacts: contacts.map(&:to_hash)}) Array.wrap(resp[:return][:results]).select { |r| r[:is_error] }.count == 0 end |
#to_hash ⇒ Object
62 63 64 65 66 |
# File 'lib/bronto/list.rb', line 62 def to_hash hash = { name: name, label: label, status: status, visibility: visibility } hash[:id] = id if id.present? hash end |