Class: Webdrivers::Network Private

Inherits:
Object
  • Object
show all
Defined in:
lib/webdrivers/network.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Class Method Details

.get(url, limit = 10) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/webdrivers/network.rb', line 11

def get(url, limit = 10)
  Webdrivers.logger.debug "Making network call to #{url}"

  response = get_response(url, limit)
  case response
  when Net::HTTPSuccess
    response.body
  else
    raise NetworkError, "#{response.class::EXCEPTION_TYPE}: #{response.code} \"#{response.message}\" with #{url}"
  end
end

.get_response(url, limit = 10) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/webdrivers/network.rb', line 29

def get_response(url, limit = 10)
  raise ConnectionError, 'Too many HTTP redirects' if limit.zero?

  begin
    response = http.get_response(URI(url))
  rescue SocketError
    raise ConnectionError, "Can not reach #{url}"
  end

  Webdrivers.logger.debug "Get response: #{response.inspect}"

  if response.is_a?(Net::HTTPRedirection)
    location = response['location']
    Webdrivers.logger.debug "Redirected to #{location}"
    get_response(location, limit - 1)
  else
    response
  end
end

.get_url(url, limit = 10) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



23
24
25
26
27
# File 'lib/webdrivers/network.rb', line 23

def get_url(url, limit = 10)
  Webdrivers.logger.debug "Making network call to #{url}"

  get_response(url, limit).uri.to_s
end

.httpObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



49
50
51
52
53
54
55
56
# File 'lib/webdrivers/network.rb', line 49

def http
  if using_proxy
    Net::HTTP.Proxy(Webdrivers.proxy_addr, Webdrivers.proxy_port,
                    Webdrivers.proxy_user, Webdrivers.proxy_pass)
  else
    Net::HTTP
  end
end

.using_proxyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



58
59
60
# File 'lib/webdrivers/network.rb', line 58

def using_proxy
  Webdrivers.proxy_addr && Webdrivers.proxy_port
end