mass-client 1.0.39 → 1.0.40
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/lib/base-line/profile.rb +34 -116
- data/lib/first-line/profile_rpa.rb +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7ec4e04320c9b045e3fd167a0992413724da792d58809ee888ec044e8c2f4cf5
|
|
4
|
+
data.tar.gz: 2b8a3d0ddadc3b85b19947a813ff460d88a6001a6e5cdbd7c6c441659787bc57
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed1b3b52dd330363eeac43528265042f89890f210fb214cf387ce742f355317564ad41e096929bd0d3cc02bf901499293100a3b6cbae4818ff84a04258e2903b
|
|
7
|
+
data.tar.gz: c88c3f653e7e9db68e81a1a9f3a7a3e71b6086b23e6088d1e6e87a468922f4b5afb43a420937d15456acc7160e6835235d1a3e24afc5fdbfb79d485ba25fbb0f
|
data/lib/base-line/profile.rb
CHANGED
|
@@ -40,8 +40,24 @@ module Mass
|
|
|
40
40
|
# return
|
|
41
41
|
return public_url
|
|
42
42
|
elsif Mass.my_s3_api_key && Mass.my_s3_url
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
relative_path = File.dirname(s3_key.to_s)
|
|
44
|
+
relative_path = '' if relative_path == '.'
|
|
45
|
+
filename = File.basename(s3_key.to_s)
|
|
46
|
+
raise MyS3Error, 'Remote filename is required' if filename.to_s.strip.empty?
|
|
47
|
+
|
|
48
|
+
begin
|
|
49
|
+
client = my_s3_client
|
|
50
|
+
client.upload_file(
|
|
51
|
+
file_path: file_path,
|
|
52
|
+
path: relative_path,
|
|
53
|
+
filename: filename,
|
|
54
|
+
ensure_path: true
|
|
55
|
+
)
|
|
56
|
+
response = client.get_public_url(path: relative_path, filename: filename)
|
|
57
|
+
return response['public_url']
|
|
58
|
+
rescue MyS3::Client::Error => e
|
|
59
|
+
raise MyS3Error, e.message
|
|
60
|
+
end
|
|
45
61
|
end
|
|
46
62
|
end
|
|
47
63
|
|
|
@@ -54,7 +70,11 @@ module Mass
|
|
|
54
70
|
)
|
|
55
71
|
return true
|
|
56
72
|
elsif Mass.my_s3_api_key && Mass.my_s3_url
|
|
57
|
-
|
|
73
|
+
begin
|
|
74
|
+
my_s3_client.ensure_folder_chain(folder_name)
|
|
75
|
+
rescue MyS3::Client::Error => e
|
|
76
|
+
raise MyS3Error, e.message
|
|
77
|
+
end
|
|
58
78
|
return true
|
|
59
79
|
end
|
|
60
80
|
end
|
|
@@ -151,7 +171,7 @@ module Mass
|
|
|
151
171
|
# Proceed with Dropbox operations
|
|
152
172
|
year = Time.now.year.to_s.rjust(4, '0')
|
|
153
173
|
month = Time.now.month.to_s.rjust(2, '0')
|
|
154
|
-
folder = dropbox_folder #"/massprospecting.rpa/#{dropbox_folder}.#{year}.#{month}"
|
|
174
|
+
folder = "#{dropbox_folder}/leads" #"/massprospecting.rpa/#{dropbox_folder}.#{year}.#{month}"
|
|
155
175
|
path = "#{folder}/#{filename}"
|
|
156
176
|
create_s3_folder(folder)
|
|
157
177
|
|
|
@@ -287,120 +307,18 @@ module Mass
|
|
|
287
307
|
|
|
288
308
|
private
|
|
289
309
|
|
|
290
|
-
def
|
|
291
|
-
|
|
292
|
-
return true if sanitized.empty?
|
|
293
|
-
|
|
294
|
-
current = ''
|
|
295
|
-
sanitized.split('/').each do |segment|
|
|
296
|
-
parent = current
|
|
297
|
-
begin
|
|
298
|
-
my_s3_json_post('/create_folder.json', {
|
|
299
|
-
path: parent,
|
|
300
|
-
folder_name: segment
|
|
301
|
-
})
|
|
302
|
-
rescue MyS3Error => e
|
|
303
|
-
raise unless e.message =~ /folder already exists/i
|
|
304
|
-
end
|
|
305
|
-
current = parent.empty? ? segment : [parent, segment].join('/').gsub(%r{/+}, '/').sub(%r{^/+}, '')
|
|
306
|
-
end
|
|
307
|
-
|
|
308
|
-
true
|
|
309
|
-
end
|
|
310
|
-
|
|
311
|
-
def my_s3_upload_file(local_path, remote_path)
|
|
312
|
-
raise MyS3Error, 'Local file not found' unless File.file?(local_path)
|
|
313
|
-
|
|
314
|
-
relative_path = File.dirname(remote_path.to_s)
|
|
315
|
-
relative_path = '' if relative_path == '.'
|
|
316
|
-
filename = File.basename(remote_path.to_s).to_s
|
|
317
|
-
raise MyS3Error, 'Remote filename is required' if filename.strip.empty?
|
|
318
|
-
|
|
319
|
-
uri = my_s3_uri_for('/upload.json')
|
|
320
|
-
boundary = "----MassMyS3#{SecureRandom.hex(12)}"
|
|
321
|
-
request = Net::HTTP::Post.new(uri)
|
|
322
|
-
request['X-API-Key'] = my_s3_api_key!
|
|
323
|
-
request['Content-Type'] = "multipart/form-data; boundary=#{boundary}"
|
|
324
|
-
request.body = build_my_s3_multipart(boundary, relative_path, filename, local_path)
|
|
325
|
-
|
|
326
|
-
response = my_s3_http(uri).request(request)
|
|
327
|
-
json = parse_my_s3_json(response.body)
|
|
328
|
-
return json if response.is_a?(Net::HTTPSuccess) && json['success']
|
|
329
|
-
|
|
330
|
-
message = json.dig('error', 'message') || response.body
|
|
331
|
-
raise MyS3Error, message
|
|
332
|
-
end
|
|
333
|
-
|
|
334
|
-
def my_s3_public_url_for(remote_path)
|
|
335
|
-
dir = File.dirname(remote_path.to_s)
|
|
336
|
-
dir = '' if dir == '.'
|
|
337
|
-
filename = File.basename(remote_path.to_s)
|
|
338
|
-
raise MyS3Error, 'Filename is required for public URL generation' if filename.to_s.strip.empty?
|
|
339
|
-
|
|
340
|
-
response = my_s3_json_post('/get_public_url.json', {
|
|
341
|
-
path: dir,
|
|
342
|
-
filename: filename
|
|
343
|
-
})
|
|
310
|
+
def my_s3_client
|
|
311
|
+
require 'my_s3/client'
|
|
344
312
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
body = []
|
|
350
|
-
body << "--#{boundary}\r\n"
|
|
351
|
-
body << "Content-Disposition: form-data; name=\"path\"\r\n\r\n"
|
|
352
|
-
body << "#{relative_path}\r\n"
|
|
353
|
-
body << "--#{boundary}\r\n"
|
|
354
|
-
body << "Content-Disposition: form-data; name=\"file\"; filename=\"#{filename}\"\r\n"
|
|
355
|
-
body << "Content-Type: application/octet-stream\r\n\r\n"
|
|
356
|
-
body << File.binread(local_path)
|
|
357
|
-
body << "\r\n--#{boundary}--\r\n"
|
|
358
|
-
body.join
|
|
359
|
-
end
|
|
360
|
-
|
|
361
|
-
def my_s3_json_post(endpoint, payload)
|
|
362
|
-
uri = my_s3_uri_for(endpoint)
|
|
363
|
-
request = Net::HTTP::Post.new(uri)
|
|
364
|
-
request['Content-Type'] = 'application/json'
|
|
365
|
-
request['X-API-Key'] = my_s3_api_key!
|
|
366
|
-
request.body = JSON.generate(payload)
|
|
367
|
-
|
|
368
|
-
response = my_s3_http(uri).request(request)
|
|
369
|
-
json = parse_my_s3_json(response.body)
|
|
370
|
-
return json if response.is_a?(Net::HTTPSuccess) && json['success']
|
|
371
|
-
|
|
372
|
-
message = json.dig('error', 'message') || response.body
|
|
373
|
-
raise MyS3Error, message
|
|
374
|
-
end
|
|
375
|
-
|
|
376
|
-
def parse_my_s3_json(body)
|
|
377
|
-
return {} if body.nil? || body.strip.empty?
|
|
378
|
-
JSON.parse(body)
|
|
379
|
-
rescue JSON::ParserError
|
|
380
|
-
raise MyS3Error, "Invalid JSON response: #{body}"
|
|
381
|
-
end
|
|
382
|
-
|
|
383
|
-
def my_s3_uri_for(endpoint)
|
|
384
|
-
normalized = my_s3_base_url!
|
|
385
|
-
URI.join(normalized, endpoint.to_s.sub(%r{^/+}, ''))
|
|
386
|
-
end
|
|
387
|
-
|
|
388
|
-
def my_s3_http(uri)
|
|
389
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
|
390
|
-
http.use_ssl = uri.scheme == 'https'
|
|
391
|
-
http
|
|
392
|
-
end
|
|
393
|
-
|
|
394
|
-
def my_s3_base_url!
|
|
395
|
-
base = Mass.my_s3_url.to_s.strip
|
|
396
|
-
raise MyS3Error, 'Mass.my_s3_url is not configured' if base.empty?
|
|
397
|
-
base.end_with?('/') ? base : "#{base}/"
|
|
398
|
-
end
|
|
313
|
+
base_url = Mass.my_s3_url.to_s.strip
|
|
314
|
+
api_key = Mass.my_s3_api_key.to_s.strip
|
|
315
|
+
raise MyS3Error, 'Mass.my_s3_url is not configured' if base_url.empty?
|
|
316
|
+
raise MyS3Error, 'Mass.my_s3_api_key is not configured' if api_key.empty?
|
|
399
317
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
318
|
+
@my_s3_client ||= MyS3::Client.new(
|
|
319
|
+
base_url: base_url,
|
|
320
|
+
api_key: api_key
|
|
321
|
+
)
|
|
404
322
|
end
|
|
405
323
|
|
|
406
324
|
end # class Profile
|
|
@@ -244,7 +244,11 @@ module Mass
|
|
|
244
244
|
# return the URL of the file
|
|
245
245
|
def snapshot(dropbox_folder=nil)
|
|
246
246
|
raise "Either dropbox_folder parameter or self.desc['id_account'] are required." if dropbox_folder.nil? && self.desc['id_account'].nil?
|
|
247
|
-
|
|
247
|
+
if dropbox_folder.nil?
|
|
248
|
+
dropbox_folder = self.desc['id_account']
|
|
249
|
+
else
|
|
250
|
+
dropbox_folder = "#{self.desc['id_account']}/#{dropbox_folder}"
|
|
251
|
+
end
|
|
248
252
|
# parameters
|
|
249
253
|
id = SecureRandom.uuid
|
|
250
254
|
filename = "#{id}.html"
|
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.
|
|
4
|
+
version: 1.0.40
|
|
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: 2026-02-
|
|
11
|
+
date: 2026-02-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: timeout
|