mass-client 1.0.26 → 1.0.28

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6caaeba4da0bc4a9f86bfea21d99d1606b24760002ecad4a350b00f6f632abac
4
- data.tar.gz: 96d5d626cd5812a85c8d228f86d5aa4a9c49f655f8969de6cce71b52e5ef8eac
3
+ metadata.gz: f7c4826e872e8cac9f58e00d66b13939016c482087bba516a54cc1e34b28a5b2
4
+ data.tar.gz: a5b754e2e85610ad2007939372438ecdd3346db69e89dc1797607ed694ecd0d7
5
5
  SHA512:
6
- metadata.gz: 21f9d3e0407e37d6f2d97517c59bf1511e6870f13377dedb97b7c3814e068c0d8fcd8d4c992949b12116a56caf08a90499a2c4d5d95ed773ebe9bc7ad2dc2623
7
- data.tar.gz: '094e068d1434dfc38cd23830d22afb78b728ffe2ce670bb738fcff4c757a95eb51e9f8139472d7ee38dc2a30cbae440d785a8b0253c1cfd0046866b11af8e1b6'
6
+ metadata.gz: 7b75129bd6625ab47e806ee1819ad248d277bdff2320844f027c11c0f5eff8672915c807d673f906afaba8e2c686a97c39e38b4bc91d050af6a00bb43e85ffa5
7
+ data.tar.gz: b68638e7923e67948a43175dce9aba69f8817d910a57f7652aee0f3e21a94c51e8a097413f3345d7b66e193ef573f9b7dcbd579e17d7b0b30756e67ce5cb649a
@@ -4,7 +4,7 @@ module Mass
4
4
 
5
5
  # DROPBOX LOCKFILE PARAMETERS
6
6
  LOCKFILE_PATH = '/tmp/dropbox_upload.lock' # Path to your lockfile
7
- LOCK_TIMEOUT = 30 # Maximum time in seconds to wait for the lock
7
+ LOCK_TIMEOUT = 60 # Maximum time in seconds to wait for the lock
8
8
 
9
9
  # DROPBOX LOCKFILE FUNCTIONS
10
10
  def acquire_lock
@@ -26,22 +26,27 @@ module Mass
26
26
  File.delete(LOCKFILE_PATH) if File.exist?(LOCKFILE_PATH)
27
27
  end
28
28
 
29
- def upload_to_dropbox_with_lock(tmp_path, path)
30
- s = ''
31
- acquire_lock
32
- begin
33
- # Upload the file to Dropbox
34
- s = BlackStack::DropBox.dropbox_upload_file(tmp_path, path)
35
- json = JSON.parse(s)
36
- if json['is_downloadable'].nil? || !json['is_downloadable']
37
- raise "Dropbox file upload failed. Dropbox response: #{s}"
38
- end
39
- rescue => e
40
- raise "Error during upload: #{e.message} - Dropbox response: #{s}"
41
- ensure
42
- # Always release the lock, even if an error occurs
43
- release_lock
44
- end
29
+ # Function to upload a file to Amazon S3 and get its public URL
30
+ def upload_file_to_s3(file_path, s3_key)
31
+ # Upload the file
32
+ Mass.s3.put_object(
33
+ bucket: Mass.s3_bucket,
34
+ key: s3_key,
35
+ body: File.open(file_path)
36
+ )
37
+ # Generate the public URL
38
+ public_url = "https://#{Mass.s3_bucket}.s3.amazonaws.com/#{s3_key}"
39
+ # return
40
+ return public_url
41
+ end
42
+
43
+ # Function to create a folder in S3
44
+ def create_s3_folder(folder_name)
45
+ Mass.s3.put_object(
46
+ bucket: Mass.s3_bucket,
47
+ key: "#{folder_name}/"
48
+ )
49
+ return true
45
50
  end
46
51
 
47
52
  #
@@ -125,12 +130,12 @@ module Mass
125
130
  # Proceed with Dropbox operations
126
131
  year = Time.now.year.to_s.rjust(4, '0')
127
132
  month = Time.now.month.to_s.rjust(2, '0')
128
- folder = "/massprospecting.rpa/#{dropbox_folder}.#{year}.#{month}"
133
+ folder = dropbox_folder #"/massprospecting.rpa/#{dropbox_folder}.#{year}.#{month}"
129
134
  path = "#{folder}/#{filename}"
130
- BlackStack::DropBox.dropbox_create_folder(folder)
135
+ create_s3_folder(folder)
131
136
 
132
137
  # Upload the file to Dropbox
