#!/usr/bin/perl -w

use strict;
use warnings;
use Carp;

use WebService::Browshot;

my $browshot = WebService::Browshot->new(
	key	=> 'my_api_key',
	debug	=> 0, # no more debug information
);


# You can only host screenshots in finished state
my $list = $browshot->screenshot_list(limit => 1, status => 'finished');

my $screenshot = { };
foreach my $id (keys %$list) {
	$screenshot = $list->{id};
}

if (! exists $screenshot->{id}) {
	print "No screenshot finished\n";
}
else {
	my $result = $browshot->screenshot_host(
	  id => $screenshot->{id}, 
	  hosting => 's3', 
	  bucket => 'my_bucket', 
	  file => 'youtube.png', 
	  width => 600
	); # host a thumbnail
	
	if ($result->{status} eq 'ok') {
		print "The screenshot is now hosted at ", $result->{url}, "\n";
	}
	else {
		print "hosting failed: ", $result->{error}, "\n";
	}
}