| 1 | #!perl | ||
| 2 | # | ||
| 3 | # Finance::Bank::IE example code | ||
| 4 | # | ||
| 5 | use lib qw( ./lib ); | ||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | |||
| 9 | use Finance::Bank::IE; | ||
| 10 | use POSIX; | ||
| 11 | use Getopt::Long; | ||
| 12 | |||
| 13 | my %config = ( | ||
| 14 | "user" => "", | ||
| 15 | "pin" => "", | ||
| 16 | "contact" => "", | ||
| 17 | "dob" => "", | ||
| 18 | ); | ||
| 19 | |||
| 20 | my ( $from, $to, $amount, $detail ); | ||
| 21 | |||
| 22 | GetOptions( "from=s" => \$from, | ||
| 23 | "to=s" => \$to, | ||
| 24 | "amount=s" => \$amount, | ||
| 25 | "detail=s" => \$detail ) or die "bad args"; | ||
| 26 | |||
| 27 | my @accounts = Finance::Bank::IE::BankOfIreland->check_balance( \%config ); | ||
| 28 | |||
| 29 | foreach ( @accounts ) { | ||
| 30 | printf "%8s : %s %8.2f\n", | ||
| 31 | $_->{account_no}, $_->{currency}, $_->{balance}; | ||
| 32 | } | ||
| 33 | |||
| 34 | print "=" x 79 . "\n"; | ||
| 35 | |||
| 36 | my ( $source, $dest ); | ||
| 37 | if (( $from||"" ) and ( $to||"" ) and ( $amount ||"" )) { | ||
| 38 | for my $account ( @accounts ) { | ||
| 39 | if ( $account->{account_no} eq $from or $account->{nick} eq $from ) { | ||
| 40 | $source = $account; | ||
| 41 | } | ||
| 42 | if ( $account->{account_no} eq $to or $account->{nick} eq $to ) { | ||
| 43 | $dest = $account; | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | if ( !defined( $source )) { | ||
| 48 | die "$from isn't a valid source account\n"; | ||
| 49 | } | ||
| 50 | if ( !defined( $dest ) and $to !~ /^[0-9]{8}$/ ) { | ||
| 51 | die "$to isn't a valid destination account\n"; | ||
| 52 | } | ||
| 53 | |||
| 54 | Finance::Bank::IE::BankOfIreland->funds_transfer( $source->{nick}, $to, $amount ); | ||
| 55 | } | ||
| 56 | |||
| 57 | $| = 1; | ||
| 58 | if ( @accounts and defined( $detail )) { | ||
| 59 | print "Detail: $detail\n"; | ||
| 60 | for my $account ( @accounts ) { | ||
| 61 | if ( $account->{account_no} eq $detail or | ||
| 62 | $account->{nick} eq $detail ) { | ||
| 63 | $source = $account; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | if ( !defined( $source )) { | ||
| 67 | $source = $accounts[-1]; | ||
| 68 | } | ||
| 69 | print "Getting account details for " . $source->{nick} . "..."; | ||
| 70 | my @activity = Finance::Bank::IE::BankOfIreland->account_details( $source->{account_no} ); | ||
| 71 | print "done\n"; | ||
| 72 | |||
| 73 | my $date; | ||
| 74 | for my $line ( @activity ) { | ||
| 75 | my @cols = @$line; | ||
| 76 | my $date = shift @cols; | ||
| 77 | if ( $date =~ /^\d+$/ ) { | ||
| 78 | print strftime( "%Y%m%d\t", localtime( $date )); | ||
| 79 | } else { | ||
| 80 | print $date . "\t"; | ||
| 81 | } | ||
| 82 | for my $col ( 0..$#cols ) { | ||
| 83 | printf( "[%s]", $cols[$col]); | ||
| 84 | } | ||
| 85 | print "\n"; | ||
| 86 | } | ||
| 87 | } |