133
- upload_to_dropbox_with_lock(tmp_path, path)
138
+ ret = upload_file_to_s3(tmp_path, path)
134
139
 
135
140
  # Delete the local file
136
141
  File.delete(tmp_path)
@@ -139,7 +144,7 @@ module Mass
139
144
  #
140
145
  # Add a timeout to wait the file is present in the cloud.
141
146
  # Reference: https://github.com/MassProspecting/docs/issues/320
142
- self.wait_for_dropbox_url(path).gsub('&dl=1', '&dl=0')
147
+ ret
143
148
  end
144
149
 
145
150
  # download image from Selenium using JavaScript and upload to Dropbox
@@ -208,46 +208,6 @@ module Mass
208
208
  raise "Downloaded file not found in paths #{file_paths.join(',')} after #{timeout} seconds."
209
209
  end
210
210
 
211
-
212
- # Retrieves the URL of a file stored in Dropbox with a timeout mechanism.
213
- # This function continuously attempts to retrieve the file URL until it
214
- # becomes available in Dropbox, up to a specified maximum wait time.
215
- #
216
- # @param path [String] The path to the file in Dropbox.
217
- # @param max_wait [Integer] Maximum time to wait (in seconds) for the file to
218
- # appear in Dropbox. Default is 30 seconds.
219
- # @param interval [Integer] Time interval (in seconds) between each retry
220
- # attempt. Default is 2 seconds.
221
- #
222
- # @return [String] The URL of the file in Dropbox, with the `&dl=1` parameter
223
- # replaced by `&dl=0`.
224
- # @return nil If the file is not available within the specified
225
- # maximum wait time, raises an error with a timeout message.
226
- #
227
- # @example
228
- # wait_for_dropbox_url('/path/to/file', max_wait: 60, interval: 3)
229
- # # => "https://www.dropbox.com/s/yourfile?dl=0"
230
- #
231
- def wait_for_dropbox_url(path, max_wait: 5, interval: 2)
232
- start_time = Time.now
233
-
234
- loop do
235
- begin
236
- # Try to get the file URL
237
- return BlackStack::DropBox.get_file_url(path).gsub('&dl=1', '&dl=0')
238
- rescue => e
239
- # Check if the timeout has been exceeded
240
- if Time.now - start_time > max_wait
241
- #raise "Timeout exceeded while waiting for Dropbox file (#{path}): #{e.message}"
242
- return nil
243
- end
244
-
245
- # Wait for a short interval before retrying
246
- sleep(interval)
247
- end
248
- end
249
- end
250
-
251
211
  # take screenshot and upload it to dropbox
252
212
  # return the URL of the screenshot
253
213
  def screenshot(dropbox_folder=nil)
@@ -262,12 +222,12 @@ module Mass
262
222
  # code
263
223
  year = Time.now.year.to_s.rjust(4,'0')
264
224
  month = Time.now.month.to_s.rjust(2,'0')
265
- folder = "/massprospecting.rpa/#{dropbox_folder}.#{year}.#{month}"
225
+ folder = dropbox_folder #"/massprospecting.rpa/#{dropbox_folder}.#{year}.#{month}"
266
226
  path = "#{folder}/#{filename}"
267
- BlackStack::DropBox.dropbox_create_folder(folder)
268
- upload_to_dropbox_with_lock(tmp_path, path)
227
+ create_s3_folder(folder)
228
+ ret = upload_file_to_s3(tmp_path, path)
269
229
  File.delete(tmp_path)
270
- BlackStack::DropBox.get_file_url(path).gsub('&dl=1', '&dl=0')
230
+ ret
271
231
  end # def screenshot
272
232
 
273
233
  # create a file in the cloud with the HTML of the current page
@@ -284,12 +244,12 @@ module Mass
284
244
  # code
285
245
  year = Time.now.year.to_s.rjust(4,'0')
286
246
  month = Time.now.month.to_s.rjust(2,'0')
287
- folder = "/massprospecting.bots/#{dropbox_folder}.#{year}.#{month}"
247
+ folder = dropbox_folder #"/massprospecting.bots/#{dropbox_folder}.#{year}.#{month}"
288
248
  path = "#{folder}/#{filename}"
289
- BlackStack::DropBox.dropbox_create_folder(folder)
290
- upload_to_dropbox_with_lock(tmp_path, path)
249
+ create_s3_folder(folder)
250
+ ret = upload_file_to_s3(tmp_path, path)
291
251
  File.delete(tmp_path)
