| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Business::Mondo::Account; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Business::Mondo::Account |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
A class for a Mondo account, extends L<Business::Mondo::Resource> |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
|
12
|
|
|
|
|
|
|
|
|
13
|
10
|
|
|
10
|
|
38
|
use strict; |
|
|
10
|
|
|
|
|
11
|
|
|
|
10
|
|
|
|
|
232
|
|
|
14
|
10
|
|
|
10
|
|
30
|
use warnings; |
|
|
10
|
|
|
|
|
10
|
|
|
|
10
|
|
|
|
|
176
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
10
|
|
|
10
|
|
30
|
use Moo; |
|
|
10
|
|
|
|
|
13
|
|
|
|
10
|
|
|
|
|
46
|
|
|
17
|
|
|
|
|
|
|
extends 'Business::Mondo::Resource'; |
|
18
|
|
|
|
|
|
|
with 'Business::Mondo::Utils'; |
|
19
|
|
|
|
|
|
|
|
|
20
|
10
|
|
|
10
|
|
2267
|
use Types::Standard qw/ :all /; |
|
|
10
|
|
|
|
|
13
|
|
|
|
10
|
|
|
|
|
105
|
|
|
21
|
10
|
|
|
10
|
|
247958
|
use Business::Mondo::Address; |
|
|
10
|
|
|
|
|
19
|
|
|
|
10
|
|
|
|
|
319
|
|
|
22
|
10
|
|
|
10
|
|
4450
|
use Business::Mondo::Balance; |
|
|
10
|
|
|
|
|
22
|
|
|
|
10
|
|
|
|
|
279
|
|
|
23
|
10
|
|
|
10
|
|
4095
|
use Business::Mondo::Webhook; |
|
|
10
|
|
|
|
|
25
|
|
|
|
10
|
|
|
|
|
284
|
|
|
24
|
10
|
|
|
10
|
|
50
|
use Business::Mondo::Exception; |
|
|
10
|
|
|
|
|
10
|
|
|
|
10
|
|
|
|
|
4815
|
|
|
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
|
|
|
|
|
|
|
has [ qw/ id / ] => ( |
|
40
|
|
|
|
|
|
|
is => 'ro', |
|
41
|
|
|
|
|
|
|
isa => Str, |
|
42
|
|
|
|
|
|
|
required => 1, |
|
43
|
|
|
|
|
|
|
); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has [ qw/ description / ] => ( |
|
46
|
|
|
|
|
|
|
is => 'ro', |
|
47
|
|
|
|
|
|
|
isa => Str, |
|
48
|
|
|
|
|
|
|
); |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
has created => ( |
|
51
|
|
|
|
|
|
|
is => 'ro', |
|
52
|
|
|
|
|
|
|
isa => Maybe[InstanceOf['DateTime']], |
|
53
|
|
|
|
|
|
|
coerce => sub { |
|
54
|
|
|
|
|
|
|
my ( $args ) = @_; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
if ( ! ref( $args ) ) { |
|
57
|
|
|
|
|
|
|
$args = DateTime::Format::DateParse->parse_datetime( $args ); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return $args; |
|
61
|
|
|
|
|
|
|
}, |
|
62
|
|
|
|
|
|
|
); |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 Operations on an account |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub url { |
|
69
|
1
|
|
|
1
|
0
|
857
|
Business::Mondo::Exception->throw({ |
|
70
|
|
|
|
|
|
|
message => "Mondo API does not currently support getting account data", |
|
71
|
|
|
|
|
|
|
}); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub get { |
|
75
|
1
|
|
|
1
|
1
|
978
|
Business::Mondo::Exception->throw({ |
|
76
|
|
|
|
|
|
|
message => "Mondo 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
|
|
|
|
|
|
|
sub add_feed_item { |
|
102
|
2
|
|
|
2
|
1
|
1478
|
my ( $self,%params ) = @_; |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
$params{params}{title} && $params{params}{image_url} || |
|
105
|
2
|
100
|
66
|
|
|
13
|
Business::Mondo::Exception->throw({ |
|
106
|
|
|
|
|
|
|
message => "add_feed_item requires params: title, image_url", |
|
107
|
|
|
|
|
|
|
}); |
|
108
|
|
|
|
|
|
|
|
|
109
|
1
|
|
|
|
|
4
|
$params{account_id} = $self->id; |
|
110
|
1
|
|
50
|
|
|
6
|
$params{type} //= 'basic'; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# title -> params[title] (params, params, params, params, params... what a mess) |
|
113
|
1
|
|
|
|
|
5
|
$params{params} = { $self->_params_as_array_string( 'params',$params{params} ) }; |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
my %post_params = ( |
|
116
|
1
|
|
|
|
|
2
|
%{ delete $params{params} }, |
|
|
1
|
|
|
|
|
5
|
|
|
117
|
|
|
|
|
|
|
%params, |
|
118
|
|
|
|
|
|
|
); |
|
119
|
|
|
|
|
|
|
|
|
120
|
1
|
|
|
|
|
9
|
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::Mondo::Webhook |
|
126
|
|
|
|
|
|
|
object. Note the required parameters: |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
my $Webhook = $Account->webhooks( |
|
129
|
|
|
|
|
|
|
callback_url => 'https://www.example.com/mondo/callback' # REQUIRED |
|
130
|
|
|
|
|
|
|
); |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub register_webhook { |
|
135
|
2
|
|
|
2
|
1
|
1067
|
my ( $self,%params ) = @_; |
|
136
|
|
|
|
|
|
|
|
|
137
|
2
|
100
|
|
|
|
11
|
$params{callback_url} || Business::Mondo::Exception->throw({ |
|
138
|
|
|
|
|
|
|
message => "register_webhook requires params: callback_url", |
|
139
|
|
|
|
|
|
|
}); |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
my %post_params = ( |
|
142
|
|
|
|
|
|
|
url => $params{callback_url}, |
|
143
|
1
|
|
|
|
|
4
|
account_id => $self->id, |
|
144
|
|
|
|
|
|
|
); |
|
145
|
|
|
|
|
|
|
|
|
146
|
1
|
|
|
|
|
5
|
my $data = $self->client->api_post( 'webhooks',\%post_params ); |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
return Business::Mondo::Webhook->new( |
|
149
|
|
|
|
|
|
|
client => $self->client, |
|
150
|
|
|
|
|
|
|
id => $data->{webhook}{id}, |
|
151
|
|
|
|
|
|
|
callback_url => $data->{webhook}{url}, |
|
152
|
1
|
|
|
|
|
14
|
account => $self, |
|
153
|
|
|
|
|
|
|
); |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 webhooks |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Returns a list of Business::Mondo::Webhook objects linked to the Account |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
my @webhooks = $Account->webhooks |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub webhooks { |
|
165
|
1
|
|
|
1
|
1
|
1606
|
my ( $self ) = @_; |
|
166
|
|
|
|
|
|
|
|
|
167
|
1
|
|
|
|
|
7
|
my $data = $self->client->api_get( |
|
168
|
|
|
|
|
|
|
'webhooks',{ account_id => $self->id } |
|
169
|
|
|
|
|
|
|
); |
|
170
|
|
|
|
|
|
|
|
|
171
|
1
|
|
|
|
|
8
|
my @webhooks; |
|
172
|
|
|
|
|
|
|
|
|
173
|
1
|
|
50
|
|
|
2
|
foreach my $webhook ( @{ $data->{webhooks} // [] } ) { |
|
|
1
|
|
|
|
|
4
|
|
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
push( |
|
176
|
|
|
|
|
|
|
@webhooks, |
|
177
|
|
|
|
|
|
|
Business::Mondo::Webhook->new( |
|
178
|
|
|
|
|
|
|
client => $self->client, |
|
179
|
|
|
|
|
|
|
id => $webhook->{id}, |
|
180
|
|
|
|
|
|
|
callback_url => $webhook->{url}, |
|
181
|
2
|
|
|
|
|
51
|
account => $self, |
|
182
|
|
|
|
|
|
|
) |
|
183
|
|
|
|
|
|
|
); |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
1
|
|
|
|
|
20
|
return @webhooks; |
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head2 transactions |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Returns a list of L<Business::Mondo::Transaction> objects for the |
|
192
|
|
|
|
|
|
|
account |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
my @transactions = $Account->transactions( %query_params ); |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=cut |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub transactions { |
|
199
|
1
|
|
|
1
|
1
|
27
|
my ( $self,%params ) = @_; |
|
200
|
|
|
|
|
|
|
|
|
201
|
1
|
|
|
|
|
12
|
return $self->client->_get_transactions({ |
|
202
|
|
|
|
|
|
|
%params, |
|
203
|
|
|
|
|
|
|
account_id => $self->id, |
|
204
|
|
|
|
|
|
|
}); |
|
205
|
|
|
|
|
|
|
} |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head2 balance |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Returns a L<Business::Mondo::Balance> object for the account with the |
|
210
|
|
|
|
|
|
|
attributes populated having called the Mondo API |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
$Balance = $Account->balance; |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=cut |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub balance { |
|
217
|
2
|
|
|
2
|
1
|
22
|
my ( $self ) = @_; |
|
218
|
|
|
|
|
|
|
|
|
219
|
2
|
|
|
|
|
22
|
return Business::Mondo::Balance->new( |
|
220
|
|
|
|
|
|
|
client => $self->client, |
|
221
|
|
|
|
|
|
|
account_id => $self->id, |
|
222
|
|
|
|
|
|
|
)->get; |
|
223
|
|
|
|
|
|
|
} |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
L<Business::Mondo> |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
L<Business::Mondo::Resource> |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
L<Business::Mondo::Balance> |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
L<Business::Mondo::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-mondo |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=cut |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
1; |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
# vim: ts=4:sw=4:et |