forked from postrank-labs/goliath
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring aroundware, Part V: Moved all the aroundware examples ove…
…r to use the new aroundware, doing necessary cleanup along the way. * BarrierAroundware now store [req, resp] in the successes / failures hashes * mongo things now work with both old and future em-mongo gems, at the cost of a big conditional 'if' statement in the file * Added enqueue_acceptor to let you enqueue activities that take a block without yielding a deferrable
- Loading branch information
Philip (flip) Kromer
committed
Jul 31, 2011
1 parent
6395370
commit 20122fb
Showing
10 changed files
with
212 additions
and
65 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
source "http://rubygems.org" | ||
|
||
gemspec | ||
gemspec |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,42 @@ | ||
#!/usr/bin/env ruby | ||
$: << File.dirname(__FILE__)+'/../../lib' | ||
require File.dirname(__FILE__)+'/rasterize' | ||
require File.dirname(__FILE__)+'/../favicon' | ||
|
||
require 'goliath' | ||
require 'em-synchrony/em-http' | ||
require 'goliath/deprecated/async_aroundware' | ||
require 'goliath/deprecated/response_receiver' | ||
require 'postrank-uri' | ||
|
||
# | ||
# Aroundware: while the Rasterize API is processing, this uses http://is.gd to | ||
# generate a shortened link, stuffing it in the header. Both requests happen | ||
# simultaneously. | ||
# | ||
class ShortenURL < Goliath::Synchrony::MultiReceiver | ||
class ShortenURL | ||
include Goliath::Rack::BarrierAroundware | ||
SHORTENER_URL_BASE = 'http://is.gd/create.php' | ||
attr_accessor :shortened_url | ||
|
||
def pre_process | ||
target_url = PostRank::URI.clean(env.params['url']) | ||
shortener_request = EM::HttpRequest.new(SHORTENER_URL_BASE).aget(:query => { :format => 'simple', :url => target_url }) | ||
enqueue :shortener, shortener_request | ||
enqueue :shortened_url, shortener_request | ||
return Goliath::Connection::AsyncResponse | ||
end | ||
|
||
def post_process | ||
if successes[:shortener] | ||
headers['X-Shortened-URI'] = successes[:shortener].response | ||
if shortened_url | ||
headers['X-Shortened-URI'] = shortened_url.response | ||
end | ||
[status, headers, body] | ||
end | ||
end | ||
|
||
class RasterizeAndShorten < Rasterize | ||
use Goliath::Rack::Params | ||
use Favicon, File.expand_path(File.dirname(__FILE__)+"/../public/favicon.ico") | ||
use Goliath::Rack::Validation::RequestMethod, %w(GET) | ||
use Goliath::Rack::Validation::RequiredParam, {:key => 'url'} | ||
# | ||
use Goliath::Rack::AsyncAroundware, ShortenURL | ||
use Goliath::Rack::BarrierAroundwareFactory, ShortenURL | ||
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
Oops, something went wrong.