mass-client 1.0.19 → 1.0.21

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: 8606bfe0664c8ac8cf9f5af547b4925ff5982957da2842e1650caba3d974c02e
4
- data.tar.gz: 0f72b71d5f681333ad318f23c1d27cc89267dc7a765ab72dc49d74e04356b6bd
3
+ metadata.gz: a9aa67c61c00611402f922ed7988f67bba40ccaab9db879440512fa1b2288bc4
4
+ data.tar.gz: 21f416174b865c81f5122d2242aea75b55acaae7224d5bc1bc7bef13e64b1f19
5
5
  SHA512:
6
- metadata.gz: d9506f4eb6db0fb7dd2785efc503ee239b33764e6cf1d0643099ab3ce9f913bdf00e280b1301288fe069f97db6d9ed50a1c358c5e57bd7254f753355be0b773f
7
- data.tar.gz: 7fce26002d9e2acf148330f23bb5c2ca4ced10fdcbf760b1e3d1286d35aa14bafff2f3057dc8fbe56f48b0f34894aff69263afdaff2670ebf1322d4aa5048011
6
+ metadata.gz: fdaca0893c886f465fbc617d4b301b5fca7552354bd4daf8d96731de5a4db7b9b0eb9a78500e1a842b21f6d3d6f64f8b12be963db44c0048d4c1f426ee0eed14
7
+ data.tar.gz: 9dc92ae9b578167df3835499c56bf44de27b94c78356f2972aacb8390f5600f5c5bcac0dbade36dc49e3105abe11653280cb9ba665dab861e7a4a4acd87501c9
@@ -101,7 +101,7 @@ module Mass
101
101
  #
102
102
  def connectioncheck(limit: 100, logger:nil)
103
103
  []
104
- end # def inboxcheck
104
+ end # def connectioncheck
105
105
 
106
106
  end # class Profile
107
107
  end # module Mass
@@ -113,7 +113,7 @@ module Mass
113
113
 
114
114
  # screenshot
115
115
  l.logs 'Screenshot... '
116
- job.desc['screenshots'] << job.profile.screenshot
116
+ job.desc['screenshots'] << job.profile.screenshot if job.profile.desc['allow_browser_to_download_multiple_files']
117
117
  l.logf 'done'.green + " (#{job.desc['screenshots'].size.to_s.blue} total)"
118
118
  end
119
119
  end
@@ -101,7 +101,7 @@ module Mass
101
101
 
102
102
  # stop the adspower server for headless mode, if it is not already stopped and if headless is activated.
103
103
  def self.clear_driver
104
- self.class.buffer_driver = nil
104
+ self.buffer_driver = nil
105
105
  end
106
106
 
107
107
  # close all tabs except one
@@ -175,7 +175,23 @@ module Mass
175
175
  automaticDownloads.find_element(:id => status.to_s).click()
176
176
  end # def automatic_downloads
177
177
 
178
-
178
+ # Waits for the presence of a file in specified file paths within a given timeout period.
179
+ # This function checks each file path in the provided array and returns the path of the
180
+ # first file it finds to exist. It raises an exception if none of the files are found
181
+ # within the specified timeout.
182
+ #
183
+ # @param file_paths [Array<String>] An array of file paths to check for the file's existence.
184
+ # @param timeout [Integer] The maximum number of seconds to wait for the file to appear.
185
+ # Default is 30 seconds.
186
+ #
187
+ # @return [String] The path of the first file found in `file_paths`.
188
+ # @raise [RuntimeError] If no file is found within the specified timeout, raises an error with a message
189
+ # listing the paths that were checked and the timeout duration.
190
+ #
191
+ # @example
192
+ # wait_for_file(['/path/to/file1', '/path/to/file2'], timeout: 60)
193
+ # # => "/path/to/file1" (if the file appears within 60 seconds)
194
+ #
179
195
  def wait_for_file(file_paths, timeout = 30)
180
196
  Timeout.timeout(timeout) do
181
197
  loop do
@@ -189,6 +205,45 @@ module Mass
189
205
  raise "Downloaded file not found in paths #{file_paths.join(',')} after #{timeout} seconds."
190
206
  end
191
207
 
208
+
209
+ # Retrieves the URL of a file stored in Dropbox with a timeout mechanism.
210
+ # This function continuously attempts to retrieve the file URL until it
211
+ # becomes available in Dropbox, up to a specified maximum wait time.
212
+ #
213
+ # @param path [String] The path to the file in Dropbox.
214
+ # @param max_wait [Integer] Maximum time to wait (in seconds) for the file to
215
+ # appear in Dropbox. Default is 30 seconds.
216
+ # @param interval [Integer] Time interval (in seconds) between each retry
217
+ # attempt. Default is 2 seconds.
218
+ #
219
+ # @return [String] The URL of the file in Dropbox, with the `&dl=1` parameter
220
+ # replaced by `&dl=0`.
221
+ # @raise [RuntimeError] If the file is not available within the specified
222
+ # maximum wait time, raises an error with a timeout message.
223
+ #
224
+ # @example
225
+ # wait_for_dropbox_url('/path/to/file', max_wait: 60, interval: 3)
226
+ # # => "https://www.dropbox.com/s/yourfile?dl=0"
227
+ #
228
+ def wait_for_dropbox_url(path, max_wait: 30, interval: 2)
229
+ start_time = Time.now
230
+
231
+ loop do
232
+ begin
233
+ # Try to get the file URL
234
+ return BlackStack::DropBox.get_file_url(path).gsub('&dl=1', '&dl=0')
235
+ rescue => e
236
+ # Check if the timeout has been exceeded
237
+ if Time.now - start_time > max_wait
238
+ raise "Timeout exceeded while waiting for file to appear in Dropbox: #{e.message}"
239
+ end
240
+
241
+ # Wait for a short interval before retrying
242
+ sleep(interval)
243
+ end
244
+ end
245
+ end
246
+
192
247
  # download image from Selenium using JavaScript and upload to Dropbox
193
248
  # return the URL of the screenshot
194
249
  #
@@ -274,8 +329,12 @@ module Mass
274
329
  BlackStack::DropBox.dropbox_upload_file(tmp_path, path)
275
330
  # Delete the local file
276
331
  File.delete(tmp_path)
332
+
277
333
  # Return the URL of the file in Dropbox
278
- BlackStack::DropBox.get_file_url(path).gsub('&dl=1', '&dl=0')
334
+ #
335
+ # Add a timeout to wait the file is present in the cloud.
336
+ # Reference: https://github.com/MassProspecting/docs/issues/320
337
+ self.wait_for_dropbox_url(path).gsub('&dl=1', '&dl=0')
279
338
  end
280
339
 
281
340
  # download image from Selenium using JavaScript and upload to Dropbox
@@ -344,7 +403,7 @@ module Mass
344
403
 
345
404
  self.class.buffer_driver = nil if !c.check(self.desc['ads_power_id'])
346
405
  sleep(1)
347
-
406
+
348
407
  if self.class.buffer_driver.nil?
349
408
  self.class.buffer_driver = c.driver(self.desc['ads_power_id'], headless)
350
409
  self.class.buffer_driver.manage.window.resize_to(self.desc['browser_width'], self.desc['browser_height'])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mass-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.19
4
+ version: 1.0.21
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: 2024-09-17 00:00:00.000000000 Z
11
+ date: 2024-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: timeout