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
|
|
1814012
|
use 5.014; |
|
4
|
|
|
|
|
14
|
|
6
|
4
|
|
|
4
|
|
17
|
use strict; use warnings; no indirect 'fatal'; use namespace::autoclean; |
|
4
|
|
|
4
|
|
5
|
|
|
4
|
|
|
4
|
|
77
|
|
|
4
|
|
|
4
|
|
15
|
|
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
111
|
|
|
4
|
|
|
|
|
388
|
|
|
4
|
|
|
|
|
843
|
|
|
4
|
|
|
|
|
26
|
|
|
4
|
|
|
|
|
202
|
|
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
31
|
|
7
|
4
|
|
|
4
|
|
278
|
use mro 'c3'; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
27
|
|
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
97
|
use Readonly; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
248
|
|
10
|
4
|
|
|
4
|
|
480
|
use Moose; use MooseX::StrictConstructor; |
|
4
|
|
|
4
|
|
250546
|
|
|
4
|
|
|
|
|
25
|
|
|
4
|
|
|
|
|
20370
|
|
|
4
|
|
|
|
|
15827
|
|
|
4
|
|
|
|
|
33
|
|
11
|
4
|
|
|
4
|
|
14938
|
use Types::Standard 'Str'; |
|
4
|
|
|
|
|
192765
|
|
|
4
|
|
|
|
|
47
|
|
12
|
4
|
|
|
4
|
|
4478
|
use CloudFlare::Client::Types 'LWPUserAgent'; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
51
|
|
13
|
4
|
|
|
4
|
|
3321
|
use Kavorka; |
|
4
|
|
|
|
|
27116
|
|
|
4
|
|
|
|
|
36
|
|
14
|
|
|
|
|
|
|
|
15
|
4
|
|
|
4
|
|
767903
|
use CloudFlare::Client::Exception::Connection; |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
238
|
|
16
|
4
|
|
|
4
|
|
2319
|
use CloudFlare::Client::Exception::Upstream; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
183
|
|
17
|
4
|
|
|
4
|
|
665
|
use LWP::UserAgent 6.02; |
|
4
|
|
|
|
|
44358
|
|
|
4
|
|
|
|
|
162
|
|
18
|
|
|
|
|
|
|
# This isn't used directly but we want the dependency |
19
|
4
|
|
|
4
|
|
2362
|
use LWP::Protocol::https 6.02; |
|
4
|
|
|
|
|
331261
|
|
|
4
|
|
|
|
|
178
|
|
20
|
4
|
|
|
4
|
|
1740
|
use JSON::MaybeXS; |
|
4
|
|
|
|
|
7951
|
|
|
4
|
|
|
|
|
889
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = 'v0.55.5'; # TRIAL 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
|
|
29
|
Readonly my $ua => LWP::UserAgent::->new; |
39
|
4
|
|
|
|
|
3778
|
$ua->agent($UA_STRING); |
40
|
4
|
|
|
|
|
195
|
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
|
|
31018
|
method _apiCall ( $act is ro, %args is ro ) { |
|
4
|
50
|
|
4
|
|
7
|
|
|
4
|
50
|
|
4
|
|
571
|
|
|
4
|
50
|
|
3
|
|
16
|
|
|
4
|
50
|
|
|
|
6
|
|
|
4
|
|
|
|
|
433
|
|
|
4
|
|
|
|
|
18
|
|
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
978
|
|
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
62
|
|
|
0
|
|
|
|
|
0
|
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
26
|
|
|
3
|
|
|
|
|
22
|
|
|
3
|
|
|
|
|
3
|
|
50
|
|
|
|
|
|
|
# query cloudflare |
51
|
3
|
|
|
|
|
98
|
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
|
|
|
|
33781
|
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
|
|
|
|
|
36
|
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
|
|
|
|
424
|
unless $info->{result} eq 'success'; |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
8
|
return $info->{response};} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# all API calls are implemented through autoloading, the action is the method |
73
|
4
|
50
|
|
4
|
|
3550
|
method AUTOLOAD { |
|
4
|
|
|
3
|
|
4
|
|
|
4
|
|
|
|
|
730
|
|
|
3
|
|
|
|
|
26586
|
|
|
3
|
|
|
|
|
10
|
|
74
|
3
|
|
|
|
|
3
|
our $AUTOLOAD; |
75
|
|
|
|
|
|
|
# pull action out of f.q. method name |
76
|
3
|
|
|
|
|
15
|
my $act = $AUTOLOAD =~ s/.*:://r; |
77
|
3
|
|
|
|
|
19
|
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.5 |
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 |