| 1 | package Finance::Bank::Bankwest::Session; | ||||||||||||||||||||||
| 2 | # ABSTRACT: operate on an established Bankwest Online Banking session | ||||||||||||||||||||||
| 3 | 5 | $Finance::Bank::Bankwest::Session::VERSION = '1.2.8'; | |||||||||||||||||||||
| 4 | |||||||||||||||||||||||
| 5 | ## no critic (RequireUseStrict, RequireUseWarnings, RequireEndWithOne) | ||||||||||||||||||||||
| 6 | 6 | ▶ | use MooseX::Declare; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | 6 | ▶ | class Finance::Bank::Bankwest::Session { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=2 SCAR=7.5
| |||||||||||||||||||||||
| 8 | |||||||||||||||||||||||
| 9 | 6 | ▶ | use Finance::Bank::Bankwest::Parsers (); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 10 | 6 | ▶ | use MooseX::StrictConstructor; # no exports | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | 6 | ▶ | use MooseX::Types; # for "class_type" | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 12 | 6 | ▶ | use TryCatch; # for "try" and "catch" | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | # Allow instantiation via ->new($mech). | ||||||||||||||||||||||
| 15 | 6 | class_type 'WWW::Mechanize'; | |||||||||||||||||||||
| 16 | 6 | with 'MooseX::OneArgNew' => { | |||||||||||||||||||||
| 17 | type => 'WWW::Mechanize', | ||||||||||||||||||||||
| 18 | init_arg => 'mech', | ||||||||||||||||||||||
| 19 | }; | ||||||||||||||||||||||
| 20 | |||||||||||||||||||||||
| 21 | |||||||||||||||||||||||
| 22 | 6 | has 'mech' => ( | |||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||
| 24 | isa => 'WWW::Mechanize', | ||||||||||||||||||||||
| 25 | required => 1, | ||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||
| 27 | |||||||||||||||||||||||
| 28 | |||||||||||||||||||||||
| 29 | 6 | for ( | |||||||||||||||||||||
| 30 | [ accounts => 'AccountInformation/AI/Balances' ], | ||||||||||||||||||||||
| 31 | [ transactions => 'AccountInformation/TS/TransactionSearch' ], | ||||||||||||||||||||||
| 32 | [ logout => 'Logout' ], | ||||||||||||||||||||||
| 33 | 0 | ▶ | ) { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
__ANON__: not called CC=1 SCAR=0.4
Subroutine
accounts: called CC=1 SCAR=0.4
| |||||||||||||||||||||||
| 34 | 0 | my ($attr, $uri_fragment) = @$_; | |||||||||||||||||||||
| 35 | 18 | my $uri = sprintf( | |||||||||||||||||||||
| 36 | 'https://ibs.bankwest.com.au/CMWeb/%s.aspx', | ||||||||||||||||||||||
| 37 | $uri_fragment, | ||||||||||||||||||||||
| 38 | 6 | ); | |||||||||||||||||||||
| 39 | 18 | has "${attr}_uri" => ( | |||||||||||||||||||||
| 40 | is => 'ro', | ||||||||||||||||||||||
| 41 | 0 | ▶ | isa => 'Str', | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
__ANON__: not called CC=4 SCAR=18.1
Subroutine
transactions: called CC=4 SCAR=18.1
| |||||||||||||||||||||||
| 42 | default => $uri, | ||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||
| 45 | 0 | ▶ | |||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.8
| |||||||||||||||||||||||
| 46 | 0 | ||||||||||||||||||||||
| 47 | method accounts { | ||||||||||||||||||||||
| 48 | return Finance::Bank::Bankwest::Parsers->handle( | ||||||||||||||||||||||
| 49 | $self->mech->get($self->accounts_uri), | ||||||||||||||||||||||
| 50 | 'Accounts', | ||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||
| 53 | 0 | ▶ | |||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.4
Branch: 4 branches
| |||||||||||||||||||||||
| 54 | |||||||||||||||||||||||
| 55 | method transactions( | ||||||||||||||||||||||
| 56 | Str :$account, | ||||||||||||||||||||||
| 57 | 0 | ▶ | Str :$from_date, | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 58 | Maybe[Str] :$to_date? | ||||||||||||||||||||||
| 59 | ) { | ||||||||||||||||||||||
| 60 | # Several hidden form fields (__EVENTTARGET, __EVENTVALIDATION, | ||||||||||||||||||||||
| 61 | # __VIEWSTATE, __VS) need to be submitted with the request, so | ||||||||||||||||||||||
| 62 | # GET the page first. | ||||||||||||||||||||||
| 63 | try { | ||||||||||||||||||||||
| 64 | Finance::Bank::Bankwest::Parsers->handle( | ||||||||||||||||||||||
| 65 | $self->mech->get($self->transactions_uri), | ||||||||||||||||||||||
| 66 | 'TransactionSearch', | ||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||
| 69 | catch ( | ||||||||||||||||||||||
| 70 | Finance::Bank::Bankwest::Error::ExportFailed::UnknownReason $e | ||||||||||||||||||||||
| 71 | ) { | ||||||||||||||||||||||
| 72 | # This is expected, so ignore the exception. | ||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||
| 74 | |||||||||||||||||||||||
| 75 | $self->mech->submit_form( | ||||||||||||||||||||||
| 76 | 0 | form_id => 'aspnetForm', | |||||||||||||||||||||
| 77 | fields => { | ||||||||||||||||||||||
| 78 | '__EVENTTARGET' | ||||||||||||||||||||||
| 79 | => '_ctl0:ContentButtonsLeft:btnExport', | ||||||||||||||||||||||
| 80 | 6 | '_ctl0:ContentButtonsLeft:txtSelectedList' | |||||||||||||||||||||
| 81 | => '3~4~5~6~7', | ||||||||||||||||||||||
| 82 | '_ctl0:ContentMain:ddlAccount' | ||||||||||||||||||||||
| 83 | 0 | ▶ | => $account, | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
__ANON__: not called CC=1 SCAR=0.6
Subroutine
logout: called CC=1 SCAR=0.6
| |||||||||||||||||||||||
| 84 | 0 | '_ctl0:ContentMain:dpFromDate:txtDate' | |||||||||||||||||||||
| 85 | => $from_date, | ||||||||||||||||||||||
| 86 | '_ctl0:ContentMain:dpToDate:txtDate' | ||||||||||||||||||||||
| 87 | => (defined $to_date ? $to_date : ''), | ||||||||||||||||||||||
| 88 | 6 | }, | |||||||||||||||||||||
| 89 | 6 | ▶ | ); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 90 | |||||||||||||||||||||||
| 91 | # Assume that a CSV file has been returned. Problems with the | ||||||||||||||||||||||
| 92 | # supplied parameters would cause the form to be presented | ||||||||||||||||||||||
| 93 | # again. If nothing else, maybe a session problem? | ||||||||||||||||||||||
| 94 | return Finance::Bank::Bankwest::Parsers->handle( | ||||||||||||||||||||||
| 95 | $self->mech->res, | ||||||||||||||||||||||
| 96 | qw{ TransactionExport TransactionSearch }, | ||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||
| 99 | |||||||||||||||||||||||
| 100 | |||||||||||||||||||||||
| 101 | method logout { | ||||||||||||||||||||||
| 102 | Finance::Bank::Bankwest::Parsers->handle( | ||||||||||||||||||||||
| 103 | $self->mech->get($self->logout_uri), | ||||||||||||||||||||||
| 104 | 'Logout', | ||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||
| 108 | |||||||||||||||||||||||
| 109 | __END__ | ||||||||||||||||||||||