diff --git a/lib/Facebook/OpenGraph.pm b/lib/Facebook/OpenGraph.pm index 34f9c5d..1a9b5c1 100644 --- a/lib/Facebook/OpenGraph.pm +++ b/lib/Facebook/OpenGraph.pm @@ -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 . @@ -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 diff --git a/t/003_publish/03_post_movie.t b/t/003_publish/03_post_movie.t index 532944d..0e858ff 100644 --- a/t/003_publish/03_post_movie.t +++ b/t/003_publish/03_post_movie.t @@ -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; diff --git a/t/resource/captions.ja_JP.srt b/t/resource/captions.ja_JP.srt new file mode 100644 index 0000000..8a9815d --- /dev/null +++ b/t/resource/captions.ja_JP.srt @@ -0,0 +1,3 @@ +1 +00:00:00,000 --> 00:00:03,000 +Hello, world!