292
- BlackStack::DropBox.get_file_url(path).gsub('&dl=1', '&dl=0')
252
+ ret
293
253
  end # def snapshot
294
254
 
295
255
  # return a selnium driver for this profile
data/lib/mass-client.rb CHANGED
@@ -8,12 +8,19 @@ require 'colorize'
8
8
  require 'timeout'
9
9
  require 'base64'
10
10
  require 'adspower-client'
11
+ require 'aws-sdk-s3' # Ensure the AWS SDK for S3 is installed
11
12
 
12
13
  # mass client configuration
13
14
  module Mass
14
15
  @@js_path
15
16
  @@drownload_path
16
17
  @@api_client
18
+
19
+ @@s3_bucket
20
+ @@s3_region
21
+ @@s3_access_key_id
22
+ @@s3_secret_access_key
23
+ @@s3
17
24
 
18
25
  # set the MassProspecting API client
19
26
  #
@@ -21,21 +28,33 @@ module Mass
21
28
  #
22
29
  # api_key: Mandatory. The API key of your MassProspecting account.
23
30
  # subaccount: Optional. The name of the subaccount you want to work with. If you provide a subaccount, the SDK will call the master to get the URL and port of the subaccount. Default is nil.
31
+ #
24
32
  # api_url: Optional. The URL of the MassProspecting API. Default is 'https://massprospecting.com'.
25
33
  # api_port: Optional. The port of the MassProspecting API. Default is 443.
26
34
  # api_version: Optional. The version of the MassProspecting API. Default is '1.0'.
35
+ #
27
36
  # backtrace: Optional. If true, the backtrace of the exceptions will be returned by the access points. If false, only an error description is returned. Default is false.
37
+ #
28
38
  # js_path: Optional. The path to the JavaScript file to be used by the SDK. Default is nil.
29
39
  # download_path: Optional. The path to the download folder(s) to be used by the SDK. Default is [].
40
+
30
41
  def self.set(
31
42
  api_key: ,
32
43
  subaccount: nil,
44
+
33
45
  api_url: 'https://massprospecting.com',
34
46
  api_port: 443,
35
47
  api_version: '1.0',
48
+
36
49
  backtrace: false,
50
+
37
51
  js_path: nil,
38
- download_path: []
52
+ download_path: [],
53
+
54
+ s3_region: nil,
55
+ s3_access_key_id: nil,
56
+ s3_secret_access_key: nil,
57
+ s3_bucket: nil
39
58
  )
40
59
  # call the master to get the URL and port of the subaccount.
41
60
  BlackStack::API.set_client(
@@ -78,6 +97,25 @@ module Mass
78
97
 
79
98
  @@js_path = js_path
80
99
  @@download_path = download_path
100
+
101
+ @@s3_region = s3_region
102
+ @@s3_access_key_id = s3_access_key_id
103
+ @@s3_secret_access_key = s3_secret_access_key
104
+ @@s3_bucket = s3_bucket
105
+
106
+ # Initialize the S3 client
107
+ if (
108
+ @@s3_region
109
+ @@s3_access_key_id
110
+ @@s3_secret_access_key
111
+ @@s3_bucket
112
+ )
113
+ @@s3 = Aws::S3::Client.new(
114
+ region: @@s3_region,
115
+ access_key_id: @@s3_access_key_id,
116
+ secret_access_key: @@s3_secret_access_key
117
+ )
118
+ end
81
119
  end
82
120
 
83
121
  def self.download_path
@@ -87,6 +125,27 @@ module Mass
87
125
  def self.js_path
88
126
  @@js_path
89
127
  end
128
+
129
+ def self.s3_region
130
+ @@s3_region
131
+ end
132
+
133
+ def self.s3_access_key_id
134
+ @@s3_access_key_id
135
+ end
136
+
137
+ def self.s3_secret_access_key
138
+ @@s3_secret_access_key
139
+ end
140
+
141
+ def self.s3_bucket
142
+ @@s3_bucket
143
+ end
144
+
145
+ def self.s3
146
+ @@s3
147
+ end
148
+
90
149
  end # module Mass
91
150
 
92
151
  # base classes
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.26
4
+ version: 1.0.28
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-10-29 00:00:00.000000000 Z
11
+ date: 2024-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: timeout
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: 1.0.14
153
+ - !ruby/object:Gem::Dependency
154
+ name: aws-sdk-s3
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 1.169.0
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 1.169.0
153
167
  description: Ruby library for MassProspecting API.
154
168
  email: leandro@massprospecting.com
155
169
  executables: []