dubdubdub 0.3.9 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15640115e011f39d528ea0ad6369097c29e02004
4
- data.tar.gz: daba756d0aec9b295a04095ef1ff04a3eeb27d6d
3
+ metadata.gz: 539019bb4ef032b1ed9e449a1bbfbbd81bd6259f
4
+ data.tar.gz: 5b51570cb2465086030f59776633ea8c22d0c719
5
5
  SHA512:
6
- metadata.gz: d32b5010a1352ccc3288ac483ce1d9f95f6d7b403ddf6c8b8ad19b6b4ed94dbf36bb9928f782a58099dce664576a2bd5c0905fa2d96c8d4b978266e9d3d57911
7
- data.tar.gz: e7450a822efec53afb7dc0e9d1dbf369291afdbb9e413687790b0daa97a027070ba5c6d2148c87150ab4817a7476c9c8818a36e4b68624802db2fb15182e1f1c
6
+ metadata.gz: faf635beb4993d2f7580ad4b0c593584d6ce48c51a428c4d1137a99a4fc1f67b19c77942c2773b99348728094003bece00d19d2af14704881e5ca5411ad86ff1
7
+ data.tar.gz: b6b4934910f0ff2510a892f915d4af707fca85b5918ef20406eb6b6dea60d1dda00badf16ce515d7667b4d659000a4f12faddd8f6829f16d099ea585e28259b5
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "dubdubdub"
8
- s.version = "0.3.9"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["James Hu"]
12
- s.date = "2014-10-31"
12
+ s.date = "2014-11-03"
13
13
  s.description = "A library that provides web utility methods with proxification."
14
14
  s.email = "axsuul@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -1,6 +1,6 @@
1
1
  class DubDubDub
2
2
  # Version
3
- VERSION = "0.3.9"
3
+ VERSION = "0.4.0"
4
4
 
5
5
  attr_accessor :client
6
6
 
@@ -4,7 +4,10 @@ require 'mechanize'
4
4
  require 'rest-client'
5
5
 
6
6
  class DubDubDub::Client
7
- attr_accessor :proxy_host, :proxy_port, :proxy_user, :proxy_password
7
+ attr_accessor :proxy_host,
8
+ :proxy_port,
9
+ :proxy_username,
10
+ :proxy_password
8
11
 
9
12
  def initialize(options = {})
10
13
  default_options = {
@@ -36,15 +39,24 @@ class DubDubDub::Client
36
39
  end
37
40
 
38
41
  def proxy=(url)
39
- host, port = url.split(":")
42
+ matches = url.match(/(?:(?<username>[^\:]+)\:(?<password>[^\@]+)\@)?(?<host>[\.0-9]+|localhost)(?:\:(?<port>[0-9]+))?/)
40
43
 
41
- port = 80 unless port
42
- self.proxy_host = host
43
- self.proxy_port = port
44
+ self.proxy_host = matches[:host]
45
+ self.proxy_port = matches[:port] || 80
46
+ self.proxy_username = matches[:username]
47
+ self.proxy_password = matches[:password]
44
48
  end
45
49
 
46
50
  def proxy
47
- "#{proxy_host}:#{proxy_port}" if proxy_host and proxy_port
51
+ if proxy_host and proxy_port
52
+ address = "#{proxy_host}:#{proxy_port}"
53
+
54
+ if proxy_username and proxy_password
55
+ address.prepend("#{proxy_username}:#{proxy_password}@")
56
+ end
57
+ end
58
+
59
+ address
48
60
  end
49
61
 
50
62
  def proxy?
@@ -31,6 +31,17 @@ describe DubDubDub do
31
31
  www.proxy_port.should == 80
32
32
  end
33
33
 
34
+ it "can specify user and password for proxy" do
35
+ address = "user:pass@203.131.212.166:55555"
36
+
37
+ www = DubDubDub.new(proxy: address)
38
+ www.proxy_host.should == "203.131.212.166"
39
+ www.proxy_port.should == 55555
40
+ www.proxy_username.should == "user"
41
+ www.proxy_password.should == "pass"
42
+ www.proxy.should == address
43
+ end
44
+
34
45
  it "can configure to use a proxy globally" do
35
46
  DubDubDub.configure do |config|
36
47
  config.proxy = "localhost:8000"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dubdubdub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Hu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-31 00:00:00.000000000 Z
11
+ date: 2014-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client