Sha256: bd26599baa755febaadb9a43a7b990ae4e36d31e40f490ec8489f913bfee7643
Contents?: true
Size: 1.89 KB
Versions: 2
Compression:
Stored size: 1.89 KB
Contents
require 'sinatra' require 'nokogiri' require 'stringio' require_relative './visualizer' module Opener class S3Outlet class Server < Sinatra::Base post '/' do output = S3Output.create(:uuid => params[:request_id], :text => params[:input]) end get '/' do if params[:request_id] redirect "#{url("/")}#{params[:request_id]}" else erb :index end end get '/:request_id' do unless params[:request_id] == 'favicon.ico' begin output = S3Output.find(params[:request_id]) if output content_type(:xml) body(output) else halt(404, "No record found for ID #{params[:request_id]}") end rescue => error error_callback = params[:error_callback] submit_error(error_callback, error.message) if error_callback raise(error) end end end get '/html/:request_id' do unless params[:request_id] == 'favicon.ico' begin output = S3Output.find(params[:request_id]) if output output = StringIO.new(output) parser = Opener::Kaf::Visualizer::Parser.new(output) doc = parser.parse html = Opener::Kaf::Visualizer::HTMLTextPresenter.new(doc) @parsed = html.to_html erb :show else halt(404, "No record found for ID #{params[:request_id]}") end rescue => error error_callback = params[:error_callback] submit_error(error_callback, error.message) if error_callback raise(error) end end end private def submit_error(url, message) HTTPClient.post(url, :body => {:error => message}) end end # Server end # S3Outlet end # Opener
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
opener-s3-outlet-1.1.1 | lib/opener/s3_outlet/server.rb |
opener-s3-outlet-1.1.0 | lib/opener/s3_outlet/server.rb |