<?php

require 'vendor/autoload.php'; # Composer
# require_once 'Browshot.php'; # or download Browshot.php

$browshot = new Browshot('my_api_key');


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

if(count($list) == 0) {
	echo "No screenshot finished\n";
}
else {
	$id = 0;
	foreach ($list as $key => $data) {
		$id = $key;
	}
	
	$result = $browshot->screenshot_host($id, array(
	  'hosting' => 's3', 
	  'bucket' => 'my_bucket', 
	  'file' => 'youtube.png', 
	  'width' => 600
	)); # host a thumbnail
	
	if ($result->{'status'} == 'ok') {
		echo sprintf("The screenshot is now hosted at %s\n", $result->{'url'});
	}
	else {
		echo sprintf("hosting failed: %s\n", $result->{'error'});
	}
}

?>