hidemyass 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ only:
3
+ - master
4
+ rvm:
5
+ - 1.9.2
6
+ - 1.9.3
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in hidemyass.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem "rake", ">= 0.8.7"
8
+ end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # HIDE MY ASS!
1
+ # HIDE MY ASS! [![Build Status](https://travis-ci.org/jassa/hidemyass.png)](https://travis-ci.org/jassa/hidemyass)
2
2
 
3
3
  Hide My Ass! fetches and connects to listed proxies at www.hidemyass.com.
4
4
 
@@ -24,7 +24,7 @@ Or install it yourself as:
24
24
  @request = Net::HTTP::Get.new(@uri.request_uri)
25
25
  @request['Referer'] = @uri.host
26
26
 
27
- response = Hidemyass::HTTP.start(@uri.host, @uri.port) do |http|
27
+ response = HideMyAss::HTTP.start(@uri.host, @uri.port) do |http|
28
28
  http.request(@request)
29
29
  end
30
30
 
@@ -34,7 +34,7 @@ Or install it yourself as:
34
34
  This method defaults to return on HTTPSuccess (2xx)
35
35
  If you want more control to follow redirections or whatever, you can retrieve the proxies list and connect manually
36
36
 
37
- Hidemyass.proxies.each do |proxy|
37
+ HideMyAss.proxies.each do |proxy|
38
38
  response = Net::HTTP::Proxy(proxy[:host], proxy[:port]).start(@uri.host, @uri.port) do |http|
39
39
  http.request(@request)
40
40
  end
@@ -43,10 +43,18 @@ If you want more control to follow redirections or whatever, you can retrieve th
43
43
  end
44
44
  end
45
45
 
46
- To try connecting through local machine before trying proxies
46
+ To try connecting through local machine before trying proxies:
47
47
 
48
- Hidemyass.options[:local] = true
49
- Hidemyass::HTTP.start ...
48
+ HideMyAss.options[:local] = true
49
+ HideMyAss::HTTP.start ...
50
+
51
+ To clear the cached proxies on every request (disabled by default):
52
+
53
+ HideMyAss.options[:clear_cache] = true
54
+
55
+ or simply run:
56
+
57
+ HideMyAss.clear_cache
50
58
 
51
59
  ## Contributing
