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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0b0359e814e6da477e31d71c4233e45a3fa390bb5b0d7261cb653ca74171c97
4
- data.tar.gz: c3f25e5ea1321af5642563748f69cd76707479dfb8963791c0936755cefcc1f6
3
+ metadata.gz: 1e4f84f4f6019e052e512e473d3897ea94d90bbb5d30fc25e37afb6f345a95e8
4
+ data.tar.gz: 58b86dc5d6902b96b2c210e7632d9ad73d0ee60a1b506e19f3464200ec3fd201
5
5
  SHA512:
6
- metadata.gz: b8e05b735de4606502fafbba815d06d1e15ab2126d0563f1fb772af0ccdbb0228aa7ef95f3b86cf91656b5dcfe4729390b27ffcb8d52ed996995734c2db43871
7
- data.tar.gz: 866efa20033fdeddec050e1d81ab957d06238ce55d44a450311b2afe79c981528e8131f6d0d3209bf419ec7f8b86dcc7d0467bff466ce2d6cad63f61fff8dd75
6
+ metadata.gz: 6ee8e822e17dd1a0b92dae24495efc45189aa3047dd1f6a5ffd3716fb2c5c514f8f2dbbd352d047b7b62fb3e2986841ab4574d2c8bf18dee21d00070e44af069
7
+ data.tar.gz: 9f1fffbab8efef2aaa07d2ad3a4b5fe3a340fb1e8d28bcf905d0899948a546581b2e08d3cbae622b914dfd13f4730362e4e65f06c8e326be9da37f09cf39d684
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'adspower-client'
3
- s.version = '1.0.8'
3
+ s.version = '1.0.10'
4
4
  s.date = '2024-02-07'
5
5
  s.summary = "Ruby library for operating AdsPower API."
6
6
  s.description = "Ruby library for operating AdsPower API."
@@ -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.adspower_listener = h[:adspower_listener] || 'http://127.0.0.1:50325'
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
- uri = URI.parse("#{self.adspower_listener}/api/v1/browser/start?user_id=#{id}&headless=#{headless ? '1' : '0'}'}")
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adspower-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Daniel Sardi