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
|
|
5926
|
use strict; |
|
10
|
|
|
|
|
48
|
|
|
10
|
|
|
|
|
378
|
|
15
|
10
|
|
|
10
|
|
84
|
use warnings; |
|
10
|
|
|
|
|
30
|
|
|
10
|
|
|
|
|
428
|
|
16
|
|
|
|
|
|
|
|
17
|
10
|
|
|
10
|
|
68
|
use Moo; |
|
10
|
|
|
|
|
27
|
|
|
10
|
|
|
|
|
104
|
|
18
|
10
|
|
|
10
|
|
4460
|
use Carp qw/ confess carp /; |
|
10
|
|
|
|
|
25
|
|
|
10
|
|
|
|
|
865
|
|
19
|
10
|
|
|
10
|
|
2532
|
use Mojo::JSON qw/ encode_json /; |
|
10
|
|
|
|
|
1060093
|
|
|
10
|
|
|
|
|
799
|
|
20
|
10
|
|
|
10
|
|
106
|
use Scalar::Util qw/ blessed /; |
|
10
|
|
|
|
|
178
|
|
|
10
|
|
|
|
|
558
|
|
21
|
10
|
|
|
10
|
|
4409
|
use Try::Tiny; |
|
10
|
|
|
|
|
12712
|
|
|
10
|
|
|
|
|
5490
|
|
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
|
3305
|
my ( $self ) = @_; |
78
|
|
|
|
|
|
|
|
79
|
35
|
|
|
|
|
76
|
my %hash = %{ $self }; |
|
35
|
|
|
|
|
316
|
|
80
|
|
|
|
|
|
|
|
81
|
35
|
|
|
|
|
120
|
delete( $hash{client} ); |
82
|
|
|
|
|
|
|
|
83
|
35
|
|
|
|
|
97
|
foreach my $currency_key ( qw/ currency local_currency / ) { |
84
|
70
|
100
|
|
|
|
563
|
if ( blessed( $hash{$currency_key} ) ) { |
85
|
6
|
|
|
|
|
34
|
$hash{$currency_key} = $hash{$currency_key}->code; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
35
|
|
|
|
|
144
|
foreach my $k ( keys %hash ) { |
90
|
242
|
100
|
|
|
|
1585
|
if ( ref( $hash{$k} ) eq 'DateTime' ) { |
|
|
100
|
|
|
|
|
|
91
|
23
|
|
|
|
|
96
|
$hash{$k} = $hash{$k}->iso8601; |
92
|
|
|
|
|
|
|
} elsif ( my $blessed = blessed( $hash{$k} ) ) { |
93
|
24
|
100
|
|
|
|
110
|
next if $blessed =~ /Boolean/; |
94
|
12
|
|
|
|
|
84
|
$hash{$k} = { $hash{$k}->to_hash }; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
35
|
|
|
|
|
480
|
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
|
32
|
my ( $self ) = @_; |
111
|
|
|
|
|
|
|
|
112
|
7
|
|
|
|
|
31
|
return encode_json( { $self->to_hash } ); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# for JSON encoding modules (convert_blessed) |
116
|
9
|
|
|
9
|
0
|
7429
|
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
|
7
|
my ( $self,$sub_key ) = @_; |
132
|
|
|
|
|
|
|
|
133
|
1
|
|
|
|
|
43
|
my $data = $self->client->api_get( $self->url ); |
134
|
1
|
50
|
|
|
|
115
|
$data = $data->{$sub_key} if $sub_key; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
return $self->new( |
137
|
|
|
|
|
|
|
client => $self->client, |
138
|
1
|
|
|
|
|
9
|
%{ $data }, |
|
1
|
|
|
|
|
38
|
|
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 |