Class: Amex::CardAccount

Inherits:
Object
  • Object
show all
Defined in:
lib/amex/card_account.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Amex::CardAccount

Generates a CardAccount object from XML properties grabbed by the client

Parameters:

  • options (Hash)

    A Hash containing XML properties pulled directly from the API XML



17
18
19
20
21
22
23
# File 'lib/amex/card_account.rb', line 17

def initialize(options)
  options.each do |key, value|
    method = key.to_s.underscore + "="
    send(key.to_s.underscore + "=", value) if respond_to? method.to_sym
  end
  @loyalty_programmes = []
end

Instance Attribute Details

#cancelledObject

Returns the value of attribute cancelled.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def cancelled
  @cancelled
end

#card_artObject

Returns the value of attribute card_art.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def card_art
  @card_art
end

#card_indexObject

Returns the value of attribute card_index.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def card_index
  @card_index
end

#card_member_nameObject

Returns the value of attribute card_member_name.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def card_member_name
  @card_member_name
end

#card_number_suffixObject

Returns the value of attribute card_number_suffix.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def card_number_suffix
  @card_number_suffix
end

#card_productObject

Returns the value of attribute card_product.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def card_product
  @card_product
end

#clientObject

Returns the value of attribute client.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def client
  @client
end

#is_basicObject

Returns the value of attribute is_basic.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def is_basic
  @is_basic
end

#is_centurionObject

Returns the value of attribute is_centurion.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def is_centurion
  @is_centurion
end

#is_platinumObject

Returns the value of attribute is_platinum.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def is_platinum
  @is_platinum
end

#is_premiumObject

Returns the value of attribute is_premium.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def is_premium
  @is_premium
end

#lending_typeObject

Returns the value of attribute lending_type.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def lending_type
  @lending_type
end

#loyalty_indicatorObject

Returns the value of attribute loyalty_indicator.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def loyalty_indicator
  @loyalty_indicator
end

#loyalty_programmesObject

Returns the value of attribute loyalty_programmes.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def loyalty_programmes
  @loyalty_programmes
end

#marketObject

Returns the value of attribute market.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def market
  @market
end

#past_dueObject

Returns the value of attribute past_due.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def past_due
  @past_due
end

#payment_creditsObject

Returns the value of attribute payment_credits.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def payment_credits
  @payment_credits
end

#payment_dueObject

Returns the value of attribute payment_due.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def payment_due
  @payment_due
end

#payment_due_dateDateTime

Returns the date that the next payment on the card is due

Returns:

  • (DateTime)

    the date when the next payment against this account is due



99
100
101
# File 'lib/amex/card_account.rb', line 99

def payment_due_date
  @payment_due_date
end

#recent_chargesObject

Returns the value of attribute recent_charges.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def recent_charges
  @recent_charges
end

#stmt_balanceObject

Returns the value of attribute stmt_balance.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def stmt_balance
  @stmt_balance
end

#total_balanceObject

Returns the value of attribute total_balance.



3
4
5
# File 'lib/amex/card_account.rb', line 3

def total_balance
  @total_balance
end

Instance Method Details

#cancelled?Boolean

Returns whether the card account is cancelled

Returns:

  • (Boolean)

    the cancellation status of this card, either true or false



91
92
93
# File 'lib/amex/card_account.rb', line 91

def cancelled?
  @cancelled
end

#due?Boolean

Returns whether this account has a due payment (i.e. whether you need to pay American Express anything) (see #overdue?)

Returns:

  • (Boolean)

    true if the account has a due payment, false otherwise



150
151
152
153
# File 'lib/amex/card_account.rb', line 150

def due?
  return true if @payment_due.to_f > 0
  false
end

#is_charge_card?Boolean

Returns whether this account is a charge card

Returns:

  • (Boolean)

    true if the account is a charge card, false otherwise



131
132
133
134
# File 'lib/amex/card_account.rb', line 131

def is_charge_card?
  return true if @lending_type == "Charge"
  false
end

#is_credit_card?Boolean

Returns whether this account is a credit card

Returns:

  • (Boolean)

    true if the account is a credit card, false otherwise



122
123
124
125
# File 'lib/amex/card_account.rb', line 122

def is_credit_card?
  return true if @lending_type == "Credit"
  false
end

#loyalty_balancesHash{String => String}

Returns a hash of loyalty scheme balances for this account

Returns:

  • (Hash{String => String})

    the loyalty balances for this account, with the key being the name of the loyalty scheme, and the value its balance



171
172
173
174
175
176
177
# File 'lib/amex/card_account.rb', line 171

def loyalty_balances
  result = {}
  @loyalty_programmes.each do |programme|
    result[programme.name] = programme.balance
  end
  result
end

#loyalty_enabled?Boolean

Returns whether this account has any kind of loyalty scheme attached

Returns:

  • (Boolean)

    true if the account has a loyalty scheme, false otherwise



160
161
162
# File 'lib/amex/card_account.rb', line 160

def loyalty_enabled?
  @loyalty_indicator
end

#overdue?Boolean

Returns whether payment on this account is overdue

Returns:

  • (Boolean)

    true if the account is overdue, false otherwise



140
141
142
143
# File 'lib/amex/card_account.rb', line 140

def overdue?
  return true if @past_due
  false
end

#productString

Returns the name of the card product that your card conforms to (e.g. “American Express Preferred Rewards Gold”)

Returns:

  • (String)

    the name of the card product that your card conforms to



83
84
85
# File 'lib/amex/card_account.rb', line 83

def product
  @card_product
end

#statement_balanceFloat

Returns the balance of the most recent statement

Returns:

  • (Float)

    the balance of the most recent statement



74
75
76
# File 'lib/amex/card_account.rb', line 74

def statement_balance
  @stmt_balance
end

#transactions(billing_period = 0) ⇒ Array<Amex::Transaction>

Note:

This can fetch either a single billing period or a range of billing periods, e.g:

> account.transaction(0)

fetches transactions since the last statement (default)

> account.transaction(0..5)

fetches transactions between now and five statements ago

Fetches transactions on an American Express card

Parameters:

  • billing_period (Fixnum, Range) (defaults to: 0)

    The billing period(s) to fetch transactions for, as either a single billing period (e.g. 0 or 1) or a range of periods to fetch (e.g. 0..3)

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/amex/card_account.rb', line 38

def transactions(billing_period=0)
  result = []

  # Build an array of billing periods we need to fetch - this is almost
  # certainly woefully inefficient code.
  billing_periods = []
  if billing_period.class == Fixnum
    billing_periods << billing_period
  elsif billing_period.class == Range
    billing_period.each { |n| billing_periods << n }
  else
    raise "The passed in billing period option must be a number or a range"
  end

  billing_periods.each do |n|
    options = { :body => {
      "PayLoadText" => @client.statement_request_xml(@card_index, n)
    }}
    response = @client.class.post(
      '/myca/intl/moblclient/emea/ws.do?Face=en_GB', options
    )
    xml = Nokogiri::XML(response.body)
    xml = xml.css("XMLResponse")

    xml.css('Transaction').each do |transaction|
      result << Amex::Transaction.new(transaction)
    end
  end

  result
end

#type:basic, ...

Returns the type of account this card conforms to (generally not useful,

probably largely used internally by American Express

Returns:

  • (:basic, :platinum, :centurion, :premium, :unknown)

    a symbol representing the ‘type’ of your card



110
111
112
113
114
115
116
# File 'lib/amex/card_account.rb', line 110

def type
  return :basic if @is_basic
  return :platinum if @is_platinum
  return :centurion if @is_centurion
  return :premium if @is_premium
  :unknown
end