Skip to content

Commit

Permalink
Merge pull request #31 from oklahomer/feature/support_captions_file
Browse files Browse the repository at this point in the history
Support captions file
  • Loading branch information
oklahomer committed Oct 22, 2019
2 parents 297367a + 18952ba commit 34a3636
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lib/Facebook/OpenGraph.pm
Expand Up @@ -451,8 +451,11 @@ sub request {

my $content = q{};
if ($method eq 'POST') {
if ($param_ref->{source} || $param_ref->{file} || $param_ref->{upload_phase} ) {
# post image or video file
if ($param_ref->{source}
|| $param_ref->{file}
|| $param_ref->{upload_phase}
|| $param_ref->{captions_file}) {
# post image, video or caption file

# https://developers.facebook.com/docs/reference/api/video/
# When posting a video, use graph-video.facebook.com .
Expand Down Expand Up @@ -576,16 +579,11 @@ sub prep_param {
$param_ref->{permissions} = ref $perms ? join q{,}, @$perms : $perms;
}

# Source, file and video_file_chunk parameter contains file path.
# Source, file, video_file_chunk and captions_file parameter contains file path.
# It must be an array ref to work with HTTP::Request::Common.
if (my $path = $param_ref->{source}) {
$param_ref->{source} = ref $path ? $path : [$path];
}
if (my $path = $param_ref->{file}) {
$param_ref->{file} = ref $path ? $path : [$path];
}
if (my $path = $param_ref->{video_file_chunk}) {
$param_ref->{video_file_chunk} = ref $path ? $path : [$path];
for my $file (qw/source file video_file_chunk captions_file/) {
next unless my $path = $param_ref->{$file};
$param_ref->{$file} = ref $path ? $path : [$path];
}

# use Field Expansion
Expand Down
50 changes: 50 additions & 0 deletions t/003_publish/03_post_movie.t
Expand Up @@ -188,4 +188,54 @@ subtest 'transfer chunked file content with Resumable' => sub {

};

subtest 'post captioned movie' => sub {

$Mock_furl_http->mock(
request => sub {
my ($mock, %args) = @_;

ok delete $args{content}, 'content'; # too huge to compare, so just check if it's given
is_deeply(
\%args,
+{
url => 'https://graph.facebook.com/video_id_12345/captions',
method => 'POST',
headers => [
'Authorization' => 'OAuth 12345qwerty',
'Content-Length' => 254,
'Content-Type' => 'multipart/form-data; boundary=xYzZY',
],
},
'args'
);

return (
1,
200,
'OK',
['Content-Type' => 'text/javascript; charset=UTF-8'],
encode_json(+{
success => JSON::true,
}),
);

},
);

my $fb = Facebook::OpenGraph->new(+{
app_id => 12345678,
access_token => '12345qwerty',
});
my $response = $fb->publish(
'/video_id_12345/captions',
+{
captions_file => './t/resource/captions.ja_JP.srt',
default_locale => 'ja_JP',
}
);

is_deeply $response, +{ success => JSON::true }, 'response';

};

done_testing;
3 changes: 3 additions & 0 deletions t/resource/captions.ja_JP.srt
@@ -0,0 +1,3 @@
1
00:00:00,000 --> 00:00:03,000
Hello, world!

0 comments on commit 34a3636

Please sign in to comment.