Skip to content

Instantly share code, notes, and snippets.

@kastner
Forked from marcel/archive_generator_service.rb
Created July 31, 2008 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kastner/3439 to your computer and use it in GitHub Desktop.
Save kastner/3439 to your computer and use it in GitHub Desktop.
require 'net/http'
require 'uri'
class ScreenShooter
SCREEN_SHOOTER_URL = 'http://www.browsrcamp.com/'
class << self
def screenshot_for(url)
returning new(url) do |shooter|
shooter.shoot
end
end
end
attr_reader :url
def initialize(url)
@url = url
end
def shoot(parameters = {})
@shoot ||= Net::HTTP.post_form(URI.parse(SCREEN_SHOOTER_URL), default_parameters.merge(parameters))
end
def screenshot
@screenshot ||= urls.first
end
def thumbnail
@thumbnail ||= urls.last
end
private
def default_parameters
{
'get' => 1, # Magic, just going with the flow
'width' => 800,
'quality' => 1, # PNG
'url' => URI.escape(url)
}
end
def urls
@urls ||= shoot.body.scan /http\S+safaritest\S+\.png/
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment