Class: Etapper::Account

Inherits:
EtapAbstract show all
Defined in:
lib/etapper/classes/account.rb

Constant Summary collapse

DONOR_RECOGNITION_TYPES =
[
:donor_name,
:do_not_recognize,
:anonymous,
:recognition_name
]
ACCOUNT_ROLE_TYPES =
[
:donor,
:tribute,
:user
]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from EtapAbstract

#==, #base, cname, etap_read_only, #initialize, #method_missing, #new?, #save

Constructor Details

This class inherits a constructor from Etapper::EtapAbstract

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Etapper::EtapAbstract

Class Method Details

.find(query) ⇒ Object

Returns an Account object retrieved from eTapestry using the supplied parameter. The exact method used varies by the query parameter type:

  • INTEGER: getAccountById()

  • ACCOUNT REF (dot-separated number string): getAccount()

  • E-MAIL ADDRESS: getDuplicateAccount

  • HASH: getAccountRef() with defined value, then getAccount() (only the first hash value is used)



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/etapper/classes/account.rb', line 33

def self.find(query)
  case query
  when Integer
    a = Etapper::client.getAccountById(query)
  when /\d+\.\d+\.\d+/  # "4310.0.2276679"
    a = Etapper::client.getAccount(query)
  when /\S+@\S+\.\S+/  # very simplistic e-mail checking but suffices for this purpose
    s = DuplicateAccountSearch.new(:email => query)
    a = Etapper::client.getDuplicateAccount(s.base)
  when Hash
    v = DefinedValue.new(query)
    a = Etapper::client.getAccountByUniqueDefinedValue(v.base)
  end
  Account.new(a) if a
end

Instance Method Details

#accountDefinedValuesObject



77
78
79
80
# File 'lib/etapper/classes/account.rb', line 77

def accountDefinedValues
  @base.accountDefinedValues ||= Etapper::API::ArrayOfDefinedValue.new
  @accountDefinedValues ||= Etapper::DefinedValueHash.new(base.accountDefinedValues)
end

#accountRoleTypeObject



94
95
96
# File 'lib/etapper/classes/account.rb', line 94

def accountRoleType
  ACCOUNT_ROLE_TYPES[@base.accountRoleType]
end

#accountRoleType=(val) ⇒ Object



98
99
100
# File 'lib/etapper/classes/account.rb', line 98

def accountRoleType=(val)
  @base.accountRoleType = ACCOUNT_ROLE_TYPES.index(val)
end

#contactsObject

Retrieves all Contact journal entries for the account.



108
109
110
# File 'lib/etapper/classes/account.rb', line 108

def contacts
  @contacts ||= Contact.findByAccount(self)
end

#definedValuesObject



82
83
84
# File 'lib/etapper/classes/account.rb', line 82

def definedValues
  @definedValues = accountDefinedValues.merge(personaDefinedValues).freeze
end

#donorRecognitionTypeObject



86
87
88
# File 'lib/etapper/classes/account.rb', line 86

def donorRecognitionType
  DONOR_RECOGNITION_TYPES[@base.donorRecognitionType]
end

#donorRecognitionType=(val) ⇒ Object



90
91
92
# File 'lib/etapper/classes/account.rb', line 90

def donorRecognitionType=(val)
  @base.donorRecognitionType = DONOR_RECOGNITION_TYPES.index(val)
end

#faxObject



64
65
66
# File 'lib/etapper/classes/account.rb', line 64

def fax
  phones[:fax]
end

#fax=(val) ⇒ Object



68
69
70
# File 'lib/etapper/classes/account.rb', line 68

def fax=(val)
  phones[:fax] = val
end

#giftsObject

Retrieves all Gift journal entries for the account.



103
104
105
# File 'lib/etapper/classes/account.rb', line 103

def gifts
  @gifts ||= Gift.findByAccount(self)
end

#idObject

Return the eTapestry account ID



113
114
115
# File 'lib/etapper/classes/account.rb', line 113

def id
  base.id
end

#personaDefinedValuesObject



72
73
74
75
# File 'lib/etapper/classes/account.rb', line 72

def personaDefinedValues
  @base.personaDefinedValues ||= Etapper::API::ArrayOfDefinedValue.new
  @personaDefinedValues ||= Etapper::DefinedValueHash.new(base.personaDefinedValues)
end

#phoneObject



56
57
58
# File 'lib/etapper/classes/account.rb', line 56

def phone
  phones[:voice] || phones[:business] || phones[:mobile] || phones[:home]
end

#phone=(val) ⇒ Object



60
61
62
# File 'lib/etapper/classes/account.rb', line 60

def phone=(val)
  phones[:voice] = val
end

#phonesObject



50
51
52
53
# File 'lib/etapper/classes/account.rb', line 50

def phones
  @base.phones ||= Etapper::API::ArrayOfPhone.new
  @phones ||= Etapper::PhoneHash.new(base.phones)
end