Permalink
Browse files

Some changes to make it our own.

* Basic auth protect hurl creating/deletion.
* Change & remove some copy
* Homepage is a list of Hurls instead of a new hurl form.
* Require libs with Bundler
* Remove some routes and rake tasks that we don't need.
* Remove example hurls
  • Loading branch information...
brianjlandau committed Mar 7, 2012
1 parent 2087654 commit bfa18acc84393e00a84987c310019bdcacd23679
View
@@ -2,3 +2,6 @@ db/
.bundle/
bin/
.rvmrc
+.powenv
+tmp/**/*
+tmp/*
View
@@ -1,11 +1,12 @@
source :rubygems
-gem 'sinatra', '~>1.0'
-gem 'yajl-ruby', '~>1.1.0'
-gem 'mustache', '~>0.11.2'
+gem 'sinatra', '~>1.0', :require => 'sinatra/base'
+gem 'yajl-ruby', '~>1.1.0', :require => 'yajl'
+gem 'mustache', '~>0.11.2', :require => 'mustache/sinatra'
gem 'curb', '~>0.7.8'
gem 'coderay', '~>0.8.357'
gem 'couchrest', '~>1.0'
+gem 'sinatra-basic-auth', :require => "sinatra/basic_auth"
group :test do
gem 'shotgun'
View
@@ -20,6 +20,8 @@ GEM
sinatra (1.1.0)
rack (~> 1.1)
tilt (~> 1.1)
+ sinatra-basic-auth (0.1.0)
+ sinatra
tilt (1.1)
unicorn (4.2.0)
kgio (~> 2.6)
@@ -37,5 +39,6 @@ DEPENDENCIES
mustache (~> 0.11.2)
shotgun
sinatra (~> 1.0)
+ sinatra-basic-auth
unicorn
yajl-ruby (~> 1.1.0)
View
@@ -9,7 +9,9 @@ Now Hurl is an open source project for your enjoyment.
This Fork
---------
-I forked hurl to work on Heroku & CouchDB.
+* [benatkin](https;//github.com/benatkin) forked hurl to work on Heroku & CouchDB.
+* [localtoast](https;//github.com/localtoast) forked it to make it single user.
+* [brianjlandau](https;//github.com/brianjlandau) changed some of the copy & removed the examples and added HTTP Basic auth for creating and deleting hurls.
Installation
------------
@@ -40,22 +42,13 @@ Run On Heroku & CouchDB
First get a CouchDB database and get the url, including auth. I got my
DB from [Cloudant](https://cloudant.com/).
- heroku create
- heroku rename my-clever-name
- heroku config:add 'COUCH_URL=https://bat:password@bat.cloudant.com/benhurl/'
-
-Now you can go to [http://my-clever-name.heroku.com/](http://my-clever-name.heroku.com/)
-
-To enable github login, register a github app with the callback `http://my-clever-name.heroku.com/login/callback/` and add your configuration:
-
- heroku config:add 'HURL_CLIENT_ID=your_client_id'
- heroku config:add 'HURL_SECRET=your_secret'
-
-Issues
-------
+ git clone git://github.com/vigetlabs/hurl.git
+ cd hurl
+ heroku create my-clever-name --stack cedar
+ heroku addons:add cloudant:oxygen
+ git push heroku master
-Find a bug? Want a feature? Submit an [issue
-here](http://github.com/defunkt/hurl/issues). Patches welcome!
+Now you can go to [http://my-clever-name.herokuapp.com/](http://my-clever-name.herokuapp.com/)
Screenshot
View
@@ -1,36 +1,7 @@
namespace :hurl do
desc "Start Hurl for development"
task :start do
- exec "bundle exec shotgun config.ru"
- end
-
- desc "Generate GitHub pages."
- task :pages => :check_dirty do
- require "mustache"
- require "rdiscount"
- view = Mustache.new
- view.template = File.read("docs/index.mustache")
- view[:content] = Markdown.new(File.read("README.md")).to_html
- File.open("new_index.html", "w") do |f|
- f.puts view.render
- end
- system "git checkout gh-pages"
- system "git pull origin gh-pages"
- system "mv new_index.html index.html"
- system "git commit -a -m 'auto update docs'"
- system "git push origin gh-pages"
- system "git checkout master"
- end
-
- task :check_dirty do
- if `git status -a` && $?.success?
- abort "dirty index - not publishing!"
- end
- end
-
- desc "Please pardon our dust."
- task :deploy do
- exec "ssh deploy@hurl.it 'cd /www/hurl && git fetch origin && git reset --hard origin/master && rake bundle && touch tmp/restart.txt'"
+ exec "bundle exec unicorn -p 3030 -c ./unicorn.rb"
end
end
View
@@ -3,6 +3,7 @@
module Hurl
class App < Sinatra::Base
register Mustache::Sinatra
+ register Sinatra::BasicAuth
helpers Hurl::Helpers
dir = File.dirname(File.expand_path(__FILE__))
@@ -23,9 +24,11 @@ class App < Sinatra::Base
def initialize(*args)
super
@debug = ENV['DEBUG']
- setup_default_hurls
end
+ authorize do |username, password|
+ username == ENV['BASIC_AUTH_USERNAME'] && password == ENV['BASIC_AUTH_PASSWORD']
+ end
#
# routes
@@ -37,51 +40,44 @@ def initialize(*args)
end
get '/' do
- @hurl = params
- mustache :index
- end
-
- get '/hurls/?' do
@hurls = @user.hurls
mustache :hurls
end
+
+ protect do
+ get '/hurls/new/?' do
+ @hurl = params
+ mustache :hurl_form
+ end
+ end
get '/hurls/:id/?' do
@hurl = find_hurl(params[:id])
@view = find_view(params[:id])
- @hurl ? mustache(:index) : not_found
+ @hurl ? mustache(:hurl_form) : not_found
end
-
- delete '/hurls/:id/?' do
-
- if @hurl = find_hurl(params[:id])
- @user.remove_hurl(@hurl['id'])
+
+ protect do
+ delete '/hurls/:id/?' do
+ if @hurl = find_hurl(params[:id])
+ @user.remove_hurl(@hurl['id'])
+ end
+ request.xhr? ? "ok" : redirect('/')
end
- request.xhr? ? "ok" : redirect('/')
end
get '/hurls/:id/:view_id/?' do
@hurl = find_hurl(params[:id])
@view = find_view(params[:view_id])
@view_id = params[:view_id]
- @hurl && @view ? mustache(:index) : not_found
+ @hurl && @view ? mustache(:hurl_form) : not_found
end
get '/views/:id/?' do
@view = find_view(params[:id])
@view ? mustache(:view, :layout => false) : not_found
end
- get '/test.json' do
- content_type 'application/json'
- File.read('test/json')
- end
-
- get '/test.xml' do
- content_type 'application/xml'
- File.read('test/xml')
- end
-
get '/about/?' do
mustache :about
end
@@ -90,68 +86,70 @@ def initialize(*args)
mustache :stats
end
- post '/' do
- return json(:error => "Calm down and try my margarita! (rate limited)") if rate_limited?
-
- url, method, auth = params.values_at(:url, :method, :auth)
+ protect do
+ post '/' do
+ return json(:error => "Calm down and try my margarita! (rate limited)") if rate_limited?
- return json(:error => "That's... wait.. what?! (invalid URL)") if invalid_url?(url)
+ url, method, auth = params.values_at(:url, :method, :auth)
- curl = Curl::Easy.new(url)
-
- sent_headers = []
- curl.on_debug do |type, data|
- # track request headers
- sent_headers << data if type == Curl::CURLINFO_HEADER_OUT
- end
+ return json(:error => "That's... wait.. what?! (invalid URL)") if invalid_url?(url)
- curl.follow_location = true if params[:follow_redirects]
+ curl = Curl::Easy.new(url)
- # ensure a method is set
- method = (method.to_s.empty? ? 'GET' : method).upcase
+ sent_headers = []
+ curl.on_debug do |type, data|
+ # track request headers
+ sent_headers << data if type == Curl::CURLINFO_HEADER_OUT
+ end
- # update auth
- add_auth(auth, curl, params)
+ curl.follow_location = true if params[:follow_redirects]
- # arbitrary headers
- add_headers_from_arrays(curl, params["header-keys"], params["header-vals"])
+ # ensure a method is set
+ method = (method.to_s.empty? ? 'GET' : method).upcase
- # arbitrary post params
- if params['post-body'] && ['POST', 'PUT'].index(method)
- post_data = [params['post-body']]
- else
- post_data = make_fields(method, params["param-keys"], params["param-vals"])
- end
+ # update auth
+ add_auth(auth, curl, params)
- begin
- debug { puts "#{method} #{url}" }
+ # arbitrary headers
+ add_headers_from_arrays(curl, params["header-keys"], params["header-vals"])
- if method == 'PUT'
- curl.http_put(stringify_data(post_data))
+ # arbitrary post params
+ if params['post-body'] && ['POST', 'PUT'].index(method)
+ post_data = [params['post-body']]
else
- curl.send("http_#{method.downcase}", *post_data)
+ post_data = make_fields(method, params["param-keys"], params["param-vals"])
end
- debug do
- puts sent_headers.join("\n")
- puts post_data.join('&') if post_data.any?
- puts curl.header_str
+ begin
+ debug { puts "#{method} #{url}" }
+
+ if method == 'PUT'
+ curl.http_put(stringify_data(post_data))
+ else
+ curl.send("http_#{method.downcase}", *post_data)
+ end
+
+ debug do
+ puts sent_headers.join("\n")
+ puts post_data.join('&') if post_data.any?
+ puts curl.header_str
+ end
+
+ header = pretty_print_headers(curl.header_str)
+ type = url =~ /(\.js)$/ ? 'js' : curl.content_type
+ body = pretty_print(type, curl.body_str)
+ request = pretty_print_requests(sent_headers, post_data)
+
+ hurl_id = save_hurl(params)
+ json :header => header,
+ :body => body,
+ :request => request,
+ :hurl_id => hurl_id,
+ :prev_hurl => @user ? @user.second_to_last_hurl_id : nil,
+ :view_id => save_view(hurl_id, header, body, request)
+ rescue => e
+ json :error => CGI::escapeHTML(e.to_s)
end
-
- header = pretty_print_headers(curl.header_str)
- type = url =~ /(\.js)$/ ? 'js' : curl.content_type
- body = pretty_print(type, curl.body_str)
- request = pretty_print_requests(sent_headers, post_data)
-
- hurl_id = save_hurl(params)
- json :header => header,
- :body => body,
- :request => request,
- :hurl_id => hurl_id,
- :prev_hurl => @user ? @user.second_to_last_hurl_id : nil,
- :view_id => save_view(hurl_id, header, body, request)
- rescue => e
- json :error => CGI::escapeHTML(e.to_s)
end
end
View
@@ -57,18 +57,5 @@ def prev_hurl
nil
end
end
-
- # creates the hurls shown on the front page if they're not in the db
- def setup_default_hurls
- default_hurls.each do |name, params|
- save_hurl(params)
- end
- end
-
- def default_hurls
- return @default_hurls if @default_hurls
- path = File.expand_path(App.root + '/hurls.yaml')
- @default_hurls = YAML.load_file(path)
- end
end
end
View
@@ -9,12 +9,11 @@
require 'zlib'
require "rexml/document"
+require 'rubygems'
+require 'bundler/setup'
+
# bundled gems
-require 'sinatra/base'
-require 'yajl'
-require 'curb'
-require 'mustache/sinatra'
-require 'coderay'
+Bundler.require(:default, RACK_ENV)
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
@@ -18,8 +18,7 @@ Then view the nicely formatted request and response.</p>
<div class="blurb">
<p>Hurl was created by <a href="http://ozmm.org/">Chris Wanstrath</a> and <a href="http://leahculver.com/">Leah Culver</a>
for the 2009 <a href="http://r09.railsrumble.com/">Rails Rumble</a>.</p>
- <p>Follow Hurl on Twitter: <a href="http://twitter.com/hurlit">@hurlit</a></p>
- <p>Grab the source code: <a href="http://github.com/defunkt/hurl">http://github.com/defunkt/hurl</a></p>
+ <p>Grab the source code: <a href="https://github.com/vigetlabs/hurl">https://github.com/vigetlabs/hurl</a></p>
<br/>
- <p>... and it's kind of like <a href="http://curl.haxx.se/">cURL</a>.</p>
+ <p>... and it's kind of like <a href="http://curl.haxx.se/">cURL</a>, but in HTML.</p>
</div>
@@ -108,16 +108,6 @@
<p>Perfect for demoing and debugging APIs.</p>
</div>
</div>
-<div class="help-blurb" {{# try_it_hidden? }}style="display: none;"{{/ try_it_hidden? }}>
- <div id="try-it">
- <h4>Try it out:</h4>
- <ul class="examples">
- {{# default_hurls }}
- <li class="{{ class }}"><a href="/hurls/{{ sha }}">{{ name }}</a></li>
- {{/ default_hurls }}
- </ul>
- </div>
-</div>
<div id="request-and-response" {{# hide_request_and_response? }}style="display:none;"{{/ hide_request_and_response? }}>
<div class="utils">
<a href="{{ view_permalink }}" class="full-size-link nav-item" target="_blank">view full size</a>
@@ -1,4 +1,4 @@
-<h2>Your hurls</h2>
+<h2>hurls</h2>
{{# any_hurls?}}
<table id="archive">
{{# hurls}}
Oops, something went wrong.

0 comments on commit bfa18ac

Please sign in to comment.