Class: PhantomJSProxy::PhantomJSClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(addr_list = [], key = nil, log = nil, con = PhantomJSClientConnection.new) ⇒ PhantomJSClient

Returns a new instance of PhantomJSClient.



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/phantom_client/phantom_client.rb', line 35

def initialize(addr_list=[], key=nil, log=nil, con = PhantomJSClientConnection.new)
	@proxy_list = addr_list
	@connection = con
	@hmac_activated = key ? true : false
	@hmac = HMAC::MD5.new key
	@logger = log
	if @logger == nil
	  @logger = DummyLogger.new
	end
	logger.info "Using #{key} as HMAC key"
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



30
31
32
# File 'lib/phantom_client/phantom_client.rb', line 30

def connection
  @connection
end

#hmacObject

Returns the value of attribute hmac.



31
32
33
# File 'lib/phantom_client/phantom_client.rb', line 31

def hmac
  @hmac
end

#hmac_activatedObject

Returns the value of attribute hmac_activated.



32
33
34
# File 'lib/phantom_client/phantom_client.rb', line 32

def hmac_activated
  @hmac_activated
end

#loggerObject

Returns the value of attribute logger.



33
34
35
# File 'lib/phantom_client/phantom_client.rb', line 33

def logger
  @logger
end

#proxy_addrObject

Returns the value of attribute proxy_addr.



27
28
29
# File 'lib/phantom_client/phantom_client.rb', line 27

def proxy_addr
  @proxy_addr
end

#proxy_listObject

Returns the value of attribute proxy_list.



29
30
31
# File 'lib/phantom_client/phantom_client.rb', line 29

def proxy_list
  @proxy_list
end

#proxy_portObject

Returns the value of attribute proxy_port.



28
29
30
# File 'lib/phantom_client/phantom_client.rb', line 28

def proxy_port
  @proxy_port
end

Instance Method Details

#get(addr_in, options = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/phantom_client/phantom_client.rb', line 51

def get(addr_in, options=nil)		
	addr,url, req = generate_request(addr_in)
	
	if options && options['imageOnly']
		req['Get-Page-As-Image'] = options['imageOnly']
		logger.info "Do image only"
	end
	
	if options && options['withIframes']
		req['Get-Page-With-IFrames'] = options['withIframes']
		logger.info "Do fetch iframes"
	end
	
	if hmac_activated
	  update_hmac_head addr, req, hmac
	end
	#::Proxy(@proxy_addr, @proxy_port)
	
	#element = get_proxy()	
	#begin
	#	@connection.do_request(element, url, req)
	#rescue
	#	return "Could not connect to proxy"
	#end
    do_get(url, req, 10)
end

#get_body(addr, options = nil) ⇒ Object



47
48
49
# File 'lib/phantom_client/phantom_client.rb', line 47

def get_body(addr, options=nil)
  get(addr, options).body
end