Monzo/Account.pm

filter: Statementstmt 100% 60 / 60 Branchbran 83.3% 5 / 6 Conditioncond 57.1% 4 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 16 / 16 Podpod 85.7% 6 / 7 totaltotal 92.0% 92 / 100 CC 8 SCAR 6.8
CC
8
Cov
95%
add_feed_item
4.0
webhooks
3.0
__ANON__
2.0
CRAP 2.0
« Monzo/Utils.pm ↑ Summary Monzo/Currency.pm »
1 package Business::Monzo::Account;
2  
3 =head1 NAME
4  
5 Business::Monzo::Account
6  
7 =head1 DESCRIPTION
8  
9 A class for a Monzo account, extends L<Business::Monzo::Resource>
10  
11 =cut
12  
13 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 11 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 11 extends 'Business::Monzo::Resource';
18 11 with 'Business::Monzo::Utils';
19  
20 11 ▶use Types::Standard qw/ :all /;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 11 ▶use Business::Monzo::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 11 ▶use Business::Monzo::Balance;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 11 ▶use Business::Monzo::Webhook;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 11 ▶use Business::Monzo::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 =head1 ATTRIBUTES
27  
28 The Account class has the following attributes (with their type).
29  
30 id (Str)
31 description (Str)
32 created (DateTime)
33  
34 Note that when a Str is passed to ->created this will be coerced
35 to a DateTime object.
36  
37 =cut
38  
39 11 has [ qw/ id / ] => (
40 is => 'ro',
41 isa => Str,
42 required => 1,
43 );
44  
45 11 has [ qw/ description / ] => (
46 is => 'ro',
47 isa => Str,
48 );
49  
50 has created => (
51 is => 'ro',
52 isa => Maybe[InstanceOf['DateTime']],
53 3 ▶ coerce => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
54 3 my ( $args ) = @_;
55  
56 3 ▶ if ( ! ref( $args ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $args) 3 0 3
57 3 $args = DateTime::Format::DateParse->parse_datetime( $args );
58 }
59  
60 3 return $args;
61 },
62 11 );
63  
64 =head1 Operations on an account
65  
66 =cut
67  
68 1 ▶sub url {
Subroutine url: called CC=1 SCAR=0.0
Pod undocumented
69 1 Business::Monzo::Exception->throw({
70 message => "Monzo API does not currently support getting account data",
71 });
72 }
73  
74 1 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod documented
75 1 Business::Monzo::Exception->throw({
76 message => "Monzo API does not currently support getting account data",
77 });
78 }
79  
80 =head2 add_feed_item
81  
82 Adds a feed item to the Account. Returns true on success, otherwise will throw
83 an error. Note the required parameters:
84  
85 $Account->add_feed_item(
86 account_id => $id, # defaults to $Account->id,
87 type => $type, # defaults to 'basic'
88 url => $url, # optional, the URL to open when the item is tapped
89 params => {
90 title => $title, # REQUIRED
91 image_url => $url, # REQUIRED
92 body => $body_text, # optional
93 background_color => $hex_value, # optional
94 title_color => $hex_value, # optional
95 body_color => $hex_value, # optional
96 }
97 );
98  
99 =cut
100  
101 2 ▶sub add_feed_item {
Subroutine add_feed_item: called CC=4 SCAR=14.0
Pod documented
102 2 my ( $self,%params ) = @_;
103  
104 $params{params}{title} && $params{params}{image_url} ||
105 2 ▶ Business::Monzo::Exception->throw({
Branch: 1 branch
BranchTrueFalseTotal
$params{"params"}{"title"} and $params{"params"}{"image_url"} or "Business::Monzo::Exception"->throw({"message", "add_feed_item requires params: title, image_url"}) 1 1 2
Condition66%2/3
$params{"params"}{"title"} and $params{"params"}{"image_url"}
!ll&&!rl&&r
101
MC/DC50%1/2
$params{"params"}{"title"} and $params{"params"}{"image_url"}
$params{"params"}{"title"} $params{"params"}{"image_url"}
Truth table66%2/3
A and B
A= $params{"params"}{"title"}B= $params{"params"}{"image_url"}
ABresult
0X0
100
111
106 message => "add_feed_item requires params: title, image_url",
107 });
108  
109 1 $params{account_id} = $self->id;
110 1 ▶ $params{type} //= 'basic';
Condition50%1/2
$params{"type"} //= "basic"
l!l
01
MC/DC0%0/1
$params{"type"} //= "basic"
$params{"type"}
Truth table50%1/2
A
A= $params{"type"}
Aresult
11
00
111  
112 # title -> params[title] (params, params, params, params, params... what a mess)
113 1 $params{params} = { $self->_params_as_array_string( 'params',$params{params} ) };
114  
115 my %post_params = (
116 1 %{ delete $params{params} },
117 %params,
118 );
119  
120 1 return $self->client->api_post( 'feed',\%post_params );
121 }
122  
123 =head2 register_webhook
124  
125 Registers a webhook against the Account. Returns a Business::Monzo::Webhook
126 object. Note the required parameters:
127  
128 my $Webhook = $Account->webhooks(
129 callback_url => 'https://www.example.com/monzo/callback' # REQUIRED
130 );
131  
132 =cut
133  
134 2 ▶sub register_webhook {
Subroutine register_webhook: called CC=2 SCAR=6.9
Pod documented
135 2 my ( $self,%params ) = @_;
136  
137 2 ▶ $params{callback_url} || Business::Monzo::Exception->throw({
Branch: 1 branch
BranchTrueFalseTotal
$params{"callback_url"} or "Business::Monzo::Exception"->throw({"message", "register_webhook requires params: callback_url"}) 1 1 2
138 message => "register_webhook requires params: callback_url",
139 });
140  
141 my %post_params = (
142 url => $params{callback_url},
143 1 account_id => $self->id,
144 );
145  
146 1 my $data = $self->client->api_post( 'webhooks',\%post_params );
147  
148 return Business::Monzo::Webhook->new(
149 client => $self->client,
150 id => $data->{webhook}{id},
151 callback_url => $data->{webhook}{url},
152 1 account => $self,
153 );
154 }
155  
156 =head2 webhooks
157  
158 Returns a list of Business::Monzo::Webhook objects linked to the Account
159  
160 my @webhooks = $Account->webhooks
161  
162 =cut
163  
164 1 ▶sub webhooks {
Subroutine webhooks: called CC=3 SCAR=11.0
Pod documented
165 1 my ( $self ) = @_;
166  
167 1 my $data = $self->client->api_get(
168 'webhooks',{ account_id => $self->id }
169 );
170  
171 1 my @webhooks;
172  
173 1 ▶ foreach my $webhook ( @{ $data->{webhooks} // [] } ) {
Condition50%1/2
$data->{"webhooks"} // []
l!l
10
MC/DC0%0/1
$data->{"webhooks"} // []
$data->{"webhooks"}
Truth table50%1/2
A
A= $data->{"webhooks"}
Aresult
11
00
174  
175 push(
176 @webhooks,
177 Business::Monzo::Webhook->new(
178 client => $self->client,
179 id => $webhook->{id},
180 callback_url => $webhook->{url},
181 2 account => $self,
182 )
183 );
184 }
185  
186 1 return @webhooks;
187 }
188  
189 =head2 transactions
190  
191 Returns a list of L<Business::Monzo::Transaction> objects for the
192 account
193  
194 my @transactions = $Account->transactions( %query_params );
195  
196 =cut
197  
198 1 ▶sub transactions {
Subroutine transactions: called CC=1 SCAR=0.0
Pod documented
199 1 my ( $self,%params ) = @_;
200  
201 1 return $self->client->_get_transactions({
202 %params,
203 account_id => $self->id,
204 });
205 }
206  
207 =head2 balance
208  
209 Returns a L<Business::Monzo::Balance> object for the account with the
210 attributes populated having called the Monzo API
211  
212 $Balance = $Account->balance;
213  
214 =cut
215  
216 2 ▶sub balance {
Subroutine balance: called CC=1 SCAR=0.0
Pod documented
217 2 my ( $self ) = @_;
218  
219 2 return Business::Monzo::Balance->new(
220 client => $self->client,
221 account_id => $self->id,
222 )->get;
223 }
224  
225 =head1 SEE ALSO
226  
227 L<Business::Monzo>
228  
229 L<Business::Monzo::Resource>
230  
231 L<Business::Monzo::Balance>
232  
233 L<Business::Monzo::Transaction>
234  
235 =head1 AUTHOR
236  
237 Lee Johnson - C<leejo@cpan.org>
238  
239 =head1 LICENSE
240  
241 This library is free software; you can redistribute it and/or modify it under
242 the same terms as Perl itself. If you would like to contribute documentation,
243 features, bug fixes, or anything else then please raise an issue / pull request:
244  
245 https://github.com/leejo/business-monzo
246  
247 =cut
248  
249 11 1;
250  
251 # vim: ts=4:sw=4:et
« Monzo/Utils.pm ↑ Summary Monzo/Currency.pm »