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.



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

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:



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

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.



21
22
23
24
25
# File 'lib/webdrivers/network.rb', line 21

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.



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

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.



56
57
58
# File 'lib/webdrivers/network.rb', line 56

def using_proxy
  Webdrivers.proxy_addr && Webdrivers.proxy_port
end