52
60
 
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
- #!/usr/bin/env rake
2
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new do |r|
5
+ r.verbose = false
6
+ end
7
+
8
+ task :default => :spec
data/hidemyass.gemspec CHANGED
@@ -4,7 +4,7 @@ require File.expand_path('../lib/hidemyass/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Javier Saldana"]
6
6
  gem.email = ["javier@tractical.com"]
7
- gem.description = "Hide My Ass! fetches and connects to listed proxies at www.hidemyass.com"
7
+ gem.description = "Hide My Ass! fetches and connects to proxies at http://hidemyass.com"
8
8
  gem.summary = "Hide My Ass! lets you connect anonymously, fetch proxies from hidemyass.com and try each one until a successful connection is made."
9
9
  gem.homepage = "http://github.com/jassa/hidemyass"
10
10
 
@@ -13,7 +13,8 @@ Gem::Specification.new do |gem|
13
13
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
14
  gem.name = "hidemyass"
15
15
  gem.require_paths = ["lib"]
16
- gem.version = Hidemyass::VERSION
16
+ gem.version = HideMyAss::VERSION
17
17
 
18
- gem.add_dependency "nokogiri"
18
+ gem.add_dependency "nokogiri", "~> 1.5.5"
19
+ gem.add_development_dependency "rspec", "~> 2.12.0"
19
20
  end
data/lib/hidemyass.rb CHANGED
@@ -2,15 +2,18 @@ require 'nokogiri'
2
2
  require 'open-uri'
3
3
  require 'net/http'
4
4
  require 'hidemyass/version'
5
+ require 'hidemyass/ip'
5
6
  require 'hidemyass/http'
6
7
  require 'hidemyass/logger'
7
8
  require 'hidemyass/railtie'
8
9
  require 'logger'
9
10
 
10
- module Hidemyass
11
+ module HideMyAss
11
12
  extend Logger
12
13
 
13
- HOST = 'hidemyass.com'
14
+ SITE = "http://hidemyass.com".freeze
15
+ ENDPOINT = "http://hidemyass.com/proxy-list/search-291666".freeze
16
+
14
17
  LOG_PREFIX = '** [hidemyass] '
15
18
 
16
19
  HTTP_ERRORS = [Timeout::Error,
@@ -24,18 +27,26 @@ module Hidemyass
24
27
  def self.options
25
28
  @options ||= {
26
29
  :log => true,
27
- :local => false
30
+ :local => false,
31
+ :clear_cache => false
28
32
  }
29
33
  end
30
34
 
31
35
  def self.proxies
32
- uri = URI.parse('http://%s/proxy-list/search-225729' % HOST)
33
- dom = Nokogiri::HTML(open(uri))
36
+ clear_cache if options[:clear_cache]
37
+ html = Nokogiri::HTML(open(URI.parse(ENDPOINT))) unless @proxies
34
38
 
35
- @proxies ||= dom.xpath('//table[@id="listtable"]/tr').collect do |node|
36
- { port: node.at_xpath('td[3]').content.strip,
37
- host: node.at_xpath('td[2]/span').xpath('text() | *[not(contains(@style,"display:none"))]').
38
- map(&:content).compact.join.to_s }
39
+ @proxies ||= html.xpath('//table[@id="listtable"]/tr').collect do |node|
40
+ ip = HideMyAss::IP.new(node.at_xpath('td[2]/span'))
41
+ next unless ip.valid?
42
+ {
43
+ host: ip.address,
44
+ port: node.at_xpath('td[3]').content.strip
45
+ }
39
46
  end
40
47
  end
48
+
49
+ def self.clear_cache
50
+ @proxies = nil
51
+ end
41
52
  end
@@ -1,31 +1,31 @@
1
- module Hidemyass
1
+ module HideMyAss
2
2
  module HTTP
3
3
  def HTTP.start(address, *arg, &block)
4
- Hidemyass.log 'Connecting to ' + address + ' through:'
4
+ HideMyAss.log 'Connecting to ' + address + ' through:'
5
5
  response = nil
6
6
 
7
- if Hidemyass.options[:local]
7
+ if HideMyAss.options[:local]
8
8
  begin
9
- Hidemyass.log 'localhost...'
9
+ HideMyAss.log 'localhost...'
10
10
  response = Net::HTTP.start(address, *arg, &block)
11
11
  if response.class.ancestors.include?(Net::HTTPSuccess)
12
12
  return response
13
13
  end
14
14
  rescue *HTTP_ERRORS => error
15
- Hidemyass.log error
15
+ HideMyAss.log error
16
16
  end
17
17
  end
18
18
 
19
- Hidemyass.proxies.each do |proxy|
19
+ HideMyAss.proxies.each do |proxy|
20
20
  begin
21
- Hidemyass.log proxy[:host] + ':' + proxy[:port]
21
+ HideMyAss.log proxy[:host] + ':' + proxy[:port]
22
22
  response = Net::HTTP::Proxy(proxy[:host], proxy[:port]).start(address, *arg, &block)
23
- Hidemyass.log response.class.to_s
23
+ HideMyAss.log response.class.to_s
24
24
  if response.class.ancestors.include?(Net::HTTPSuccess)
25
25
  return response
26
26
  end
27
27
  rescue *HTTP_ERRORS => error
28
- Hidemyass.log error
28
+ HideMyAss.log error
29
29
  end
30
30
  end
31
31
 
@@ -0,0 +1,36 @@
1
+ module HideMyAss
2
+ class IP
3
+
4
+ attr_accessor :decoys, :address
5
+
6
+ VALID_TAGS = %w(span div text).freeze
7
+
8
+ def initialize(encoded_address)
9
+ @decoys = encoded_address.css("style").text.split("\n").select {|style| style =~ /none/}
10
+ elements = encoded_address.children
11
+ decode(elements)
12
+ @address = elements.map(&:content).join
13
+
14
+ self
15
+ end
16
+
17
+ def decode(elements)
18
+ elements.each do |element|
19
+ if !VALID_TAGS.include?(element.name) || (element["style"] && element["style"] =~ /none/)
20
+ element.children.remove
21
+ elsif element["class"]
22
+ decoys.each { |decoy| element.children.remove if decoy.include?(element["class"]) }
23
+ end
24
+ end
25
+ end
26
+
27
+ def valid?
28
+ address.split(".").reject(&:empty?).size == 4
29
+ end
30
+
31
+ def inspect
32
+ "#<#{self.class}> @address=#{address}>"
33
+ end
34
+
35
+ end # IP
36
+ end # HideMyAss
@@ -1,4 +1,4 @@
1
- module Hidemyass
1
+ module HideMyAss
2
2
  module Logger
3
3
  def log(message)
4
4
  logger.info("#{LOG_PREFIX} #{message}") if logging?
@@ -1,12 +1,12 @@
1
1
  require 'hidemyass'
2
2
 
3
- module Hidemyass
3
+ module HideMyAss
4
4
  require 'rails'
5
5
 
6
6
  class Railtie < Rails::Railtie
7
7
  initializer "hidemyass.configure_rails_initialization" do
8
- Hidemyass.options[:logger] = Rails.logger if defined?(Rails)
9
- Hidemyass.options[:logger] = ActiveRecord::Base.logger if defined?(ActiveRecord)
8
+ HideMyAss.options[:logger] = Rails.logger if defined?(Rails)
9
+ HideMyAss.options[:logger] = ActiveRecord::Base.logger if defined?(ActiveRecord)
10
10
  end
11
11
  end
12
12
  end
@@ -1,3 +1,3 @@
1
- module Hidemyass
2
- VERSION = "0.0.9"
1
+ module HideMyAss
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ describe HideMyAss::IP do
4
+
5
+ # Tipically we would use webmock here to fake the http request,
6
+ # but hidemyass.com seems to be changing their encoding strategy often.
7
+ # By having real data we ensure this gem is working.
8
+ it "decodes encoded address" do
9
+ html = Nokogiri::HTML(open(URI.parse(HideMyAss::ENDPOINT)))
10
+
11
+ HideMyAss::IP.new(html.at_xpath('//table[@id="listtable"]/tr/td[2]/span'))
12
+ .should be_valid
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ require "hidemyass"
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # Require this file using `require "spec_helper"` to ensure that it is only
6
+ # loaded once.
7
+ #
8
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = 'random'
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hidemyass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,25 +9,31 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-15 00:00:00.000000000 Z
12
+ date: 2012-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &70167372757800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 1.5.5
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
24
+ version_requirements: *70167372757800
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70167372757300 !ruby/object:Gem::Requirement
25
28
  none: false
26
29
  requirements:
27
- - - ! '>='
30
+ - - ~>
28
31
  - !ruby/object:Gem::Version
29
- version: '0'
30
- description: Hide My Ass! fetches and connects to listed proxies at www.hidemyass.com
32
+ version: 2.12.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70167372757300
36
+ description: Hide My Ass! fetches and connects to proxies at http://hidemyass.com
31
37
  email:
32
38
  - javier@tractical.com
33
39
  executables: []
@@ -35,6 +41,8 @@ extensions: []
35
41
  extra_rdoc_files: []
36
42
  files:
37
43
  - .gitignore
44
+ - .rspec
45
+ - .travis.yml
38
46
  - Gemfile
39
47
  - LICENSE
40
48
  - README.md
@@ -42,9 +50,12 @@ files:
42
50
  - hidemyass.gemspec
43
51
  - lib/hidemyass.rb
44
52
  - lib/hidemyass/http.rb
53
+ - lib/hidemyass/ip.rb
45
54
  - lib/hidemyass/logger.rb
46
55
  - lib/hidemyass/railtie.rb
47
56
  - lib/hidemyass/version.rb
57
+ - spec/lib/ip_spec.rb
58
+ - spec/spec_helper.rb
48
59
  homepage: http://github.com/jassa/hidemyass
49
60
  licenses: []
50
61
  post_install_message:
@@ -65,9 +76,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
76
  version: '0'
66
77
  requirements: []
67
78
  rubyforge_project:
68
- rubygems_version: 1.8.22
79
+ rubygems_version: 1.8.11
69
80
  signing_key:
70
81
  specification_version: 3
71
82
  summary: Hide My Ass! lets you connect anonymously, fetch proxies from hidemyass.com
72
83
  and try each one until a successful connection is made.
73
- test_files: []
84
+ test_files:
85
+ - spec/lib/ip_spec.rb
86
+ - spec/spec_helper.rb