adspower-client 1.0.8 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/adspower-client.gemspec +1 -1
- data/lib/adspower-client.rb +42 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e4f84f4f6019e052e512e473d3897ea94d90bbb5d30fc25e37afb6f345a95e8
|
4
|
+
data.tar.gz: 58b86dc5d6902b96b2c210e7632d9ad73d0ee60a1b506e19f3464200ec3fd201
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ee8e822e17dd1a0b92dae24495efc45189aa3047dd1f6a5ffd3716fb2c5c514f8f2dbbd352d047b7b62fb3e2986841ab4574d2c8bf18dee21d00070e44af069
|
7
|
+
data.tar.gz: 9f1fffbab8efef2aaa07d2ad3a4b5fe3a340fb1e8d28bcf905d0899948a546581b2e08d3cbae622b914dfd13f4730362e4e65f06c8e326be9da37f09cf39d684
|
data/adspower-client.gemspec
CHANGED
data/lib/adspower-client.rb
CHANGED
@@ -8,7 +8,7 @@ require 'watir'
|
|
8
8
|
class AdsPowerClient
|
9
9
|
# reference: https://localapi-doc-en.adspower.com/
|
10
10
|
# reference: https://localapi-doc-en.adspower.com/docs/Rdw7Iu
|
11
|
-
attr_accessor :key, :adspower_listener, :adspower_default_browser_version
|
11
|
+
attr_accessor :key, :port, :server_log, :adspower_listener, :adspower_default_browser_version
|
12
12
|
|
13
13
|
# control over the drivers created, in order to don't create the same driver twice and don't generate memory leaks.
|
14
14
|
# reference: https://github.com/leandrosardi/adspower-client/issues/4
|
@@ -16,11 +16,44 @@ class AdsPowerClient
|
|
16
16
|
|
17
17
|
def initialize(h={})
|
18
18
|
self.key = h[:key] # mandatory
|
19
|
-
self.
|
19
|
+
self.port = h[:port] || '50325'
|
20
|
+
self.server_log = h[:server_log] || '~/adspower-client.log'
|
21
|
+
self.adspower_listener = h[:adspower_listener] || 'http://127.0.0.1'
|
20
22
|
self.adspower_default_browser_version = h[:adspower_default_browser_version] || '116'
|
21
23
|
# self.profiles_created = []
|
22
24
|
end
|
23
25
|
|
26
|
+
# return an array of PIDs of all the adspower_global processes running in the local computer.
|
27
|
+
def server_pids
|
28
|
+
`ps aux | grep "adspower_global" | grep -v grep | awk '{print $2}'`.split("\n")
|
29
|
+
end
|
30
|
+
|
31
|
+
# return true if there is any adspower_global process running in the local computer.
|
32
|
+
|
33
|
+
# run async command to start adspower server in headless mode.
|
34
|
+
# wait up to 10 seconds to start the server, or raise an exception.
|
35
|
+
def server_start(timeout=10)
|
36
|
+
`/usr/bin/adspower_global --headless=true --api-key=#{ADSPOWER_API_KEY} --api-port=#{ADSPOWER_PORT} > #{self.server_log} 2>&1 &`
|
37
|
+
# wait up to 10 seconds to start the server
|
38
|
+
timeout.times do
|
39
|
+
break if self.online?
|
40
|
+
sleep(1)
|
41
|
+
end
|
42
|
+
# add a delay of 5 more seconds
|
43
|
+
sleep(5)
|
44
|
+
# raise an exception if the server is not running
|
45
|
+
raise "Error: the server is not running" if self.online? == false
|
46
|
+
return
|
47
|
+
end
|
48
|
+
|
49
|
+
# kill all the adspower_global processes running in the local computer.
|
50
|
+
def server_stop
|
51
|
+
self.server_pids.each { |pid|
|
52
|
+
`kill -9 #{pid}`
|
53
|
+
}
|
54
|
+
return
|
55
|
+
end
|
56
|
+
|
24
57
|
# send an GET request to "#{url}/status".
|
25
58
|
# Return true if it responded successfully.
|
26
59
|
#
|
@@ -28,7 +61,7 @@ class AdsPowerClient
|
|
28
61
|
#
|
29
62
|
def online?
|
30
63
|
begin
|
31
|
-
url = "#{self.adspower_listener}/status"
|
64
|
+
url = "#{self.adspower_listener}:#{port}/status"
|
32
65
|
uri = URI.parse(url)
|
33
66
|
res = Net::HTTP.get(uri)
|
34
67
|
# show respose body
|
@@ -48,7 +81,7 @@ class AdsPowerClient
|
|
48
81
|
# reference: https://localapi-doc-en.adspower.com/docs/Awy6Dg
|
49
82
|
#
|
50
83
|
def create
|
51
|
-
url = "#{self.adspower_listener}/api/v1/user/create"
|
84
|
+
url = "#{self.adspower_listener}:#{port}/api/v1/user/create"
|
52
85
|
body = {
|
53
86
|
#'api_key' => self.key,
|
54
87
|
'group_id' => '0',
|
@@ -69,7 +102,7 @@ class AdsPowerClient
|
|
69
102
|
end
|
70
103
|
|
71
104
|
def delete(id)
|
72
|
-
url = "#{self.adspower_listener}/api/v1/user/delete"
|
105
|
+
url = "#{self.adspower_listener}:#{port}/api/v1/user/delete"
|
73
106
|
body = {
|
74
107
|
'api_key' => self.key,
|
75
108
|
'user_ids' => [id],
|
@@ -88,7 +121,8 @@ class AdsPowerClient
|
|
88
121
|
# reference: https://localapi-doc-en.adspower.com/docs/FFMFMf
|
89
122
|
#
|
90
123
|
def start(id, headless=false)
|
91
|
-
|
124
|
+
url = "#{self.adspower_listener}:#{port}/api/v1/browser/start?user_id=#{id}&headless=#{headless ? '1' : '0'}"
|
125
|
+
uri = URI.parse(url)
|
92
126
|
res = Net::HTTP.get(uri)
|
93
127
|
# show respose bo
|
94
128
|
ret = JSON.parse(res)
|
@@ -109,7 +143,7 @@ class AdsPowerClient
|
|
109
143
|
@@drivers[id] = nil
|
110
144
|
end
|
111
145
|
|
112
|
-
uri = URI.parse("#{self.adspower_listener}/api/v1/browser/stop?user_id=#{id}")
|
146
|
+
uri = URI.parse("#{self.adspower_listener}:#{port}/api/v1/browser/stop?user_id=#{id}")
|
113
147
|
res = Net::HTTP.get(uri)
|
114
148
|
# show respose body
|
115
149
|
ret = JSON.parse(res)
|
@@ -125,7 +159,7 @@ class AdsPowerClient
|
|
125
159
|
# reference: https://localapi-doc-en.adspower.com/docs/YjFggL
|
126
160
|
#
|
127
161
|
def check(id)
|
128
|
-
url = "#{self.adspower_listener}/api/v1/browser/active?user_id=#{id}"
|
162
|
+
url = "#{self.adspower_listener}:#{port}/api/v1/browser/active?user_id=#{id}"
|
129
163
|
uri = URI.parse(url)
|
130
164
|
res = Net::HTTP.get(uri)
|
131
165
|
# show respose body
|