phantom_client 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/phantom_client +1 -1
- data/lib/phantom_client/phantom_client.rb +26 -7
- metadata +4 -4
data/bin/phantom_client
CHANGED
@@ -25,5 +25,5 @@ if url == nil
|
|
25
25
|
return
|
26
26
|
end
|
27
27
|
|
28
|
-
client = PhantomJSProxy::PhantomJSClient.new(proxy_list, hmac_key, PhantomJSProxy::PhantomJSClientConnection.new)
|
28
|
+
client = PhantomJSProxy::PhantomJSClient.new(proxy_list, hmac_key, nil, PhantomJSProxy::PhantomJSClientConnection.new)
|
29
29
|
puts client.get_body(url, {:imageOnly => false, :withIframes => true})
|
@@ -7,6 +7,20 @@ module PhantomJSProxy
|
|
7
7
|
attr_accessor :body
|
8
8
|
attr_accessor :code
|
9
9
|
end
|
10
|
+
class DummyLogger
|
11
|
+
def info msg
|
12
|
+
puts msg
|
13
|
+
end
|
14
|
+
|
15
|
+
def warn msg
|
16
|
+
puts msg
|
17
|
+
end
|
18
|
+
|
19
|
+
def error msg
|
20
|
+
purs msg
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
10
24
|
class PhantomJSClient
|
11
25
|
|
12
26
|
attr_accessor :proxy_addr
|
@@ -15,13 +29,18 @@ module PhantomJSProxy
|
|
15
29
|
attr_accessor :connection
|
16
30
|
attr_accessor :hmac
|
17
31
|
attr_accessor :hmac_activated
|
32
|
+
attr_accessor :logger
|
18
33
|
|
19
|
-
def initialize(addr_list=[], key=nil, con = PhantomJSClientConnection.new)
|
34
|
+
def initialize(addr_list=[], key=nil, log=nil, con = PhantomJSClientConnection.new)
|
20
35
|
@proxy_list = addr_list
|
21
36
|
@connection = con
|
22
37
|
@hmac_activated = key ? true : false
|
23
38
|
@hmac = HMAC::MD5.new key
|
24
|
-
|
39
|
+
@logger = log
|
40
|
+
if @logger == nil
|
41
|
+
@logger = DummyLogger.new
|
42
|
+
end
|
43
|
+
logger.info "Using #{key} as HMAC key"
|
25
44
|
end
|
26
45
|
|
27
46
|
def get_body(addr, options=nil)
|
@@ -38,12 +57,12 @@ module PhantomJSProxy
|
|
38
57
|
|
39
58
|
if options && options['imageOnly']
|
40
59
|
req['Get-Page-As-Image'] = options['imageOnly']
|
41
|
-
|
60
|
+
logger.info "Do image only"
|
42
61
|
end
|
43
62
|
|
44
63
|
if options && options['withIframes']
|
45
64
|
req['Get-Page-With-IFrames'] = options['withIframes']
|
46
|
-
|
65
|
+
logger.info "Do fetch iframes"
|
47
66
|
end
|
48
67
|
|
49
68
|
if hmac_activated
|
@@ -65,15 +84,15 @@ module PhantomJSProxy
|
|
65
84
|
t = Time.now
|
66
85
|
req['Hmac-Key'] = hmac_keygen.update(addr+t.to_s).hexdigest
|
67
86
|
req['Hmac-Time'] = t
|
68
|
-
|
87
|
+
logger.info "Encode: #{addr} to #{req['Hmac-Key']}"
|
69
88
|
end
|
70
89
|
|
71
90
|
def do_get(url, req, count)
|
72
91
|
element = get_proxy()
|
73
92
|
if element[:addr] && element[:port]
|
74
|
-
|
93
|
+
logger.info "try: "+element[:addr]+", "+element[:port]
|
75
94
|
else
|
76
|
-
|
95
|
+
logger.info "DUMMY TRY"
|
77
96
|
end
|
78
97
|
|
79
98
|
begin
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phantom_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 1
|
10
|
+
version: 1.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel Sudmann
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-05-
|
18
|
+
date: 2012-05-10 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|