adspower-client 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/adspower-client.gemspec +5 -2
- data/lib/adspower-client.rb +96 -21
- metadata +62 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1289e195355621cc166ac8cb97668015390fa31b5bb0db7579c7b397bad31fcf
|
4
|
+
data.tar.gz: b467fd3a6e5bbbcec7ddf207b1ce2909e480db5fc66849548be27154414bac32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9ae982a04c8e734bf33bb2864ae247c8ce180b136c79e290d6dadabd0957b0ca33b1b2f62cff06fef5fcd12b4f4f9f5eb61fe24eed489d562210cdbc1c9cf84
|
7
|
+
data.tar.gz: 72a3f7138ee351ee425ca9aa7243a70e8951f5a04df357257734e991a180dc2e207782fd9d858f61462747d4576eee05820c9adb4dc685c35f5a74cbf7f280b4
|
data/adspower-client.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'adspower-client'
|
3
|
-
s.version = '1.0.
|
4
|
-
s.date = '2023-12-
|
3
|
+
s.version = '1.0.4'
|
4
|
+
s.date = '2023-12-31'
|
5
5
|
s.summary = "Ruby library for operating AdsPower API."
|
6
6
|
s.description = "Ruby library for operating AdsPower API."
|
7
7
|
s.authors = ["Leandro Daniel Sardi"]
|
@@ -18,4 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_runtime_dependency 'blackstack-core', '~> 1.2.15', '>= 1.2.15'
|
19
19
|
s.add_runtime_dependency 'selenium-webdriver', '~> 4.10.0', '>= 4.10.0'
|
20
20
|
s.add_runtime_dependency 'watir', '~> 7.3.0', '>= 7.3.0'
|
21
|
+
s.add_runtime_dependency 'sequel', '~> 5.75.0', '>= 5.75.0'
|
22
|
+
s.add_runtime_dependency 'colorize', '~> 1.1.0', '>= 1.1.0'
|
23
|
+
s.add_runtime_dependency 'simple_cloud_logging', '~> 1.2.2', '>= 1.2.2'
|
21
24
|
end
|
data/lib/adspower-client.rb
CHANGED
@@ -9,24 +9,30 @@ class AdsPowerClient
|
|
9
9
|
# reference: https://localapi-doc-en.adspower.com/
|
10
10
|
# reference: https://localapi-doc-en.adspower.com/docs/Rdw7Iu
|
11
11
|
attr_accessor :key, :adspower_listener, :adspower_default_browser_version
|
12
|
+
# attr_accessor :profiles_created
|
12
13
|
|
13
14
|
def initialize(h={})
|
14
15
|
self.key = h[:key] # mandatory
|
15
16
|
self.adspower_listener = h[:adspower_listener] || 'http://127.0.0.1:50325'
|
16
17
|
self.adspower_default_browser_version = h[:adspower_default_browser_version] || '116'
|
18
|
+
# self.profiles_created = []
|
17
19
|
end
|
18
20
|
|
19
|
-
# send an GET request to "#{url}/status"
|
20
|
-
#
|
21
|
+
# send an GET request to "#{url}/status".
|
22
|
+
# Return true if it responded successfully.
|
21
23
|
#
|
22
24
|
# reference: https://localapi-doc-en.adspower.com/docs/6DSiws
|
23
25
|
#
|
24
|
-
def
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
def online?
|
27
|
+
begin
|
28
|
+
url = "#{self.adspower_listener}/status"
|
29
|
+
uri = URI.parse(url)
|
30
|
+
res = Net::HTTP.get(uri)
|
31
|
+
# show respose body
|
32
|
+
return JSON.parse(res)['msg'] == 'success'
|
33
|
+
rescue => e
|
34
|
+
return false
|
35
|
+
end
|
30
36
|
end
|
31
37
|
|
32
38
|
# send a post request to "#{url}/api/v1/user/create"
|
@@ -53,6 +59,8 @@ class AdsPowerClient
|
|
53
59
|
# show respose body
|
54
60
|
ret = JSON.parse(res.body)
|
55
61
|
raise "Error: #{ret.to_s}" if ret['msg'].to_s.downcase != 'success'
|
62
|
+
# add to array of profiles created
|
63
|
+
# self.profiles_created << ret
|
56
64
|
# return id of the created user
|
57
65
|
ret['data']['id']
|
58
66
|
end
|
@@ -76,8 +84,8 @@ class AdsPowerClient
|
|
76
84
|
#
|
77
85
|
# reference: https://localapi-doc-en.adspower.com/docs/FFMFMf
|
78
86
|
#
|
79
|
-
def start(id)
|
80
|
-
uri = URI.parse("#{self.adspower_listener}/api/v1/browser/start?user_id=#{id}")
|
87
|
+
def start(id, headless=false)
|
88
|
+
uri = URI.parse("#{self.adspower_listener}/api/v1/browser/start?user_id=#{id}&headless=#{headless ? '1' : '0'}'}")
|
81
89
|
res = Net::HTTP.get(uri)
|
82
90
|
# show respose bo
|
83
91
|
ret = JSON.parse(res)
|
@@ -101,9 +109,25 @@ class AdsPowerClient
|
|
101
109
|
ret
|
102
110
|
end
|
103
111
|
|
112
|
+
# send an GET request to "#{url}/status"
|
113
|
+
# and return if I get the json response['data']['status'] == 'Active'.
|
114
|
+
# Otherwise, return false.
|
115
|
+
#
|
116
|
+
# reference: https://localapi-doc-en.adspower.com/docs/YjFggL
|
117
|
+
#
|
118
|
+
def check(id)
|
119
|
+
url = "#{self.adspower_listener}/api/v1/browser/active?user_id=#{id}"
|
120
|
+
uri = URI.parse(url)
|
121
|
+
res = Net::HTTP.get(uri)
|
122
|
+
# show respose body
|
123
|
+
return false if JSON.parse(res)['msg'] != 'success'
|
124
|
+
# return
|
125
|
+
JSON.parse(res)['data']['status'] == 'Active'
|
126
|
+
end
|
127
|
+
|
104
128
|
#
|
105
|
-
def driver(id)
|
106
|
-
ret = self.start(id)
|
129
|
+
def driver(id, headless=false)
|
130
|
+
ret = self.start(id, headless)
|
107
131
|
|
108
132
|
# Attach test execution to the existing browser
|
109
133
|
# reference: https://zhiminzhan.medium.com/my-innovative-solution-to-test-automation-attach-test-execution-to-the-existing-browser-b90cda3b7d4a
|
@@ -128,13 +152,64 @@ class AdsPowerClient
|
|
128
152
|
# delete the profile
|
129
153
|
# return the html
|
130
154
|
def html(url)
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
155
|
+
ret = {
|
156
|
+
:profile_id => nil,
|
157
|
+
:html => nil,
|
158
|
+
:status => 'success',
|
159
|
+
}
|
160
|
+
id = nil
|
161
|
+
html = nil
|
162
|
+
begin
|
163
|
+
# create the profile
|
164
|
+
sleep(1) # Avoid the "Too many request per second" error
|
165
|
+
id = self.create
|
166
|
+
|
167
|
+
# update the result
|
168
|
+
ret[:profile_id] = id
|
169
|
+
|
170
|
+
# start the profile and attach the driver
|
171
|
+
driver = self.driver(id)
|
172
|
+
|
173
|
+
# get html
|
174
|
+
driver.get(url)
|
175
|
+
html = driver.page_source
|
176
|
+
|
177
|
+
# update the result
|
178
|
+
ret[:html] = html
|
179
|
+
|
180
|
+
# stop the profile
|
181
|
+
sleep(1) # Avoid the "Too many request per second" error
|
182
|
+
driver.quit
|
183
|
+
self.stop(id)
|
184
|
+
|
185
|
+
# delete the profile
|
186
|
+
sleep(1) # Avoid the "Too many request per second" error
|
187
|
+
self.delete(id)
|
188
|
+
|
189
|
+
# reset id
|
190
|
+
id = nil
|
191
|
+
rescue => e
|
192
|
+
# stop and delete current profile
|
193
|
+
if id
|
194
|
+
sleep(1) # Avoid the "Too many request per second" error
|
195
|
+
self.stop(id)
|
196
|
+
sleep(1) # Avoid the "Too many request per second" error
|
197
|
+
driver.quit
|
198
|
+
self.delete(id) if id
|
199
|
+
end # if id
|
200
|
+
# inform the exception
|
201
|
+
ret[:status] = e.to_s
|
202
|
+
# # process interruption
|
203
|
+
# rescue SignalException, SystemExit, Interrupt => e
|
204
|
+
# if id
|
205
|
+
# sleep(1) # Avoid the "Too many request per second" error
|
206
|
+
# self.stop(id)
|
207
|
+
# sleep(1) # Avoid the "Too many request per second" error
|
208
|
+
# driver.quit
|
209
|
+
# self.delete(id) if id
|
210
|
+
# end # if id
|
211
|
+
end
|
212
|
+
# return
|
213
|
+
ret
|
214
|
+
end # def html
|
140
215
|
end # class AdsPowerClient
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adspower-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leandro Daniel Sardi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uri
|
@@ -130,6 +130,66 @@ dependencies:
|
|
130
130
|
- - ">="
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: 7.3.0
|
133
|
+
- !ruby/object:Gem::Dependency
|
134
|
+
name: sequel
|
135
|
+
requirement: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: 5.75.0
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: 5.75.0
|
143
|
+
type: :runtime
|
144
|
+
prerelease: false
|
145
|
+
version_requirements: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - "~>"
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: 5.75.0
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 5.75.0
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: colorize
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 1.1.0
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: 1.1.0
|
163
|
+
type: :runtime
|
164
|
+
prerelease: false
|
165
|
+
version_requirements: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - "~>"
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: 1.1.0
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: 1.1.0
|
173
|
+
- !ruby/object:Gem::Dependency
|
174
|
+
name: simple_cloud_logging
|
175
|
+
requirement: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - "~>"
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: 1.2.2
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: 1.2.2
|
183
|
+
type: :runtime
|
184
|
+
prerelease: false
|
185
|
+
version_requirements: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - "~>"
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: 1.2.2
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: 1.2.2
|
133
193
|
description: Ruby library for operating AdsPower API.
|
134
194
|
email: leandro@connectionsphere.com
|
135
195
|
executables: []
|