#!/usr/bin/env ruby

require 'browshot'

browshot = Browshot.new('my_api_key', true)



# You can only host screenshots in finished state
list = browshot.screenshot_list({ 'limit' => 1, 'status' => 'finished' })

if (list.count == 0)
	puts "No screenshot finished\n"
else
  id = 0
  list.each { |key, screenshot|
    id = key
  }
  
  result = browshot.screenshot_host(id, 's3', {
    'bucket' => 'my_bucket', 
    'file' => 'youtube.png', 
    'width' => 600
  }) # host a thumbnail
  
  if (result['status'] == 'ok')
    puts "The screenshot is now hosted at #{result['url']}\n"
  else
    print "hosting failed: #{result['error']}\n"
  end
end