File Coverage

blib/lib/Business/Monzo/Balance.pm
Criterion Covered Total %
statement 22 22 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 30 30 100.0


line stmt bran cond sub pod time code
1             package Business::Monzo::Balance;
2              
3             =head1 NAME
4              
5             Business::Monzo::Balance
6              
7             =head1 DESCRIPTION
8              
9             A class for a Monzo balance, extends L<Business::Monzo::Resource>
10              
11             =cut
12              
13 10     10   79 use strict;
  10         32  
  10         360  
14 10     10   67 use warnings;
  10         27  
  10         467  
15              
16 10     10   71 use Moo;
  10         31  
  10         100  
17             extends 'Business::Monzo::Resource';
18             with 'Business::Monzo::Utils';
19             with 'Business::Monzo::Currency';
20              
21 10     10   4961 use Types::Standard qw/ :all /;
  10         37  
  10         324  
22 10     10   611893 use Business::Monzo::Merchant;
  10         30  
  10         411  
23 10     10   74 use DateTime::Format::DateParse;
  10         26  
  10         2491  
24              
25             =head1 ATTRIBUTES
26              
27             The Balance class has the following attributes (with their type).
28              
29             account_id (Str)
30             balance (Int)
31             spend_today (Int)
32             currency (Data::Currency)
33              
34             Note that when a Str is passed to ->currency this will be coerced to a
35             Data::Currency object,
36              
37             =cut
38              
39             has [ qw/ account_id / ] => (
40             is => 'ro',
41             isa => Str,
42             required => 1,
43             );
44              
45             has [ qw/ balance spend_today / ] => (
46             is => 'ro',
47             isa => Int,
48             );
49              
50             has [ qw/ url / ] => (
51             is => 'ro',
52             lazy => 1,
53             default => sub {
54             my ( $self ) = @_;
55             return $self->client->api_url . '/balance?account_id=' . $self->account_id;
56             },
57             );
58              
59             =head1 Operations on an transaction
60              
61             =head2 get
62              
63             Returns a new instance of the object with the attributes populated
64             having called the Monzo API
65              
66             $Balance = $Balance->get;
67              
68             =cut
69              
70             sub get {
71 3     3 1 50 my ( $self ) = @_;
72              
73 3         79 my $data = $self->client->api_get(
74             'balance?account_id=' . $self->account_id
75             );
76              
77             return $self->new(
78             account_id => $self->account_id,
79             client => $self->client,
80 3         468 %{ $data },
  3         112  
81             );
82             }
83              
84             =head1 SEE ALSO
85              
86             L<Business::Monzo>
87              
88             L<Business::Monzo::Resource>
89              
90             =head1 AUTHOR
91              
92             Lee Johnson - C<leejo@cpan.org>
93              
94             =head1 LICENSE
95              
96             This library is free software; you can redistribute it and/or modify it under
97             the same terms as Perl itself. If you would like to contribute documentation,
98             features, bug fixes, or anything else then please raise an issue / pull request:
99              
100             https://github.com/leejo/business-monzo
101              
102             =cut
103              
104             1;
105              
106             # vim: ts=4:sw=4:et