adspower-client 1.0.2 → 1.0.3
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 +5 -2
- data/lib/adspower-client.rb +65 -10
- 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: 2a6276d009445088184bda9fb619b9f64da4a2f50e383eeef8e7166503d5c38f
|
4
|
+
data.tar.gz: 27127685f33523332a282fc6e50d43f6e7064bde27666c7b18bde1f407a97fbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50a25edcd5c54207f6f4e86004671596f47e8b360bd3961b8e2c67759dfd134f30939ca330a45c54a80777ee5e805d6cb1ebfa90a4a2bde0cea46ab7b917efb7
|
7
|
+
data.tar.gz: 106df641acb2442c19da7ba0bb24e7603d5d9521621b6a0968a172c9746ab9ac98f99af1cbe04df307b62c8be9564c1090aeae9d88e7fbe7934cf7a70fdc0616
|
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.3'
|
4
|
+
s.date = '2023-12-07'
|
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,11 +9,13 @@ 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
21
|
# send an GET request to "#{url}/status"
|
@@ -53,6 +55,8 @@ class AdsPowerClient
|
|
53
55
|
# show respose body
|
54
56
|
ret = JSON.parse(res.body)
|
55
57
|
raise "Error: #{ret.to_s}" if ret['msg'].to_s.downcase != 'success'
|
58
|
+
# add to array of profiles created
|
59
|
+
# self.profiles_created << ret
|
56
60
|
# return id of the created user
|
57
61
|
ret['data']['id']
|
58
62
|
end
|
@@ -77,7 +81,7 @@ class AdsPowerClient
|
|
77
81
|
# reference: https://localapi-doc-en.adspower.com/docs/FFMFMf
|
78
82
|
#
|
79
83
|
def start(id)
|
80
|
-
uri = URI.parse("#{self.adspower_listener}/api/v1/browser/start?user_id=#{id}")
|
84
|
+
uri = URI.parse("#{self.adspower_listener}/api/v1/browser/start?user_id=#{id}&headless=1")
|
81
85
|
res = Net::HTTP.get(uri)
|
82
86
|
# show respose bo
|
83
87
|
ret = JSON.parse(res)
|
@@ -128,13 +132,64 @@ class AdsPowerClient
|
|
128
132
|
# delete the profile
|
129
133
|
# return the html
|
130
134
|
def html(url)
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
135
|
+
ret = {
|
136
|
+
:profile_id => nil,
|
137
|
+
:html => nil,
|
138
|
+
:status => 'success',
|
139
|
+
}
|
140
|
+
id = nil
|
141
|
+
html = nil
|
142
|
+
begin
|
143
|
+
# create the profile
|
144
|
+
sleep(1) # Avoid the "Too many request per second" error
|
145
|
+
id = self.create
|
146
|
+
|
147
|
+
# update the result
|
148
|
+
ret[:profile_id] = id
|
149
|
+
|
150
|
+
# start the profile and attach the driver
|
151
|
+
driver = self.driver(id)
|
152
|
+
|
153
|
+
# get html
|
154
|
+
driver.get(url)
|
155
|
+
html = driver.page_source
|
156
|
+
|
157
|
+
# update the result
|
158
|
+
ret[:html] = html
|
159
|
+
|
160
|
+
# stop the profile
|
161
|
+
sleep(1) # Avoid the "Too many request per second" error
|
162
|
+
driver.quit
|
163
|
+
self.stop(id)
|
164
|
+
|
165
|
+
# delete the profile
|
166
|
+
sleep(1) # Avoid the "Too many request per second" error
|
167
|
+
self.delete(id)
|
168
|
+
|
169
|
+
# reset id
|
170
|
+
id = nil
|
171
|
+
rescue => e
|
172
|
+
# stop and delete current profile
|
173
|
+
if id
|
174
|
+
sleep(1) # Avoid the "Too many request per second" error
|
175
|
+
self.stop(id)
|
176
|
+
sleep(1) # Avoid the "Too many request per second" error
|
177
|
+
driver.quit
|
178
|
+
self.delete(id) if id
|
179
|
+
end # if id
|
180
|
+
# inform the exception
|
181
|
+
ret[:status] = e.to_s
|
182
|
+
# # process interruption
|
183
|
+
# rescue SignalException, SystemExit, Interrupt => e
|
184
|
+
# if id
|
185
|
+
# sleep(1) # Avoid the "Too many request per second" error
|
186
|
+
# self.stop(id)
|
187
|
+
# sleep(1) # Avoid the "Too many request per second" error
|
188
|
+
# driver.quit
|
189
|
+
# self.delete(id) if id
|
190
|
+
# end # if id
|
191
|
+
end
|
192
|
+
# return
|
193
|
+
ret
|
194
|
+
end # def html
|
140
195
|
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.3
|
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-07 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: []
|