Class: XeroGateway::ContactGroup
- Inherits:
-
Object
- Object
- XeroGateway::ContactGroup
- Defined in:
- lib/xero_gateway/contact_group.rb
Instance Attribute Summary collapse
-
#contact_group_id ⇒ Object
All accessible fields.
-
#contacts ⇒ Object
Return the list of Contacts.
-
#contacts_downloaded ⇒ Object
Boolean representing whether the accounts list has been loaded.
-
#gateway ⇒ Object
Xero::Gateway associated with this invoice.
-
#name ⇒ Object
All accessible fields.
-
#status ⇒ Object
All accessible fields.
Class Method Summary collapse
Instance Method Summary collapse
-
#contact_ids ⇒ Object
Returns the array of ContactIDs.
-
#contact_ids=(contact_ids) ⇒ Object
Assign ContactIDs to the group for updating.
-
#initialize(params = {}) ⇒ ContactGroup
constructor
A new instance of ContactGroup.
- #to_xml(b = Builder::XmlMarkup.new) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ ContactGroup
Returns a new instance of ContactGroup.
14 15 16 17 18 19 20 |
# File 'lib/xero_gateway/contact_group.rb', line 14 def initialize(params = {}) @contacts = [] params.each do |k,v| self.send("#{k}=", v) end @contacts_downloaded = (params.delete(:contacts_downloaded) == true) end |
Instance Attribute Details
#contact_group_id ⇒ Object
All accessible fields
8 9 10 |
# File 'lib/xero_gateway/contact_group.rb', line 8 def contact_group_id @contact_group_id end |
#contacts ⇒ Object
Return the list of Contacts. Will load the contacts if the group hasn’t loaded the contacts yet (i.e. returned by a index call)
Loaded contacts will only have Name and ContactId set.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/xero_gateway/contact_group.rb', line 26 def contacts if !@contacts_downloaded && contact_group_id @contacts_downloaded = true # Load the contact list. @contacts = gateway.get_contact_group_by_id(contact_group_id).contact_group.contacts || [] end @contacts end |
#contacts_downloaded ⇒ Object
Boolean representing whether the accounts list has been loaded.
12 13 14 |
# File 'lib/xero_gateway/contact_group.rb', line 12 def contacts_downloaded @contacts_downloaded end |
#gateway ⇒ Object
Xero::Gateway associated with this invoice.
5 6 7 |
# File 'lib/xero_gateway/contact_group.rb', line 5 def gateway @gateway end |
#name ⇒ Object
All accessible fields
8 9 10 |
# File 'lib/xero_gateway/contact_group.rb', line 8 def name @name end |
#status ⇒ Object
All accessible fields
8 9 10 |
# File 'lib/xero_gateway/contact_group.rb', line 8 def status @status end |
Class Method Details
.from_xml(contact_group_element, gateway, options = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/xero_gateway/contact_group.rb', line 71 def self.from_xml(contact_group_element, gateway, = {}) contact_group = ContactGroup.new(gateway: gateway, contacts_downloaded: [:contacts_downloaded]) contact_group_element.children.each do |element| case(element.name) when "ContactGroupID" then contact_group.contact_group_id = element.text when "Name" then contact_group.name = element.text when "Status" then contact_group.status = element.text when "Contacts" then contact_group.contacts_downloaded = true element.children.each do |contact_child| contact_group.contacts << Contact.from_xml(contact_child, gateway) end end end contact_group end |
Instance Method Details
#contact_ids ⇒ Object
Returns the array of ContactIDs. If the contact_ids array has been assigned, will return that array. Otherwise, returns any loaded ContactIDs
40 41 42 43 44 45 46 |
# File 'lib/xero_gateway/contact_group.rb', line 40 def contact_ids if defined?(@contact_ids) @contact_ids else contacts.map(&:contact_id) end end |
#contact_ids=(contact_ids) ⇒ Object
Assign ContactIDs to the group for updating.
49 50 51 |
# File 'lib/xero_gateway/contact_group.rb', line 49 def contact_ids=(contact_ids) @contact_ids = contact_ids end |
#to_xml(b = Builder::XmlMarkup.new) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/xero_gateway/contact_group.rb', line 53 def to_xml(b = Builder::XmlMarkup.new) b.ContactGroup { b.ContactGroupID contact_group_id unless contact_group_id.nil? b.Name self.name b.Status self.status if @contacts_downloaded || @contact_ids b.Contacts { self.contact_ids.each do |contact_id| b.Contact { b.ContactID contact_id } end } end } end |