Class: Syrup::Institutions::ZionsBank

Inherits:
InstitutionBase show all
Defined in:
lib/syrup/institutions/zions_bank.rb

Instance Attribute Summary

Attributes inherited from InstitutionBase

#password, #secret_questions, #username

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from InstitutionBase

#accounts, #find_account_by_id, inherited, #initialize, #populate_account, #populate_accounts, #populated=, #populated?, #setup, subclasses

Constructor Details

This class inherits a constructor from Syrup::Institutions::InstitutionBase

Class Method Details

.idObject



12
13
14
# File 'lib/syrup/institutions/zions_bank.rb', line 12

def id
  "zions_bank"
end

.nameObject



8
9
10
# File 'lib/syrup/institutions/zions_bank.rb', line 8

def name
  "Zions Bank"
end

Instance Method Details

#fetch_account(account_id) ⇒ Object



17
18
19
# File 'lib/syrup/institutions/zions_bank.rb', line 17

def ()
  fetch_accounts
end

#fetch_accountsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/syrup/institutions/zions_bank.rb', line 21

def fetch_accounts
  ensure_authenticated

  # List accounts
  page = agent.get('https://banking.zionsbank.com/ibuir/displayAccountBalance.htm')
  json = MultiJson.load(page.body)

  accounts = []
  json['accountBalance']['depositAccountList'].each do ||
     = Account.new(:id => ['accountId'], :institution => self)
    .name = unescape_html(['name'])
    . = ['number']
    .current_balance = parse_currency(['currentAmt'])
    .available_balance = parse_currency(['availableAmt'])
    .type = :deposit
    
    accounts << 
  end
  json['accountBalance']['creditAccountList'].each do ||
     = Account.new(:id => ['accountId'], :institution => self)
    .name = unescape_html(['name'])
    . = ['number']
    .current_balance = parse_currency(['balanceDueAmt'])
    .type = :credit
    
    accounts << 
  end

  accounts
end

#fetch_transactions(account_id, starting_at, ending_at) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/syrup/institutions/zions_bank.rb', line 52

def fetch_transactions(, starting_at, ending_at)
  ensure_authenticated
  
  transactions = []
  
  post_vars = { "actAcct" => , "dayRange.searchType" => "dates", "dayRange.startDate" => starting_at.strftime('%m/%d/%Y'), "dayRange.endDate" => ending_at.strftime('%m/%d/%Y'), "submit_view.x" => 11, "submit_view.y" => 11, "submit_view" => "view" }
  
  page = agent.post("https://banking.zionsbank.com/zfnb/userServlet/app/bank/user/register_view_main?reSort=false&actAcct=#{}", post_vars)
  
  # Get all the transactions
  page.search('tr').each do |row_element|
    # Look for the account information first
     = ()
    datapart = row_element.css('.acct')
    if datapart && datapart.inner_html.size > 0
      if match = /Prior Day Balance:\s*([^<]+)/.match(datapart.inner_html)
        .prior_day_balance = parse_currency(match[1])
      end
      if match = /Current Balance:\s*([^<]+)/.match(datapart.inner_html)
        .current_balance = parse_currency(match[1])
      end
      if match = /Available Balance:\s*([^<]+)/.match(datapart.inner_html)
        .available_balance = parse_currency(match[1])
      end
    end
  
    data = []
    datapart = row_element.css('.data')
    if datapart
      data += datapart
      datapart = row_element.css('.curr')
      data += datapart if datapart
    end
    
    datapart = row_element.css('.datagrey')
    if datapart
      data += datapart
      datapart = row_element.css('.currgrey')
      data += datapart if datapart
    end
    
    if data.size == 7
      data.map! {|cell| cell.inner_html.strip.gsub(/[^ -~]/, '') }
      
      transaction = Transaction.new

      transaction.posted_at = Date.strptime(data[0], '%m/%d/%Y')
      transaction.payee = unescape_html(data[2])
      transaction.status = data[3].include?("Posted") ? :posted : :pending
      unless data[4].empty?
        transaction.amount = -parse_currency(data[4])
      end
      unless data[5].empty?
        transaction.amount = parse_currency(data[5])
      end
      
      transactions << transaction
    end
  end
  
  transactions
end