Finance-Bank-Halifax-Sharedealing
view release on metacpan or search on metacpan
lib/Finance/Bank/Halifax/Sharedealing.pm view on Meta::CPAN
use strict;
use warnings;
use Carp;
use HTML::TokeParser;
use WWW::Mechanize;
=head1 NAME
Finance::Bank::Halifax::Sharedealing - access Halifax Sharedealing accounts from Perl.
=head1 VERSION
Version 0.03
=cut
our $VERSION = '0.03';
=head1 SYNOPSIS
use Finance::Bank::Halifax::Sharedealing;
# Set up the login details
my $sd = Finance::Bank::Halifax::Sharedealing->new(
username => 'myusername',
password => 'mysecretpassword',
security_mother_first_name => 'Alice',
security_father_first_name => 'Bob',
security_school_name => 'Somewheretown Primary School',
security_birthplace => 'Somewheretown',
);
$sd->log_in();
# Get the user's accounts and print a brief statement for each one.
my %accounts = $sd->get_all_accounts();
foreach my $account_id (keys(%accounts)) {
$sd->set_account($account_id);
print "Account: " . $accounts{$account_id} . "\n";
print "Available to invest: " . $sd->get_available_cash() . "\n";
my @portfolio = $sd->get_portfolio();
if (@portfolio) {
print "Share\tValuation\n";
foreach my $share (@portfolio) {
print $share->{'symbol'} . "\t";
print $share->{'valuation'} . "\n";
}
}
print "\n";
}
$sd->log_out();
=head1 DESCRIPTION
This module provides an interface to the Halifax online share dealing
service at L<https://www.halifaxsharedealing-online.co.uk/>. It requires
C<WWW::Mechanize>, C<HTML::TokeParser>, and either C<Crypt::SSLeay> or
C<IO::Socket::SSL>.
=head1 METHODS
=cut
# Global constants - these will only change if Halifax reorganise their
# share dealing site.
# URL of the login page
use constant LOGIN_PAGE => 'https://www.halifaxsharedealing-online.co.uk/_mem_bin/formslogin.asp';
# Text of the link to view your statements
use constant STATEMENTS_LINK_TEXT => 'My Statements';
# Name of the account select box on the statements page.
use constant ACCOUNT_SELECT_BOX_NAME => 'AccNavList';
# Name of the form that contains the 'Sign out' button.
use constant HEADER_FORM_NAME => 'frmHeaderButtons';
##################
# Public methods #
##################
=head2 new(username => $u, password => $p, security_mother_first_name => $m, security_father_first_name => $f, security_school_name => $s, security_birthplace => $b)
Returns a new Sharedealing object.
The required arguments are the user's login details as a list of key/value
pairs. Answers are required for all the possible security questions, as we
don't know in advance which one the site will ask us.
=cut
sub new {
my ($class, %opts) = @_;
croak 'Username not specified' if not exists $opts{username};
croak 'Password not specified' if not exists $opts{password};
croak "Security answer not specified: mother's first name"
if not exists $opts{security_mother_first_name};
croak "Security answer not specified: father's first name"
if not exists $opts{security_father_first_name};
croak 'Security answer not specified: name of first school'
if not exists $opts{security_school_name};
croak 'Security answer not specified: place/town of birth'
if not exists $opts{security_birthplace};
my $self = {
agent => new WWW::Mechanize(autocheck => 1),
username => $opts{username},
password => $opts{password},
security_mother_first_name => $opts{security_mother_first_name},
security_father_first_name => $opts{security_father_first_name},
security_school_name => $opts{security_school_name},
security_birthplace => $opts{security_birthplace},
_account => '',
};
( run in 2.675 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )