Class: Bronto::Contact
Defined Under Namespace
Classes: Field
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#lists ⇒ Object
Returns the value of attribute lists.
Class Method Summary collapse
-
.find(filter = Bronto::Filter.new, page_number = 1, fields = nil, include_lists = false) ⇒ Object
Finds contacts based on the ‘filter` (Bronto::Filter object).
Instance Method Summary collapse
- #get_field(field) ⇒ Object
-
#initialize(options = {}) ⇒ Contact
constructor
A new instance of Contact.
- #set_field(field, value) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
3 4 5 |
# File 'lib/bronto/contact.rb', line 3 def email @email end |
#fields ⇒ Object
Returns the value of attribute fields.
3 4 5 |
# File 'lib/bronto/contact.rb', line 3 def fields @fields end |
#lists ⇒ Object
Returns the value of attribute lists.
3 4 5 |
# File 'lib/bronto/contact.rb', line 3 def lists @lists end |
Class Method Details
.find(filter = Bronto::Filter.new, page_number = 1, fields = nil, include_lists = false) ⇒ 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.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/bronto/contact.rb', line 10 def self.find(filter = Bronto::Filter.new, page_number = 1, fields = nil, include_lists = false) body = { filter: filter.to_hash, page_number: page_number } body[:fields] = Array.wrap(fields).map { |f| f.is_a?(Bronto::Field) ? f.id : f } if Array(fields).length > 0 body[:include_lists] = include_lists resp = request(:read) do soap.body = body end Array.wrap(resp[:return]).map { |hash| new(hash) } end |
Instance Method Details
#get_field(field) ⇒ Object
44 45 46 47 |
# File 'lib/bronto/contact.rb', line 44 def get_field(field) id = field.is_a?(Bronto::Field) ? field.id : field self.fields[id].try(:content) end |
#set_field(field, value) ⇒ Object
39 40 41 42 |
# File 'lib/bronto/contact.rb', line 39 def set_field(field, value) id = field.is_a?(Bronto::Field) ? field.id : field self.fields[id] = Field.new(id, value) end |
#to_hash ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/bronto/contact.rb', line 31 def to_hash if id.present? { id: id, email: email, fields: fields.values.map(&:to_hash) } else { email: email, fields: fields.values.map(&:to_hash) } end end |