Skip to content

Instantly share code, notes, and snippets.

@PlasticLizard
Created July 5, 2011 20:28
Show Gist options
  • Save PlasticLizard/1065840 to your computer and use it in GitHub Desktop.
Save PlasticLizard/1065840 to your computer and use it in GitHub Desktop.
Formatter woes
require 'msgpack'
module Goliath
module Rack
module Formatters
# A MessagePack formatter.
# @example
# use Goliath::Rack::Formatters::MSGPACK
class MSGPACK
include AsyncMiddleware
def post_process(env, status, headers, body)
if msgpack_response?(headers)
body = [MessagePack.pack(body)]
end
[status, headers, body]
end
def msgpack_response?(headers)
headers['Content-Type'] =~ %r{^application/msgpack}
end
end
end
end
end
require 'rubygems'
require 'bundler'
Bundler.setup(:default)
require 'goliath'
require 'wonkavision'
require "wonkavision/analytics/persistence/em_mongo"
dir = File.dirname(__FILE__)
appdir = File.join(dir,"app")
#load the msgpack formatter
require File.join( dir, "goliath/rack/formatters/msgpack")
class Query < Goliath::API
def execute_query(env)
{:some => :hash}
end
def response(env)
cellset = execute_query(env)
[200, {}, cellset]
end
end
class RpmAnalytics < Goliath::API
use Goliath::Rack::Tracer
use Goliath::Rack::DefaultMimeType
use Goliath::Rack::Render, 'json', 'msgpack'
use Goliath::Rack::Heartbeat
use Goliath::Rack::Params
get '/query/:aggregation' do
run Query.new
end
get '/*glob' do
run Proc.new { |env| [404,{},"Not Found"] }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment