Created
July 31, 2008 12:21
-
-
Save marcel/3438 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
class ArchiveGeneratorService | |
class << self | |
def update | |
returning new do |generator| | |
generator.generate | |
generator.upload | |
end | |
end | |
end | |
attr_reader :year, :month, :screenshot | |
def initialize | |
@year = ENV['YEAR'] || Time.now.year.to_s | |
@month = ENV['MONTH'] || Time.now.month.to_s | |
end | |
def generate | |
@screenshot ||= ScreenShooter.screenshot_for(month_permalink_url) | |
end | |
def upload | |
ProjectionistS3Object.store( | |
ProjectionistS3Object.archive_image_key_for(year, month), | |
open(screenshot.thumbnail), | |
:access => :public_read | |
) | |
end | |
private | |
def month_permalink_url | |
"http://project.ioni.st/#{year}/#{month}?hide_chrome=1" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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