adspower-client 1.0.3 → 1.0.4

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: 2a6276d009445088184bda9fb619b9f64da4a2f50e383eeef8e7166503d5c38f
4
- data.tar.gz: 27127685f33523332a282fc6e50d43f6e7064bde27666c7b18bde1f407a97fbf
3
+ metadata.gz: 1289e195355621cc166ac8cb97668015390fa31b5bb0db7579c7b397bad31fcf
4
+ data.tar.gz: b467fd3a6e5bbbcec7ddf207b1ce2909e480db5fc66849548be27154414bac32
5
5
  SHA512:
6
- metadata.gz: 50a25edcd5c54207f6f4e86004671596f47e8b360bd3961b8e2c67759dfd134f30939ca330a45c54a80777ee5e805d6cb1ebfa90a4a2bde0cea46ab7b917efb7
7
- data.tar.gz: 106df641acb2442c19da7ba0bb24e7603d5d9521621b6a0968a172c9746ab9ac98f99af1cbe04df307b62c8be9564c1090aeae9d88e7fbe7934cf7a70fdc0616
6
+ metadata.gz: a9ae982a04c8e734bf33bb2864ae247c8ce180b136c79e290d6dadabd0957b0ca33b1b2f62cff06fef5fcd12b4f4f9f5eb61fe24eed489d562210cdbc1c9cf84
7
+ data.tar.gz: 72a3f7138ee351ee425ca9aa7243a70e8951f5a04df357257734e991a180dc2e207782fd9d858f61462747d4576eee05820c9adb4dc685c35f5a74cbf7f280b4
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'adspower-client'
3
- s.version = '1.0.3'
4
- s.date = '2023-12-07'
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,17 +18,21 @@ class AdsPowerClient
18
18
  # self.profiles_created = []
19
19
  end
20
20
 
21
- # send an GET request to "#{url}/status"
22
- # and return the response body.
21
+ # send an GET request to "#{url}/status".
22
+ # Return true if it responded successfully.
23
23
  #
24
24
  # reference: https://localapi-doc-en.adspower.com/docs/6DSiws
25
25
  #
26
- def status
27
- url = "#{self.adspower_listener}/status"
28
- uri = URI.parse(url)
29
- res = Net::HTTP.get(uri)
30
- # show respose body
31
- return JSON.parse(res)['msg']
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
32
36
  end
33
37
 
34
38
  # send a post request to "#{url}/api/v1/user/create"
@@ -80,8 +84,8 @@ class AdsPowerClient
80
84
  #
81
85
  # reference: https://localapi-doc-en.adspower.com/docs/FFMFMf
82
86
  #
83
- def start(id)
84
- uri = URI.parse("#{self.adspower_listener}/api/v1/browser/start?user_id=#{id}&headless=1")
87
+ def start(id, headless=false)
88
+ uri = URI.parse("#{self.adspower_listener}/api/v1/browser/start?user_id=#{id}&headless=#{headless ? '1' : '0'}'}")
85
89
  res = Net::HTTP.get(uri)
86
90
  # show respose bo
87
91
  ret = JSON.parse(res)
@@ -105,9 +109,25 @@ class AdsPowerClient
105
109
  ret
106
110
  end
107
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
+
108
128
  #
109
- def driver(id)
110
- ret = self.start(id)
129
+ def driver(id, headless=false)
130
+ ret = self.start(id, headless)
111
131
 
112
132
  # Attach test execution to the existing browser
113
133
  # reference: https://zhiminzhan.medium.com/my-innovative-solution-to-test-automation-attach-test-execution-to-the-existing-browser-b90cda3b7d4a
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.3
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-07 00:00:00.000000000 Z
11
+ date: 2023-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uri