Permalink
Browse files

Merge branch 'first'

  • Loading branch information...
2 parents 2b29e9c + 0c54c3d commit 00fb5cdce1bc3f83bc4c550e993391775f3dc8ff @mnewt committed Jun 4, 2012
View
2 Gemfile
@@ -21,6 +21,8 @@ group :assets do
end
gem 'jquery-rails'
+gem 'haml'
+gem 'typhoeus'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
View
5 Gemfile.lock
@@ -40,6 +40,7 @@ GEM
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
+ haml (3.1.6)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
@@ -94,6 +95,8 @@ GEM
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
+ typhoeus (0.3.3)
+ mime-types
tzinfo (0.3.33)
uglifier (1.2.4)
execjs (>= 0.3.0)
@@ -104,8 +107,10 @@ PLATFORMS
DEPENDENCIES
coffee-rails (~> 3.2.1)
+ haml
jquery-rails
rails (= 3.2.5)
sass-rails (~> 3.2.3)
sqlite3
+ typhoeus
uglifier (>= 1.0.3)
View
3 app/assets/javascripts/proxy.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3 app/assets/stylesheets/proxy.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Proxy controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
38 app/controllers/proxy_controller.rb
@@ -0,0 +1,38 @@
+
+class ProxyController < ApplicationController
+ def main
+ require 'rubygems'
+ require 'typhoeus'
+ require 'json'
+
+ # the request object
+ request = Typhoeus::Request.new("http://mnewton.com")
+ # :body => "this is a request body",
+ # :method => :post,
+ # :headers => {:Accept => "text/html"},
+ # :timeout => 100, # milliseconds
+ # :cache_timeout => 60, # seconds
+ # :params => {:field1 => "a field"})
+ # we can see from this that the first argument is the url. the second is a set of options.
+ # the options are all optional. The default for :method is :get. Timeout is measured in milliseconds.
+ # cache_timeout is measured in seconds.
+
+ # Run the request via Hydra.
+ hydra = Typhoeus::Hydra.new
+ hydra.queue(request)
+ hydra.run
+
+ # the response object will be set after the request is run
+ response = request.response
+ @body = response.body
+ # 1. create header view - should it be a partial or its own controller?
+ # 2. create js parser/inserter
+ # 3. stick header and parser in response.body before sending to view
+
+ # response.code # http status code
+ # response.time # time in seconds the request took
+ # response.headers # the http headers
+ # response.headers_hash # http headers put into a hash
+ # response.body # the response body
+ end
+end
View
2 app/helpers/proxy_helper.rb
@@ -0,0 +1,2 @@
+module ProxyHelper
+end
View
2 app/views/proxy/main.html.haml
@@ -0,0 +1,2 @@
+= raw @body
+
View
2 config/routes.rb
@@ -1,4 +1,6 @@
Proxy::Application.routes.draw do
+ get "proxy/main"
+
# The priority is based upon order of creation:
# first created -> highest priority.
View
43 light-proxy.rb
@@ -0,0 +1,43 @@
+require 'rubygems'
+require 'typhoeus'
+require 'json'
+
+# the request object
+request = Typhoeus::Request.new("http://www.pauldix.net")
+ # :body => "this is a request body",
+ # :method => :post,
+ # :headers => {:Accept => "text/html"},
+ # :timeout => 100, # milliseconds
+ # :cache_timeout => 60, # seconds
+ # :params => {:field1 => "a field"})
+# we can see from this that the first argument is the url. the second is a set of options.
+# the options are all optional. The default for :method is :get. Timeout is measured in milliseconds.
+# cache_timeout is measured in seconds.
+
+# Run the request via Hydra.
+hydra = Typhoeus::Hydra.new
+hydra.queue(request)
+hydra.run
+
+# the response object will be set after the request is run
+response = request.response
+response.code # http status code
+response.time # time in seconds the request took
+response.headers # the http headers
+response.headers_hash # http headers put into a hash
+response.body # the response body
+
+puts "response.code:"
+puts response.code
+puts
+puts "response.time:"
+puts response.time
+puts
+puts "response.headers:"
+puts response.headers
+puts
+puts "response.headers_hash:"
+puts response.headers_hash
+puts
+puts "response.body:"
+puts response.body

0 comments on commit 00fb5cd

Please sign in to comment.