| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Brightcove::MAPI; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Brightcove Media API Wrapper |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.1'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
25545
|
use URI; |
|
|
1
|
|
|
|
|
8058
|
|
|
|
1
|
|
|
|
|
26
|
|
|
8
|
1
|
|
|
1
|
|
1053
|
use JSON; |
|
|
1
|
|
|
|
|
14654
|
|
|
|
1
|
|
|
|
|
7
|
|
|
9
|
1
|
|
|
1
|
|
1194
|
use Any::Moose; |
|
|
1
|
|
|
|
|
39548
|
|
|
|
1
|
|
|
|
|
6
|
|
|
10
|
1
|
|
|
1
|
|
5135
|
use LWP::UserAgent; |
|
|
1
|
|
|
|
|
55525
|
|
|
|
1
|
|
|
|
|
472
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has read_api_url => ( |
|
13
|
|
|
|
|
|
|
is => 'rw', |
|
14
|
|
|
|
|
|
|
required=> 1, |
|
15
|
|
|
|
|
|
|
default => 'https://api.brightcove.com/services/library', |
|
16
|
|
|
|
|
|
|
); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has write_api_url => ( |
|
19
|
|
|
|
|
|
|
is => 'rw', |
|
20
|
|
|
|
|
|
|
required=> 1, |
|
21
|
|
|
|
|
|
|
default => 'https://api.brightcove.com/services/post', |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has token => ( |
|
25
|
|
|
|
|
|
|
is => 'rw', |
|
26
|
|
|
|
|
|
|
required=> 1, |
|
27
|
|
|
|
|
|
|
); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has user_agent => ( |
|
30
|
|
|
|
|
|
|
is => 'ro', |
|
31
|
|
|
|
|
|
|
default => sub { |
|
32
|
|
|
|
|
|
|
my $self = shift; |
|
33
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
|
34
|
|
|
|
|
|
|
$ua->agent(__PACKAGE__.'/'.$VERSION); |
|
35
|
|
|
|
|
|
|
return $ua; |
|
36
|
|
|
|
|
|
|
}, |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get { |
|
41
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
42
|
0
|
|
|
|
|
|
my $command = shift; |
|
43
|
0
|
|
0
|
|
|
|
my $params = shift || {}; |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$params->{command} = $command; |
|
46
|
0
|
|
|
|
|
|
$params->{token} = $self->token; |
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $url = URI->new($self->read_api_url); |
|
49
|
0
|
|
|
|
|
|
$url->query_form(%$params); |
|
50
|
0
|
|
|
|
|
|
my $res = $self->user_agent->get($url->as_string); |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
if ($res->is_success) { |
|
53
|
0
|
|
|
|
|
|
return decode_json($res->decoded_content); |
|
54
|
|
|
|
|
|
|
} else { |
|
55
|
0
|
|
|
|
|
|
confess $res->status_line; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub post { |
|
61
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
62
|
0
|
|
|
|
|
|
my $method = shift; |
|
63
|
0
|
|
0
|
|
|
|
my $params = shift || {}; |
|
64
|
0
|
|
|
|
|
|
my $file = shift; |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$params->{token} = $self->token; |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my $jsonrpc = encode_json({ |
|
69
|
|
|
|
|
|
|
method => $method, |
|
70
|
|
|
|
|
|
|
params => $params, |
|
71
|
|
|
|
|
|
|
}); |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my $res; |
|
74
|
0
|
0
|
0
|
|
|
|
if (defined($file) and -f $file) { |
|
75
|
0
|
|
|
|
|
|
$res = $self->user_agent->post( |
|
76
|
|
|
|
|
|
|
$self->write_api_url, |
|
77
|
|
|
|
|
|
|
Content_Type => 'form-data', |
|
78
|
|
|
|
|
|
|
Content => [ |
|
79
|
|
|
|
|
|
|
json => $jsonrpc, |
|
80
|
|
|
|
|
|
|
file => [ $file ] |
|
81
|
|
|
|
|
|
|
] |
|
82
|
|
|
|
|
|
|
); |
|
83
|
|
|
|
|
|
|
} else { |
|
84
|
0
|
|
|
|
|
|
$res = $self->user_agent->post( |
|
85
|
|
|
|
|
|
|
$self->write_api_url, |
|
86
|
|
|
|
|
|
|
Content => [ json => $jsonrpc ] |
|
87
|
|
|
|
|
|
|
); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
if ($res->is_success) { |
|
91
|
0
|
|
|
|
|
|
my $content = $res->decoded_content; |
|
92
|
0
|
|
|
|
|
|
return decode_json($content); |
|
93
|
|
|
|
|
|
|
} else { |
|
94
|
0
|
|
|
|
|
|
confess $res->status_line; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__END__ |