package Finance::Bank::CIBC; use strict; use version; our $VERSION = qv('0.01'); use base 'Finance::Bank::Generic'; use Regexp::Common qw/whitespace/; # return: hashref # the hashref data is stored in the config object attribute sub _config { return { LOGIN_FORM_URL => 'https://www.cibconline.cibc.com/olbtxn/authentication/PreSignOn.cibc?locale=en_CA', ACCOUNTS_URL => 'https://www.cibconline.cibc.com/olbtxn/accounts/MyAccounts.cibc', FIELD_CARD_NUMBER => 'newCardNumber', FIELD_PASSWORD => 'pswPassword', TABLE_HEADERS => { "summary" => [ "Deposit Accounts", "Transit / Account Number", "Available Funds", "Balance" ], "details" => [ "Date", "Transactions", "Debit", "Credit" ], }, DETAIL_FORM_ACCOUNT_FIELD => 'selectedAccount', DETAIL_FORM_ACTION => '/olbtxn/accounts/AccountHistoryDispatcher.cibc', }; } sub bank_name { return 'cibc'; } sub _parse_summary_row { my ($self, $row) = @_; # first column contains name and account id # account id is in the link my ($account_id, $name) = $row->[0] =~ m/"javascript:submitAccountDetail\('.+?','(.+?)'\)">(.+?)<\/a>/; $name =~ s/[^\w]//g; # name must be alphanumeric # second column is transit / account number my $number = $row->[1]; $number =~ s/$RE{ws}{crop}//g; $number =~ s/[^\w\/\s]//g; # third column is Available Balance, remove anything that's not a dollar amount my $available = $row->[2]; $available =~ s/[^\$\-\.\d]//g; # fourth column is Posted Balance, remove anything that's not a dollar amount my $posted = $row->[3]; $posted =~ s/[^\$\-\.\d]//g; unless ( defined $number && defined $available && defined $posted ) { return undef; } return { bank_name => $self->bank_name(), bank_id => $self->{bank_id}, number => $number, account_id => $account_id, name => $name, designation => $name, available => $available, posted => $posted, }; } sub _parse_details_row { my ($self, $row) = @_; my $date = $row->[0]; $date =~ s/[^\w\s,]//g; my $info = $row->[1]; $info =~ s/$RE{ws}{crop}//g; my $debit = $row->[2]; $debit =~ s/[^\$\.\d]//g; my $credit = $row->[3]; $credit =~ s/[^\$\.\d]//g; unless ( defined $date && defined $info && (defined $debit or defined $credit) ) { return undef; } return { date => $date, info => $info, debit => $debit, credit => $credit, }; } 1; __END__ =head1 NAME Finance::Bank::CIBC =head1 SYNOPSIS my $bank = Finance::Bank::CIBC->new({card_number=>'123456789', password=>'password'}); my $accounts = $bank->accounts(); foreach my $account ( @$accounts ) { my $details = $bank->details($account->{name}); } =head1 AUTHOR Ilia Lobsanov