line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CloudFlare::Client; |
2
|
|
|
|
|
|
|
# ABSTRACT: Object Orientated Interface to CloudFlare client API |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# Or Kavorka will explode |
5
|
4
|
|
|
4
|
|
153676
|
use 5.014; |
|
4
|
|
|
|
|
10
|
|
6
|
4
|
|
|
4
|
|
17
|
use strict; use warnings; no indirect 'fatal'; use namespace::autoclean; |
|
4
|
|
|
4
|
|
4
|
|
|
4
|
|
|
4
|
|
82
|
|
|
4
|
|
|
4
|
|
15
|
|
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
115
|
|
|
4
|
|
|
|
|
400
|
|
|
4
|
|
|
|
|
997
|
|
|
4
|
|
|
|
|
30
|
|
|
4
|
|
|
|
|
203
|
|
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
33
|
|
7
|
4
|
|
|
4
|
|
305
|
use mro 'c3'; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
26
|
|
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
107
|
use Readonly; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
260
|
|
10
|
4
|
|
|
4
|
|
476
|
use Moose; use MooseX::StrictConstructor; |
|
4
|
|
|
4
|
|
252330
|
|
|
4
|
|
|
|
|
30
|
|
|
4
|
|
|
|
|
26372
|
|
|
4
|
|
|
|
|
22750
|
|
|
4
|
|
|
|
|
32
|
|
11
|
4
|
|
|
4
|
|
22134
|
use Types::Standard 'Str'; |
|
4
|
|
|
|
|
210415
|
|
|
4
|
|
|
|
|
43
|
|
12
|
4
|
|
|
4
|
|
4253
|
use CloudFlare::Client::Types 'LWPUserAgent'; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
49
|
|
13
|
4
|
|
|
4
|
|
3276
|
use Kavorka; |
|
4
|
|
|
|
|
30061
|
|
|
4
|
|
|
|
|
38
|
|
14
|
|
|
|
|
|
|
|
15
|
4
|
|
|
4
|
|
670736
|
use CloudFlare::Client::Exception::Connection; |
|
4
|
|
|
|
|
17
|
|
|
4
|
|
|
|
|
267
|
|
16
|
4
|
|
|
4
|
|
2423
|
use CloudFlare::Client::Exception::Upstream; |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
225
|
|
17
|
4
|
|
|
4
|
|
1009
|
use LWP::UserAgent 6.02; |
|
4
|
|
|
|
|
50676
|
|
|
4
|
|
|
|
|
172
|
|
18
|
|
|
|
|
|
|
# This isn't used directly but we want the dependency |
19
|
4
|
|
|
4
|
|
2193
|
use LWP::Protocol::https 6.02; |
|
4
|
|
|
|
|
401883
|
|
|
4
|
|
|
|
|
202
|
|
20
|
4
|
|
|
4
|
|
2039
|
use JSON::MaybeXS; |
|
4
|
|
|
|
|
11167
|
|
|
4
|
|
|
|
|
1179
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = 'v0.55.4'; # VERSION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# CF credentials |
25
|
|
|
|
|
|
|
has '_user' => ( |
26
|
|
|
|
|
|
|
is => 'ro', |
27
|
|
|
|
|
|
|
isa => Str, |
28
|
|
|
|
|
|
|
required => 1, |
29
|
|
|
|
|
|
|
init_arg => 'user',); |
30
|
|
|
|
|
|
|
has '_key' => ( |
31
|
|
|
|
|
|
|
is => 'ro', |
32
|
|
|
|
|
|
|
isa => Str, |
33
|
|
|
|
|
|
|
required => 1, |
34
|
|
|
|
|
|
|
init_arg => 'apikey',); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Readonly my $UA_STRING => "CloudFlare::Client/$CloudFlare::Client::VERSION"; |
37
|
|
|
|
|
|
|
sub _buildUa { |
38
|
4
|
|
|
4
|
|
40
|
Readonly my $ua => LWP::UserAgent::->new; |
39
|
4
|
|
|
|
|
4346
|
$ua->agent($UA_STRING); |
40
|
4
|
|
|
|
|
286
|
return $ua;} |
41
|
|
|
|
|
|
|
has '_ua' => ( |
42
|
|
|
|
|
|
|
is => 'ro', |
43
|
|
|
|
|
|
|
isa => LWPUserAgent, |
44
|
|
|
|
|
|
|
init_arg => undef, |
45
|
|
|
|
|
|
|
builder => '_buildUa',); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Calls through to the CF API, can throw exceptions under ::Exception:: |
48
|
|
|
|
|
|
|
Readonly my $CF_URL => 'https://www.cloudflare.com/api_json.html'; |
49
|
4
|
50
|
33
|
4
|
|
38534
|
method _apiCall ( $act is ro, %args is ro ) { |
|
4
|
50
|
|
4
|
|
9
|
|
|
4
|
50
|
|
4
|
|
784
|
|
|
4
|
50
|
|
3
|
|
25
|
|
|
4
|
50
|
|
|
|
7
|
|
|
4
|
|
|
|
|
592
|
|
|
4
|
|
|
|
|
26
|
|
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
1299
|
|
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
57
|
|
|
0
|
|
|
|
|
0
|
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
15
|
|
|
3
|
|
|
|
|
38
|
|
|
3
|
|
|
|
|
22
|
|
|
3
|
|
|
|
|
4
|
|
50
|
|
|
|
|
|
|
# query cloudflare |
51
|
3
|
|
|
|
|
94
|
Readonly my $res => $self->_ua->post( $CF_URL, { |
52
|
|
|
|
|
|
|
%args, |
53
|
|
|
|
|
|
|
# global args |
54
|
|
|
|
|
|
|
# override user specified |
55
|
|
|
|
|
|
|
tkn => $self->_key, |
56
|
|
|
|
|
|
|
email => $self->_user, |
57
|
|
|
|
|
|
|
a => $act,}); |
58
|
|
|
|
|
|
|
# Handle connection errors |
59
|
3
|
100
|
|
|
|
35778
|
CloudFlare::Client::Exception::Connection::->throw( |
60
|
|
|
|
|
|
|
status => $res->status_line, |
61
|
|
|
|
|
|
|
message => 'HTTPS request failed',) |
62
|
|
|
|
|
|
|
unless $res->is_success; |
63
|
|
|
|
|
|
|
# Handle errors from CF |
64
|
2
|
|
|
|
|
79
|
Readonly my $info => decode_json($res->decoded_content); |
65
|
|
|
|
|
|
|
CloudFlare::Client::Exception::Upstream::->throw( |
66
|
|
|
|
|
|
|
errorCode => $info->{err_code}, |
67
|
|
|
|
|
|
|
message => $info->{msg},) |
68
|
2
|
100
|
|
|
|
567
|
unless $info->{result} eq 'success'; |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
12
|
return $info->{response};} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# all API calls are implemented through autoloading, the action is the method |
73
|
4
|
50
|
|
4
|
|
5352
|
method AUTOLOAD { |
|
4
|
|
|
3
|
|
8
|
|
|
4
|
|
|
|
|
899
|
|
|
3
|
|
|
|
|
28770
|
|
|
3
|
|
|
|
|
12
|
|
74
|
3
|
|
|
|
|
5
|
our $AUTOLOAD; |
75
|
|
|
|
|
|
|
# pull action out of f.q. method name |
76
|
3
|
|
|
|
|
13
|
my $act = $AUTOLOAD =~ s/.*:://r; |
77
|
3
|
|
|
|
|
22
|
return $self->_apiCall( $act, @_ );} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
80
|
|
|
|
|
|
|
1; # End of CloudFlare::Client |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=pod |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=encoding UTF-8 |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 NAME |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
CloudFlare::Client - Object Orientated Interface to CloudFlare client API |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 VERSION |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
version v0.55.4 |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=for test_synopsis my ( $CF_USER, $CF_KEY, $ZONE, $INTERVAL); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 SYNOPSIS |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
use CloudFlare::Client; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $api = CloudFlare::Client::->new( |
103
|
|
|
|
|
|
|
user => $CF_USER, |
104
|
|
|
|
|
|
|
apikey => $CF_KEY,); |
105
|
|
|
|
|
|
|
$api->stats( z => $ZONE, interval => $INTERVAL); |
106
|
|
|
|
|
|
|
... |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 OVERVIEW |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Please see the documentation at |
111
|
|
|
|
|
|
|
L<https://www.cloudflare.com/docs/client-api.html> for information on the |
112
|
|
|
|
|
|
|
CloudFlare client API and its arguments. API actions are mapped to methods of |
113
|
|
|
|
|
|
|
the same name and arguments are passed in as a hash with keys as given in the |
114
|
|
|
|
|
|
|
docs |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Successful API calls return the response section from the upstream JSON |
117
|
|
|
|
|
|
|
API. Failures for whatever reason throw exceptions under the |
118
|
|
|
|
|
|
|
CloudFlare::Client::Exception:: namespace |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 METHODS |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 new |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Construct a new API object |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
my $api = CloudFlare::Client::->new( |
127
|
|
|
|
|
|
|
user => $CF_USER, |
128
|
|
|
|
|
|
|
apikey => $CF_KEY); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 SEE ALSO |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Please see those modules/websites for more information related to this module. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=over 4 |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item * |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
L<Mojo::Cloudflare|Mojo::Cloudflare> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L<WebService::CloudFlare::Host|WebService::CloudFlare::Host> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=back |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 SUPPORT |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 Perldoc |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
perldoc CloudFlare::Client |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 Websites |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
The following websites have more information about this module, and may be of help to you. As always, |
159
|
|
|
|
|
|
|
in addition to those websites please use your favorite search engine to discover more resources. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=over 4 |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item * |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
MetaCPAN |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
A modern, open-source CPAN search engine, useful to view POD in HTML format. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
L<http://metacpan.org/release/CloudFlare-Client> |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=back |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 Email |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
You can email the author of this module at C<me+dev@peter-r.co.uk> asking for help with any problems you have. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 Source Code |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
The code is open to the world, and available for you to hack on. Please feel free to browse it and play |
180
|
|
|
|
|
|
|
with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull |
181
|
|
|
|
|
|
|
from your repository :) |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
L<https://github.com/pwr22/cloudflare-client> |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
git clone git://github.com/pwr22/cloudflare-client.git |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 BUGS |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website |
190
|
|
|
|
|
|
|
https://github.com/pwr22/cloudflare-client/issues |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
193
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
194
|
|
|
|
|
|
|
feature. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Thanks to CloudFlare providing an awesome free service with an API |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head1 CONTRIBUTOR |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=for stopwords Peter Roberts |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Peter Roberts <me+github@peter-r.co.uk> |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 AUTHOR |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Peter Roberts <me+dev@peter-r.co.uk> |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
This software is Copyright (c) 2016 by Peter Roberts. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
This is free software, licensed under: |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
The MIT (X11) License |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=cut |