File Coverage

blib/lib/WebService/Postcodeanywhere/BACS/REST.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package WebService::Postcodeanywhere::BACS::REST;
2 1     1   23787 use strict;
  1         3  
  1         67  
3             our $VERSION = '0.01';
4              
5             =head1 NAME
6              
7             WebService::Postcodeanywhere::BACS::REST - Perl API for postcodeanywhere BACS Information webservice
8              
9             =head1 SYNOPSIS
10              
11             use WebService::Postcodeanywhere::BACS::REST;
12              
13             WebService::Postcodeanywhere::BACS::REST->license_code($license);
14             WebService::Postcodeanywhere::BACS::REST->account_code($account);
15              
16             my $details = WebService::Postcodeanywhere::BACS::REST->getBACSFromSortCode($sortcode);
17              
18             =head1 DESCRIPTION
19              
20             This module provides a simple API to the postcodeanywhere
21             bank information checking webservice through it's REST API.
22              
23             You will need to register and set up your account with postcodeanywhere,
24             a free demo is available see www.postcodeanywhere.net for details
25              
26             =cut
27              
28 1     1   5 use base qw(Class::Data::Inheritable);
  1         2  
  1         1087  
29 1     1   1476 use LWP::Simple qw(get);
  1         103689  
  1         11  
30 1     1   1631 use XML::Simple;
  0            
  0            
31              
32             # Set up DataFile as inheritable class data.
33             __PACKAGE__->mk_classdata('webservice_url');
34             __PACKAGE__->mk_classdata('account_code');
35             __PACKAGE__->mk_classdata('license_code');
36              
37             my $default_url = 'http://services.postcodeanywhere.co.uk/xml.aspx';
38             __PACKAGE__->webservice_url($default_url);
39              
40             =head1 CLASS METHODS
41              
42             =head2 account_code
43              
44             Gets/Sets the account code to be used for the webservice, this is required.
45              
46             You will need to register and set up your account with postcodeanywhere
47              
48             =head2 license_code
49              
50             Gets/Sets the license code to be used for the webservice, this is required.
51              
52             You will need to register and set up your account with postcodeanywhere
53              
54             =head2 webservice_url
55              
56             Gets/Sets the webservice url to be used for requests, this is optional as the default should JustWork(TM)
57              
58             =head2 getBACSFromSortCode
59              
60             Takes a single argument of the sortcode in dd-dd-dd format.
61             Returns a hashref of the keys/values returned by the webservice.
62              
63             my $sortcode = '00-00-00';
64             my $details = WebService::Postcodeanywhere::BACS::REST->getBACSFromSortCode($sortcode);
65              
66             =cut
67              
68             sub getBACSFromSortCode {
69             my ($class,$sortcode) = @_;
70             unless ($class->account_code && $class->license_code) { die "[FATAL ERROR] getBACSFromSortCode requires license_code and account_code to be set\n"; }
71             my $argument_string = "action=bacs_fetch&account_code=${\__PACKAGE__->account_code}&license_code=${\__PACKAGE__->license_code}&sortcode=$sortcode";
72             my $response = XMLin(get(__PACKAGE__->webservice_url."?$argument_string"));
73             my $result = $response->{Data}{Item};
74             return $result;
75             }
76              
77             1;
78              
79             __END__