Class: Quickeebooks::Windows::Model::Customer

Inherits:
IntuitType
  • Object
show all
Includes:
ActiveModel::Validations, Model::Addressable
Defined in:
lib/quickeebooks/windows/model/customer.rb

Constant Summary collapse

DEFAULT_TYPE_OF =
'Person'
XML_COLLECTION_NODE =
'Customers'
XML_NODE =
'Customer'
REST_RESOURCE =
"customer"

Instance Method Summary collapse

Methods included from Model::Addressable

included

Methods included from Logging

#log

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/quickeebooks/windows/model/customer.rb', line 81

def active?
  active == 'true'
end

#email_address=(email_address) ⇒ Object



104
105
106
# File 'lib/quickeebooks/windows/model/customer.rb', line 104

def email_address=(email_address)
  self.email = Quickeebooks::Windows::Model::Email.new(email_address)
end

#email_address_is_validObject



121
122
123
124
125
126
127
128
# File 'lib/quickeebooks/windows/model/customer.rb', line 121

def email_address_is_valid
  if email
    address = email.address
    unless address.index('@') && address.index('.')
      errors.add(:email, "Email address must contain @ and . (dot)")
    end
  end
end

#name_cannot_contain_invalid_charactersObject



115
116
117
118
119
# File 'lib/quickeebooks/windows/model/customer.rb', line 115

def name_cannot_contain_invalid_characters
  if name.to_s.index(':')
    errors.add(:name, "Name cannot contain a colon (:)")
  end
end

#require_an_addressObject



130
131
132
133
134
# File 'lib/quickeebooks/windows/model/customer.rb', line 130

def require_an_address
  if addresses.nil? || (addresses.is_a?(Array) && addresses.empty?)
    errors.add(:addresses, "Must provide at least one address for this Customer.")
  end
end

#to_xml_ns(options = {}) ⇒ Object



100
101
102
# File 'lib/quickeebooks/windows/model/customer.rb', line 100

def to_xml_ns(options = {})
  to_xml
end

#valid_for_create?Boolean

Returns:

  • (Boolean)


92
93
94
95
96
97
98
# File 'lib/quickeebooks/windows/model/customer.rb', line 92

def valid_for_create?
  valid?
  if type_of.nil?
    errors.add(:type_of, "Missing required attribute TypeOf for Create")
  end
  errors.empty?
end

#valid_for_deletion?Boolean

To delete an account Intuit requires we provide Id and SyncToken fields

Returns:

  • (Boolean)


110
111
112
113
# File 'lib/quickeebooks/windows/model/customer.rb', line 110

def valid_for_deletion?
  return false if(id.nil? || sync_token.nil?)
  id.to_i > 0 && !sync_token.to_s.empty? && sync_token.to_i >= 0
end

#valid_for_update?Boolean

Returns:

  • (Boolean)


85
86
87
88
89
90
# File 'lib/quickeebooks/windows/model/customer.rb', line 85

def valid_for_update?
  if sync_token.nil?
    errors.add(:sync_token, "Missing required attribute SyncToken for update")
  end
  errors.empty?
end