lib/xero_gateway/contact.rb in xero_gateway-2.5.0 vs lib/xero_gateway/contact.rb in xero_gateway-2.6.0
- old
+ new
@@ -15,11 +15,11 @@
# Any errors that occurred when the #valid? method called.
attr_reader :errors
attr_accessor :contact_id, :contact_number, :account_number, :status, :name, :first_name, :last_name, :email, :addresses, :phones, :updated_at,
:bank_account_details, :tax_number, :accounts_receivable_tax_type, :accounts_payable_tax_type, :is_customer, :is_supplier,
- :default_currency, :contact_groups
+ :default_currency, :contact_groups, :contact_persons
def initialize(params = {})
@errors ||= []
@@ -77,10 +77,15 @@
# })
def add_phone(phone_params = {})
self.phones << Phone.new(phone_params)
end
+ def add_contact_person(contact_person_params = {})
+ self.contact_persons ||= []
+ self.contact_persons << ContactPerson.new(contact_person_params)
+ end
+
# Validate the Contact record according to what will be valid by the gateway.
#
# Usage:
# contact.valid? # Returns true/false
#
@@ -158,10 +163,13 @@
addresses.each { |address| address.to_xml(b) }
} unless addresses.nil?
b.Phones {
phones.each { |phone| phone.to_xml(b) }
} if self.phones.any?
+ b.ContactPersons {
+ contact_persons.each { |contact_person| contact_person.to_xml(b) }
+ } unless contact_persons.nil?
}
end
# Take a Contact element and convert it into an Contact object
def self.from_xml(contact_element, gateway = nil)
@@ -185,9 +193,10 @@
when "ContactGroups" then contact.contact_groups = element.text
when "IsCustomer" then contact.is_customer = (element.text == "true")
when "IsSupplier" then contact.is_supplier = (element.text == "true")
when "DefaultCurrency" then contact.default_currency = element.text
when "UpdatedDateUTC" then contact.updated_at = parse_date_time(element.text)
+ when "ContactPersons" then element.children.each { |contact_person_element| contact.contact_persons ||= []; contact.contact_persons << ContactPerson.from_xml(contact_person_element) }
end
end
contact
end