Permalink
Browse files

Version bump to 0.2.0

  • Loading branch information...
1 parent 287809b commit c75c838741fe6979665e96d7bd7c00f789191177 @brunogh committed Jun 12, 2012
Showing with 139 additions and 40 deletions.
  1. +0 −4 Gemfile
  2. +10 −7 README.rdoc
  3. +1 −1 VERSION
  4. +18 −0 lib/tor/configuration.rb
  5. +19 −0 lib/tor/http.rb
  6. +19 −0 lib/tor/tor_requests.rb
  7. +0 −19 lib/tor_requests.rb
  8. +28 −0 spec/configuration_spec.rb
  9. +19 −0 spec/http_spec.rb
  10. +22 −0 spec/integration_spec.rb
  11. +3 −1 spec/spec_helper.rb
  12. +0 −8 spec/tor_requests_spec.rb
View
@@ -10,10 +10,6 @@ group :development do
gem "rdoc", "~> 3.12"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.8.3"
- # gem "rcov", ">= 0"
gem "simplecov"
gem "socksify"
-
-# require 'net/http'
-# require 'socksify/http'
end
View
@@ -2,23 +2,26 @@
1 - Install Tor
-* https://www.torproject.org
-* On Settings -> Advanced -> Fix the port to 9051
+* Download at https://www.torproject.org
+* Start Tor
+* You can change port configuration following On Settings -> Advanced -> Fix the port to 9051
2 - Ruby code
- res = Request.http("google.com")
+ res = Tor::HTTP.get("google.com", 80, "/")
p res.code
p res.body
OR
- res = Request.http("google.com", 80, "/")
+ res = Tor::HTTP.get("google.com")
-== Backlog
+Default configuration is port 9050 and ip 127.0.0.1. If you need to change configuration, you can call:
-* HTTPS
-* Making the running Tor port configurable
+ Tor.configure do |config|
+ config.ip = "127.0.0.1"
+ config.port = 9050
+ end
== Contributing to tor_requests
View
@@ -1 +1 @@
-0.1.0
+0.2.0
@@ -0,0 +1,18 @@
+require 'net/http'
+require 'socksify/http'
+
+module Tor
+
+ class Configuration
+
+ attr_accessor :ip,
+ :port
+
+ def initialize
+ @ip = '127.0.0.1'
+ @port = 9050
+ end
+
+ end
+
+end
View
@@ -0,0 +1,19 @@
+require 'net/http'
+require 'socksify/http'
+
+module Tor
+
+ class HTTP
+
+ def self.get(host, port = 80, path = "/")
+ res = ""
+ Net::HTTP.SOCKSProxy(Tor.configuration.ip, Tor.configuration.port).start(host, port) do |http|
+ res = http.get(path)
+ end
+ res
+ end
+
+ end
+
+end
+
@@ -0,0 +1,19 @@
+module Tor
+ class << self
+ def configuration
+ config
+ end
+
+ def configure
+ config
+ yield(configuration)
+ end
+
+ private
+
+ def config
+ @onfiguration ||= Configuration.new
+ end
+
+ end
+end
View
@@ -1,19 +0,0 @@
-require 'net/http'
-require 'socksify/http'
-
-class Request
-
- class << self
-
- def http(host, port = 80, path = "/")
- res = ""
- Net::HTTP.SOCKSProxy('127.0.0.1', 9050).start(host, port) do |http|
- res = http.get(path)
- end
- res
- end
-
- end
-
-end
-
@@ -0,0 +1,28 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+
+describe "Configure" do
+
+ it "default port" do
+ Tor::Configuration.new.port.should eq(9050)
+ end
+
+ it "default ip" do
+ Tor::Configuration.new.ip.should eq('127.0.0.1')
+ end
+
+ context "initialize" do
+ it "default port" do
+ config = Tor::Configuration.new
+ config.port = 99
+ config.port.should eq(99)
+ end
+
+ it "default ip" do
+ config = Tor::Configuration.new
+ config.ip = "whatever"
+ config.ip.should eq("whatever")
+ end
+ end
+
+end
View
@@ -0,0 +1,19 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+
+describe "Http" do
+
+ describe "get" do
+ it "default params" do
+ res = Tor::HTTP.get("google.com")
+ res.code.should eq("301")
+ end
+
+ it "makes a HTTP request to Google" do
+ res = Tor::HTTP.get("google.com", 80, "/")
+ res.code.should eq("301")
+ end
+
+ end
+
+end
@@ -0,0 +1,22 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+require 'net/http'
+require 'socksify/http'
+
+describe "Configure" do
+
+ context "different values" do
+ it "calls correctly" do
+
+ Tor.configure do |config|
+ config.ip = "a"
+ config.port = 9051
+ end
+
+ proxy = Net::HTTP.SOCKSProxy("127.0.0.1", 9050)
+ proxy.stub(:start)
+ Net::HTTP.should_receive(:SOCKSProxy).with("a", 9051).and_return( proxy)
+ Tor::HTTP.get("google.com")
+ end
+ end
+
+end
View
@@ -1,7 +1,9 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
-require 'tor_requests'
+require 'tor/http'
+require 'tor/configuration'
+require 'tor/tor_requests'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
@@ -1,8 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-
-describe "TorRequests" do
- it "makes a HTTP request to Google" do
- res = Request.new.http("google.com", 80, "/")
- res.code.should eq("301")
- end
-end

0 comments on commit c75c838

Please sign in to comment.