File Coverage

blib/lib/Finance/Wesabe.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Finance::Wesabe;
2              
3 1     1   1186 use Moose;
  0            
  0            
4              
5             use URI;
6             use LWP::UserAgent;
7             use XML::Simple ();
8              
9             use Finance::Wesabe::Account;
10             use Finance::Wesabe::Profile;
11              
12             our $VERSION = '0.02';
13             our $API_VERSION = '1.0.0';
14              
15             my $agent_name = __PACKAGE__ . "/$VERSION Wesabe-API/$API_VERSION";
16              
17             =head1 NAME
18              
19             Finance::Wesabe - Access your wesabe.com account information
20              
21             =head1 SYNOPSIS
22              
23             my $w = Finance::Wesabe->new( {
24             username => $u,
25             password => $p,
26             } );
27            
28             printf "%s: %s\n", $_->name, $_->pretty_balance for $w->accounts;
29              
30             =head1 DESCRIPTION
31              
32             Wesabe is part money management tool, part community.
33              
34             This module provides access to your basic account info via the wesabe
35             API. It currently supports a subset of the 1.0.0 API.
36              
37             =head1 WESABE.COM SHUTDOWN / OPEN SOURCE "MESABE"
38              
39             On July 31st, 2010, the wesabe.com service shut its doors. Subsequently,
40             parts of the application have been released as open source code on the wesabe
41             github account (L<http://www.github.com/wesabe>).
42              
43             Of particular interest are the instructions to get a local copy of the wesabe
44             web app running locally (known as "mesabe"): L<http://github.com/wesabe/mesabe/wiki>.
45              
46             At the time of this writing, it is unclear if this module will interface
47             with a locally run version of the app, however, the base URL is configurable
48             as follows:
49              
50             my $w = Finance::Wesabe->new( {
51             url => 'http://localhost:3000/', # change as required
52             username => $u,
53             password => $p,
54             } );
55            
56              
57             =head1 ACCESSORS
58              
59             =over 4
60              
61             =item * agent - A useragent for all requests
62              
63             =item * url - Base URI for all requests
64              
65             =item * username - your wesabe.com username
66              
67             =item * password - your wesabe.com password
68              
69             =back
70              
71             =cut
72              
73             has 'agent' =>
74             ( is => 'ro', isa => 'Object', default => sub { LWP::UserAgent->new( agent => $agent_name ) } );
75              
76             has 'url' =>
77             ( is => 'ro', isa => 'URI',
78             default => sub { URI->new( 'https://www.wesabe.com/' ) } );
79              
80             has 'username' => ( is => 'ro', isa => 'Str' );
81              
82             has 'password' => ( is => 'ro', isa => 'Str' );
83              
84             =head1 METHODS
85              
86             =head2 accounts( )
87              
88             Returns L<Finance::Wesabe::Account> objects for each of your accounts.
89              
90             =cut
91              
92             sub accounts {
93             my $self = shift;
94             my $xml = $self->_get_req( '/accounts.xml' );
95             return map { Finance::Wesabe::Account->new( content => $_, parent => $self ) } @{ $xml->{ account } };
96             }
97              
98             =head2 account( $index )
99              
100             Returns a L<Finance::Wesabe::Account> object for the given <$index>.
101              
102             NB: Accounts have no specific numeric id, so C<1> means the first account,
103             and so on.
104              
105             =cut
106              
107             sub account {
108             my( $self, $id ) = @_;
109             my $xml = $self->_get_req( "/accounts/${id}.xml" );
110             return Finance::Wesabe::Account->new( content => $xml, parent => $self );
111             }
112              
113             =head2 profile( )
114              
115             Returns a L<Finance::Wesabe::Profile> with your profile information.
116              
117             =cut
118              
119             sub profile {
120             my( $self ) = @_;
121             my $xml = $self->_get_req( "/profile.xml" );
122             return Finance::Wesabe::Profile->new( content => $xml, parent => $self );
123             }
124              
125             sub _get_req {
126             my( $self, $path ) = @_;
127              
128             my $url = $self->url->clone;
129             $url->path( $path );
130              
131             my $req = HTTP::Request->new( GET => $url );
132             $req->authorization_basic( $self->username, $self->password );
133             my $response = $self->agent->request( $req );
134              
135             my $xml = XML::Simple::XMLin( $response->content, KeyAttr => [] );
136             return $xml;
137             }
138              
139             no Moose;
140              
141             __PACKAGE__->meta->make_immutable;
142              
143             =head1 SEE ALSO
144              
145             =over 4
146              
147             =item * L<http://www.wesabe.com>
148              
149             =item * L<http://github.com/wesabe/mesabe/wiki>
150              
151             =back
152              
153             =head1 AUTHOR
154              
155             Brian Cassidy E<lt>bricas@cpan.orgE<gt>
156              
157             =head1 COPYRIGHT AND LICENSE
158              
159             Copyright 2009-2010 by Brian Cassidy
160              
161             This library is free software; you can redistribute it and/or modify
162             it under the same terms as Perl itself.
163              
164             =cut
165              
166             1;