line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::PutIo; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION='0.3'; |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
50677
|
use base 'Mojo::Base'; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
3264
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
50712
|
use Mojo::UserAgent; |
|
4
|
|
|
|
|
2200456
|
|
|
4
|
|
|
|
|
58
|
|
8
|
4
|
|
|
4
|
|
1279
|
use Mojo::JSON; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
209
|
|
9
|
4
|
|
|
4
|
|
23
|
use Mojo::URL; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
24
|
|
10
|
4
|
|
|
4
|
|
5214
|
use WebService::PutIo::Result; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
53
|
|
11
|
4
|
|
|
4
|
|
116
|
use Carp qw/croak/; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
1505
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
__PACKAGE__->attr([qw/api_key api_secret/]); |
14
|
|
|
|
|
|
|
__PACKAGE__->attr(ua => sub { Mojo::UserAgent->new; }); |
15
|
|
|
|
|
|
|
__PACKAGE__->attr(json => sub { Mojo::JSON->new; }); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub request { |
18
|
0
|
|
|
0
|
1
|
|
my ($self,$class,$method,%params)=@_; |
19
|
0
|
0
|
0
|
|
|
|
croak "Must set api_key and api_secret" unless $self->api_key && $self->api_secret; |
20
|
0
|
|
0
|
|
|
|
$params ||= (); |
21
|
0
|
|
|
|
|
|
my $data={ |
22
|
|
|
|
|
|
|
api_key => $self->api_key, |
23
|
|
|
|
|
|
|
api_secret => $self->api_secret, |
24
|
|
|
|
|
|
|
params => \%params |
25
|
|
|
|
|
|
|
}; |
26
|
0
|
|
|
|
|
|
my $url=Mojo::URL->new('http://api.put.io/') |
27
|
|
|
|
|
|
|
->path("/v1/$class/$method") |
28
|
|
|
|
|
|
|
->query(method=>$method); |
29
|
0
|
|
|
|
|
|
my $tx=$self->ua->post_form( $url => { request => $self->json->encode($data) } ); |
30
|
0
|
0
|
|
|
|
|
if (my $res=$tx->success) { |
31
|
0
|
|
|
|
|
|
return WebService::PutIo::Result->new( response => $res ); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else { |
34
|
0
|
|
|
|
|
|
my ($message,$code)=$tx->error; |
35
|
0
|
|
|
|
|
|
croak "Request failed($code): $message"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 NAME |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
WebService::PutIo - WebService client for the put.io API |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 SYNOPSIS |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
use WebService::PutIo; |
48
|
|
|
|
|
|
|
my $ua=WebService::PutIo->new(api_key=>'foo',api_secret=>'bar'); |
49
|
|
|
|
|
|
|
my $res=$ua->request('files','list'); |
50
|
|
|
|
|
|
|
foreach my $file (@{$res->results}) { |
51
|
|
|
|
|
|
|
print "Got ". Data::Dumper($file); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 DESCRIPTION |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
This is a simple Web Service client for the ping.io service. See the other |
57
|
|
|
|
|
|
|
sub-classes for the actual API functions you can call. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 api_key |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 api_secret |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
These are the authentication credentials for ping.io. Get them from your |
66
|
|
|
|
|
|
|
account page. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 ua |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
<<<<<<< HEAD |
71
|
|
|
|
|
|
|
The client to use. Defaults to L->new |
72
|
|
|
|
|
|
|
||||||| merged common ancestors |
73
|
|
|
|
|
|
|
The client to use. Defaults to L->new |
74
|
|
|
|
|
|
|
======= |
75
|
|
|
|
|
|
|
The useragent client to use. Defaults to L->new |
76
|
|
|
|
|
|
|
>>>>>>> 09f641cdc79848ee9224fd2f2e60408c9d411d75 |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 json |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
The JSON object to use. Defaults to L->new |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 METHODS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 request <$class>, <$method>, [%params] |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Send an API request. Takes a class to operate on, an API method, and |
87
|
|
|
|
|
|
|
an optional hash of parameters. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 SEE ALSO |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
L, L, L, |
92
|
|
|
|
|
|
|
L, L,L |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 AUTHOR |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Marcus Ramberg, C. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Copyright (C) 2010, Marcus Ramberg. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under |
103
|
|
|
|
|
|
|
the terms of the Artistic License version 2.0. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |