Class: ProxyCredentials

Inherits:
Object
  • Object
show all
Includes:
Gem::UserInteraction
Defined in:
lib/proxy_credentials.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.proxy_credentials(proxy) ⇒ Object



6
7
8
# File 'lib/proxy_credentials.rb', line 6

def self.proxy_credentials(proxy)
  new.get_credentials(proxy)
end

Instance Method Details

#get_credentials(proxy) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/proxy_credentials.rb', line 10

def get_credentials(proxy)
  puts "need credentials for proxy #{proxy}"
  uri = URI(proxy)
  proxy_host = uri.hostname
  proxy_port = uri.port
  proxy_user = ask("username:")
  proxy_password = ask_for_password("password:")

  uri = URI("http://blogsearch.google.com/ping/RPC2")
  req = Net::HTTP::Get.new(uri)
  net = Net::HTTP.new(uri.hostname, uri.port, proxy_host, proxy_port, proxy_user, proxy_password)
  puts "created net"
  net.read_timeout = 20
  net.open_timeout = 20

  net.start { |http|
    response = http.request(req)
    puts "response code from internet web service is #{response.code}, message is #{response.message}"
  }
end