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
|
|
141549
|
use 5.014; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
104
|
|
6
|
4
|
|
|
4
|
|
13
|
use strict; use warnings; no indirect 'fatal'; use namespace::autoclean; |
|
4
|
|
|
4
|
|
5
|
|
|
4
|
|
|
4
|
|
89
|
|
|
4
|
|
|
4
|
|
14
|
|
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
87
|
|
|
4
|
|
|
|
|
325
|
|
|
4
|
|
|
|
|
681
|
|
|
4
|
|
|
|
|
23
|
|
|
4
|
|
|
|
|
178
|
|
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
26
|
|
7
|
4
|
|
|
4
|
|
235
|
use mro 'c3'; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
22
|
|
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
86
|
use Readonly; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
205
|
|
10
|
4
|
|
|
4
|
|
458
|
use Moose; use MooseX::StrictConstructor; |
|
4
|
|
|
4
|
|
227001
|
|
|
4
|
|
|
|
|
21
|
|
|
4
|
|
|
|
|
20412
|
|
|
4
|
|
|
|
|
20574
|
|
|
4
|
|
|
|
|
25
|
|
11
|
4
|
|
|
4
|
|
16665
|
use Types::Standard 'Str'; |
|
4
|
|
|
|
|
183802
|
|
|
4
|
|
|
|
|
45
|
|
12
|
4
|
|
|
4
|
|
3718
|
use CloudFlare::Client::Types 'LWPUserAgent'; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
37
|
|
13
|
4
|
|
|
4
|
|
2777
|
use Kavorka; |
|
4
|
|
|
|
|
21708
|
|
|
4
|
|
|
|
|
30
|
|
14
|
|
|
|
|
|
|
|
15
|
4
|
|
|
4
|
|
579985
|
use CloudFlare::Client::Exception::Connection; |
|
4
|
|
|
|
|
17
|
|
|
4
|
|
|
|
|
342
|
|
16
|
4
|
|
|
4
|
|
2189
|
use CloudFlare::Client::Exception::Upstream; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
199
|
|
17
|
4
|
|
|
4
|
|
717
|
use LWP::UserAgent 6.02; |
|
4
|
|
|
|
|
37445
|
|
|
4
|
|
|
|
|
170
|
|
18
|
|
|
|
|
|
|
# This isn't used directly but we want the dependency |
19
|
4
|
|
|
4
|
|
2338
|
use LWP::Protocol::https 6.02; |
|
4
|
|
|
|
|
301601
|
|
|
4
|
|
|
|
|
174
|
|
20
|
4
|
|
|
4
|
|
1626
|
use JSON::MaybeXS; |
|
4
|
|
|
|
|
5684
|
|
|
4
|
|
|
|
|
803
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = 'v0.55.3'; # 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
|
|
25
|
Readonly my $ua => LWP::UserAgent::->new; |
39
|
4
|
|
|
|
|
3730
|
$ua->agent($UA_STRING); |
40
|
4
|
|
|
|
|
192
|
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
|
|
31805
|
method _apiCall ( $act is ro, %args is ro ) { |
|
4
|
50
|
|
4
|
|
6
|
|
|
4
|
50
|
|
4
|
|
514
|
|
|
4
|
50
|
|
3
|
|
15
|
|
|
4
|
50
|
|
|
|
6
|
|
|
4
|
|
|
|
|
392
|
|
|
4
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
1288
|
|
|
3
|
|
|
|
|
77
|
|
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
54
|
|
|
0
|
|
|
|
|
0
|
|
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
27
|
|
|
3
|
|
|
|
|
26
|
|
|
3
|
|
|
|
|
3
|
|
50
|
|
|
|
|
|
|
# query cloudflare |
51
|
3
|
|
|
|
|
87
|
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
|
|
|
|
29725
|
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
|
|
|
|
|
32
|
Readonly my $info => decode_json($res->decoded_content); |
65
|
2
|
100
|
|
|
|
363
|
CloudFlare::Client::Exception::Upstream::->throw( |
66
|
|
|
|
|
|
|
errorCode => $info->{err_code}, |
67
|
|
|
|
|
|
|
message => $info->{msg},) |
68
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub AUTOLOAD { |
74
|
3
|
|
|
3
|
|
24586
|
our $AUTOLOAD; |
75
|
3
|
|
|
|
|
8
|
my $self = shift; |
76
|
|
|
|
|
|
|
# pull action out of f.q. method name |
77
|
3
|
|
|
|
|
22
|
my $act = $AUTOLOAD =~ s/.*:://r; |
78
|
3
|
|
|
|
|
59
|
return $self->_apiCall( $act, @_ );} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
81
|
|
|
|
|
|
|
1; # End of CloudFlare::Client |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
__END__ |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=pod |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=encoding UTF-8 |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 NAME |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
CloudFlare::Client - Object Orientated Interface to CloudFlare client API |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 VERSION |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
version v0.55.3 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 SYNOPSIS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
use CloudFlare::Client; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $api = CloudFlare::Client::->new( |
102
|
|
|
|
|
|
|
user => $CF_USER, |
103
|
|
|
|
|
|
|
apikey => $CF_KEY,); |
104
|
|
|
|
|
|
|
$api->stats( z => $ZONE, interval => $INTERVAL); |
105
|
|
|
|
|
|
|
... |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 OVERVIEW |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Please see the documentation at |
110
|
|
|
|
|
|
|
L<https://www.cloudflare.com/docs/client-api.html> for information on the |
111
|
|
|
|
|
|
|
CloudFlare client API and its arguments. API actions are mapped to methods of |
112
|
|
|
|
|
|
|
the same name and arguments are passed in as a hash with keys as given in the |
113
|
|
|
|
|
|
|
docs |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Successful API calls return the response section from the upstream JSON |
116
|
|
|
|
|
|
|
API. Failures for whatever reason throw exceptions under the |
117
|
|
|
|
|
|
|
CloudFlare::Client::Exception:: namespace |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 METHODS |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 new |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Construct a new API object |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my $api = CloudFlare::Client::->new( |
126
|
|
|
|
|
|
|
user => $CF_USER, |
127
|
|
|
|
|
|
|
apikey => $CF_KEY); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=for test_synopsis my ( $CF_USER, $CF_KEY, $ZONE, $INTERVAL); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 SEE ALSO |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Please see those modules/websites for more information related to this module. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=over 4 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item * |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
L<Mojo::Cloudflare|Mojo::Cloudflare> |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item * |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
L<WebService::CloudFlare::Host|WebService::CloudFlare::Host> |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=back |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 SUPPORT |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 Perldoc |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
perldoc CloudFlare::Client |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 Websites |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
The following websites have more information about this module, and may be of help to you. As always, |
160
|
|
|
|
|
|
|
in addition to those websites please use your favorite search engine to discover more resources. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=over 4 |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item * |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
MetaCPAN |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
A modern, open-source CPAN search engine, useful to view POD in HTML format. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
L<http://metacpan.org/release/CloudFlare-Client> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=back |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 Email |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
You can email the author of this module at C<me+dev@peter-r.co.uk> asking for help with any problems you have. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 Source Code |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
The code is open to the world, and available for you to hack on. Please feel free to browse it and play |
181
|
|
|
|
|
|
|
with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull |
182
|
|
|
|
|
|
|
from your repository :) |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
L<https://github.com/pwr22/cloudflare-client> |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
git clone git://github.com/pwr22/cloudflare-client.git |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 BUGS |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website |
191
|
|
|
|
|
|
|
https://github.com/pwr22/cloudflare-client/issues |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
194
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
195
|
|
|
|
|
|
|
feature. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Thanks to CloudFlare providing an awesome free service with an API |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 CONTRIBUTOR |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=for stopwords Peter Roberts |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Peter Roberts <me+dev@peter-r.co.uk> |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 AUTHOR |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Peter Roberts <me+dev@peter-r.co.uk> |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
This software is Copyright (c) 2015 by Peter Roberts. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
This is free software, licensed under: |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
The MIT (X11) License |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=cut |