class XeroGateway::ContactGroup

Attributes

contact_group_id[RW]

All accessible fields

contacts[W]
contacts_downloaded[RW]

Boolean representing whether the accounts list has been loaded.

gateway[RW]

Xero::Gateway associated with this invoice.

name[RW]

All accessible fields

status[RW]

All accessible fields

Public Class Methods

from_xml(contact_group_element, gateway, options = {}) click to toggle source
# File lib/xero_gateway/contact_group.rb, line 71
def self.from_xml(contact_group_element, gateway, options = {})
  contact_group = ContactGroup.new(gateway: gateway, contacts_downloaded: options[: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
new(params = {}) click to toggle source
# 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

Public Instance Methods

contact_ids() click to toggle source

Returns the array of ContactIDs. If the contact_ids array has been assigned, will return that array. Otherwise, returns any loaded ContactIDs

# 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) click to toggle source

Assign ContactIDs to the group for updating.

# File lib/xero_gateway/contact_group.rb, line 49
def contact_ids=(contact_ids)
  @contact_ids = contact_ids
end
contacts() click to toggle source

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.

# 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
to_xml(b = Builder::XmlMarkup.new) click to toggle source
# 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