| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Business::Monzo::Resource; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Business::Monzo::Resource |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
This is a base class for Monzo resource classes, it implements common |
|
10
|
|
|
|
|
|
|
behaviour. You shouldn't use this class directly, but extend it instead. |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
|
13
|
|
|
|
|
|
|
|
|
14
|
10
|
|
|
10
|
|
5282
|
use strict; |
|
|
10
|
|
|
|
|
35
|
|
|
|
10
|
|
|
|
|
305
|
|
|
15
|
10
|
|
|
10
|
|
55
|
use warnings; |
|
|
10
|
|
|
|
|
21
|
|
|
|
10
|
|
|
|
|
336
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
10
|
|
|
10
|
|
54
|
use Moo; |
|
|
10
|
|
|
|
|
17
|
|
|
|
10
|
|
|
|
|
79
|
|
|
18
|
10
|
|
|
10
|
|
3648
|
use Carp qw/ confess carp /; |
|
|
10
|
|
|
|
|
22
|
|
|
|
10
|
|
|
|
|
715
|
|
|
19
|
10
|
|
|
10
|
|
2018
|
use Mojo::JSON qw/ encode_json /; |
|
|
10
|
|
|
|
|
782246
|
|
|
|
10
|
|
|
|
|
788
|
|
|
20
|
10
|
|
|
10
|
|
101
|
use Scalar::Util qw/ blessed /; |
|
|
10
|
|
|
|
|
148
|
|
|
|
10
|
|
|
|
|
443
|
|
|
21
|
10
|
|
|
10
|
|
4059
|
use Try::Tiny; |
|
|
10
|
|
|
|
|
10751
|
|
|
|
10
|
|
|
|
|
4880
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
The Resource class has the following attributes (with their type). |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
client (Business::Monzo::Client) - REQUIRED |
|
28
|
|
|
|
|
|
|
url (Str) |
|
29
|
|
|
|
|
|
|
url_no_id (Str) |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has client => ( |
|
34
|
|
|
|
|
|
|
is => 'ro', |
|
35
|
|
|
|
|
|
|
isa => sub { |
|
36
|
|
|
|
|
|
|
confess( "$_[0] is not a Business::Monzo::Client" ) |
|
37
|
|
|
|
|
|
|
if ref $_[0] ne 'Business::Monzo::Client'; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$Business::Monzo::Resource::client = $_[0]; |
|
40
|
|
|
|
|
|
|
}, |
|
41
|
|
|
|
|
|
|
required => 1, |
|
42
|
|
|
|
|
|
|
); |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
has [ qw/ url / ] => ( |
|
45
|
|
|
|
|
|
|
is => 'ro', |
|
46
|
|
|
|
|
|
|
lazy => 1, |
|
47
|
|
|
|
|
|
|
default => sub { |
|
48
|
|
|
|
|
|
|
my ( $self ) = @_; |
|
49
|
|
|
|
|
|
|
join( '/',$self->url_no_id,$self->id ) |
|
50
|
|
|
|
|
|
|
}, |
|
51
|
|
|
|
|
|
|
); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
has [ qw/ url_no_id / ] => ( |
|
54
|
|
|
|
|
|
|
is => 'ro', |
|
55
|
|
|
|
|
|
|
lazy => 1, |
|
56
|
|
|
|
|
|
|
default => sub { |
|
57
|
|
|
|
|
|
|
my ( $self ) = @_; |
|
58
|
|
|
|
|
|
|
return join( |
|
59
|
|
|
|
|
|
|
'/', |
|
60
|
|
|
|
|
|
|
$self->client->api_url, |
|
61
|
|
|
|
|
|
|
lc( ( split( ':',ref( $self ) ) )[-1] ) . 's', |
|
62
|
|
|
|
|
|
|
); |
|
63
|
|
|
|
|
|
|
}, |
|
64
|
|
|
|
|
|
|
); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 METHODS |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 to_hash |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Returns a hash representation of the object. |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my %data = $transaction->to_hash; |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub to_hash { |
|
77
|
35
|
|
|
35
|
1
|
2043
|
my ( $self ) = @_; |
|
78
|
|
|
|
|
|
|
|
|
79
|
35
|
|
|
|
|
53
|
my %hash = %{ $self }; |
|
|
35
|
|
|
|
|
222
|
|
|
80
|
|
|
|
|
|
|
|
|
81
|
35
|
|
|
|
|
85
|
delete( $hash{client} ); |
|
82
|
|
|
|
|
|
|
|
|
83
|
35
|
|
|
|
|
64
|
foreach my $currency_key ( qw/ currency local_currency / ) { |
|
84
|
70
|
100
|
|
|
|
371
|
if ( blessed( $hash{$currency_key} ) ) { |
|
85
|
6
|
|
|
|
|
21
|
$hash{$currency_key} = $hash{$currency_key}->code; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
35
|
|
|
|
|
94
|
foreach my $k ( keys %hash ) { |
|
90
|
242
|
100
|
|
|
|
1176
|
if ( ref( $hash{$k} ) eq 'DateTime' ) { |
|
|
|
100
|
|
|
|
|
|
|
91
|
23
|
|
|
|
|
70
|
$hash{$k} = $hash{$k}->iso8601; |
|
92
|
|
|
|
|
|
|
} elsif ( my $blessed = blessed( $hash{$k} ) ) { |
|
93
|
24
|
100
|
|
|
|
114
|
next if $blessed =~ /Boolean/; |
|
94
|
12
|
|
|
|
|
63
|
$hash{$k} = { $hash{$k}->to_hash }; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
35
|
|
|
|
|
324
|
return %hash; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 as_json |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Returns a json string representation of the object. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my $json = $transaction->as_json; |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub as_json { |
|
110
|
7
|
|
|
7
|
1
|
24
|
my ( $self ) = @_; |
|
111
|
|
|
|
|
|
|
|
|
112
|
7
|
|
|
|
|
28
|
return encode_json( { $self->to_hash } ); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# for JSON encoding modules (convert_blessed) |
|
116
|
9
|
|
|
9
|
0
|
5320
|
sub TO_JSON { shift->to_hash; } |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 get |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Returns a new instance of the object populated with the attributes having called |
|
121
|
|
|
|
|
|
|
the API |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $populated_object = $object->get; |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This is for when you have instantiated an object with the id, so calling the API |
|
126
|
|
|
|
|
|
|
will retrieve the full details for the entity. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub get { |
|
131
|
1
|
|
|
1
|
1
|
3
|
my ( $self,$sub_key ) = @_; |
|
132
|
|
|
|
|
|
|
|
|
133
|
1
|
|
|
|
|
23
|
my $data = $self->client->api_get( $self->url ); |
|
134
|
1
|
50
|
|
|
|
64
|
$data = $data->{$sub_key} if $sub_key; |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
return $self->new( |
|
137
|
|
|
|
|
|
|
client => $self->client, |
|
138
|
1
|
|
|
|
|
4
|
%{ $data }, |
|
|
1
|
|
|
|
|
20
|
|
|
139
|
|
|
|
|
|
|
); |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 AUTHOR |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Lee Johnson - C<leejo@cpan.org> |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under |
|
147
|
|
|
|
|
|
|
the same terms as Perl itself. If you would like to contribute documentation, |
|
148
|
|
|
|
|
|
|
features, bug fixes, or anything else then please raise an issue / pull request: |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
https://github.com/leejo/business-monzo |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# vim: ts=4:sw=4:et |