| 1 | package Brightcove::MAPI; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Brightcove Media API Wrapper | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = '0.1'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Any::Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | has read_api_url => ( | |||||||||||||||||||||||||||
| 13 | is => 'rw', | ||||||||||||||||||||||||||||
| 14 | required=> 1, | ||||||||||||||||||||||||||||
| 15 | default => 'https://api.brightcove.com/services/library', | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | has write_api_url => ( | |||||||||||||||||||||||||||
| 19 | is => 'rw', | ||||||||||||||||||||||||||||
| 20 | required=> 1, | ||||||||||||||||||||||||||||
| 21 | default => 'https://api.brightcove.com/services/post', | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | has token => ( | |||||||||||||||||||||||||||
| 25 | is => 'rw', | ||||||||||||||||||||||||||||
| 26 | required=> 1, | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | has user_agent => ( | ||||||||||||||||||||||||||||
| 30 | is => 'ro', | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 32 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 33 | 0 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||||||||||
| 34 | 0 | $ua->agent(__PACKAGE__.'/'.$VERSION); | |||||||||||||||||||||||||||
| 35 | 0 | return $ua; | |||||||||||||||||||||||||||
| 36 | }, | ||||||||||||||||||||||||||||
| 37 | 1 | ); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 42 | 0 | my $command = shift; | |||||||||||||||||||||||||||
| 43 | 0 | ▶ | my $params = shift || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= 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 | ▶ | if ($res->is_success) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | return decode_json($res->decoded_content); | |||||||||||||||||||||||||||
| 54 | } else { | ||||||||||||||||||||||||||||
| 55 | 0 | confess $res->status_line; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub post { | ||||||||||||||||||||||||||
|
Subroutine
post: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 62 | 0 | my $method = shift; | |||||||||||||||||||||||||||
| 63 | 0 | ▶ | my $params = shift || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= 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 | ▶ | if (defined($file) and -f $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $file and -f $file
MC/DC0%0/2
defined $file and -f $file
defined $file
-f $file
Truth table0%0/3
A and B
A= defined $fileB= -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 | ▶ | if ($res->is_success) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 1; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | __END__ | ||||||||||||||||||||||||||||