line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Cloutree; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24710
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
58
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
99
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
39
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use base 'Class::Singleton'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
973
|
|
8
|
1
|
|
|
1
|
|
7253
|
use Digest::SHA1 qw(sha1_hex); |
|
1
|
|
|
|
|
1021
|
|
|
1
|
|
|
|
|
73
|
|
9
|
1
|
|
|
1
|
|
1119
|
use HTTP::Request::Common; |
|
1
|
|
|
|
|
39196
|
|
|
1
|
|
|
|
|
90
|
|
10
|
1
|
|
|
1
|
|
4036
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
38789
|
|
|
1
|
|
|
|
|
740
|
|
11
|
1
|
|
|
1
|
|
1941
|
use LWP::Protocol::https; |
|
1
|
|
|
|
|
140042
|
|
|
1
|
|
|
|
|
393
|
|
12
|
|
|
|
|
|
|
require JSON; |
13
|
|
|
|
|
|
|
require Carp; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '1.01'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
WWW::Cloutree - Perl interface to Cloutree CDN |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Use this module for uploading files to https://cloutr.ee/ |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use WWW::Cloutree; |
26
|
|
|
|
|
|
|
# Create a WWW::Cloutree instance |
27
|
|
|
|
|
|
|
my $cloutree = WWW::Cloutree->instance( { app_key => $opts{key}, app_secret => $opts{secret}, raw => 1 } ); |
28
|
|
|
|
|
|
|
# Upload file and say raw server response (JSON) |
29
|
|
|
|
|
|
|
say $cloutree->upload_file({ file => $opts{file}, filename => $filename }); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 METHODS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 upload_file |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Upload file to CDN |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head3 parameters |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
filename - filename, |
40
|
|
|
|
|
|
|
file - file handler, |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub upload_file { |
45
|
0
|
|
|
0
|
1
|
|
my ( $self, $params ) = @_; |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
Carp::croak("File is mandatory parameter") unless $params->{file}; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# ToDo: test sending big files |
50
|
0
|
0
|
|
|
|
|
open my $file, '<', $params->{file} or Carp::croak("Can't open file: $!"); |
51
|
0
|
|
|
|
|
|
local $/ = undef; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# ToDo: set time |
54
|
0
|
|
|
|
|
|
my $time = ''; |
55
|
0
|
|
|
|
|
|
my $request = POST $self->{url}, |
56
|
|
|
|
|
|
|
KEY => $self->{app_key}, |
57
|
|
|
|
|
|
|
CHECKSUM => |
58
|
|
|
|
|
|
|
sha1_hex( join( ':', $self->{app_key}, $time, $params->{filename}, $self->{app_secret} ) ), |
59
|
|
|
|
|
|
|
FILENAME => $params->{filename}, |
60
|
|
|
|
|
|
|
TIMESTAMP => $time, |
61
|
|
|
|
|
|
|
Content => <$file>; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $response = $self->{ua}->request($request); |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
return unless $response->is_success; |
66
|
0
|
0
|
|
|
|
|
return $response->content if $self->{raw}; |
67
|
0
|
|
|
|
|
|
return $self->{json}->decode( $response->content ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 instance |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Create a WWW::Cloutree singleton instance. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $cloutree = WWW::Cloutree->instance( { app_key => 'KEY', app_secret => 'SECRET' } ); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head3 parameters (* - mandatory) |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
*app_key - API key, |
79
|
|
|
|
|
|
|
*app_secret - API secret, |
80
|
|
|
|
|
|
|
raw - Option: return raw text from server (do not decode JSON), |
81
|
|
|
|
|
|
|
url - URL of cloutree upload service (default https://cloutr.ee/upload) |
82
|
|
|
|
|
|
|
ua - User Agent module (default LWP::UserAgent) |
83
|
|
|
|
|
|
|
json - JSON module (default JSON) |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _new_instance { |
88
|
0
|
|
|
0
|
|
|
my $class = shift; |
89
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
90
|
0
|
|
|
|
|
|
my $params = shift; |
91
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
$self->{app_key} = $params->{app_key} or Carp::croak("Specify app_key"); |
93
|
0
|
0
|
|
|
|
|
$self->{app_secret} = $params->{app_secret} or Carp::croak("Specify app_secret"); |
94
|
|
|
|
|
|
|
#ToDo: Disabling SSL checking (fix it)! |
95
|
0
|
|
0
|
|
|
|
$self->{ua} = $params->{ua} || LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 } ); |
96
|
0
|
|
0
|
|
|
|
$self->{json} = $params->{json} || JSON->new(); |
97
|
0
|
|
0
|
|
|
|
$self->{url} = $params->{url} || 'https://cloutr.ee/upload'; |
98
|
0
|
|
|
|
|
|
$self->{raw} = $params->{raw}; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
return $self; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 AUTHOR |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Alexander Babenko (foxcool@cpan.org) |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SUPPORT |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Github: https://github.com/Foxcool/Cloutree-Upload |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Bugs & Issues: https://github.com/Foxcool/Cloutree-perl/issues |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |