filestack 2.2.1 → 2.3.0
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/CHANGELOG.md +3 -0
- data/README.md +36 -46
- data/VERSION +1 -1
- data/docs/FilestackCommon.html +293 -293
- data/docs/FilestackFilelink.html +463 -463
- data/docs/IntelligentUtils.html +537 -537
- data/docs/MultipartUploadUtils.html +18 -18
- data/docs/Transform.html +3 -3
- data/docs/UploadUtils.html +7 -7
- data/filestack-ruby.gemspec +2 -2
- data/lib/filestack/mixins/filestack_common.rb +1 -1
- data/lib/filestack/models/filelink.rb +4 -4
- data/lib/filestack/models/filestack_transform.rb +1 -1
- data/lib/filestack/ruby/version.rb +1 -1
- data/lib/filestack/utils/multipart_upload_utils.rb +19 -20
- data/lib/filestack/utils/utils.rb +33 -35
- metadata +6 -6
|
@@ -163,7 +163,7 @@
|
|
|
163
163
|
<li class="public ">
|
|
164
164
|
<span class="summary_signature">
|
|
165
165
|
|
|
166
|
-
<a href="#multipart_complete-instance_method" title="#multipart_complete (instance method)">#<strong>multipart_complete</strong>(apikey, filename, filesize, mimetype, start_response, parts_and_etags, options, intelligent = false) ⇒
|
|
166
|
+
<a href="#multipart_complete-instance_method" title="#multipart_complete (instance method)">#<strong>multipart_complete</strong>(apikey, filename, filesize, mimetype, start_response, parts_and_etags, options, intelligent = false) ⇒ Typhoeus::Response </a>
|
|
167
167
|
|
|
168
168
|
|
|
169
169
|
|
|
@@ -187,7 +187,7 @@
|
|
|
187
187
|
<li class="public ">
|
|
188
188
|
<span class="summary_signature">
|
|
189
189
|
|
|
190
|
-
<a href="#multipart_start-instance_method" title="#multipart_start (instance method)">#<strong>multipart_start</strong>(apikey, filename, filesize, mimetype, security, options) ⇒
|
|
190
|
+
<a href="#multipart_start-instance_method" title="#multipart_start (instance method)">#<strong>multipart_start</strong>(apikey, filename, filesize, mimetype, security, options) ⇒ Typhoeus::Response </a>
|
|
191
191
|
|
|
192
192
|
|
|
193
193
|
|
|
@@ -211,7 +211,7 @@
|
|
|
211
211
|
<li class="public ">
|
|
212
212
|
<span class="summary_signature">
|
|
213
213
|
|
|
214
|
-
<a href="#multipart_upload-instance_method" title="#multipart_upload (instance method)">#<strong>multipart_upload</strong>(apikey, filepath, security, options, timeout, intelligent: false) ⇒
|
|
214
|
+
<a href="#multipart_upload-instance_method" title="#multipart_upload (instance method)">#<strong>multipart_upload</strong>(apikey, filepath, security, options, timeout, intelligent: false) ⇒ Typhoeus::Response </a>
|
|
215
215
|
|
|
216
216
|
|
|
217
217
|
|
|
@@ -259,7 +259,7 @@
|
|
|
259
259
|
<li class="public ">
|
|
260
260
|
<span class="summary_signature">
|
|
261
261
|
|
|
262
|
-
<a href="#upload_chunk-instance_method" title="#upload_chunk (instance method)">#<strong>upload_chunk</strong>(job, apikey, filepath, options) ⇒
|
|
262
|
+
<a href="#upload_chunk-instance_method" title="#upload_chunk (instance method)">#<strong>upload_chunk</strong>(job, apikey, filepath, options) ⇒ Typhoeus::Response </a>
|
|
263
263
|
|
|
264
264
|
|
|
265
265
|
|
|
@@ -379,7 +379,7 @@
|
|
|
379
379
|
<span class='name'>start_response</span>
|
|
380
380
|
|
|
381
381
|
|
|
382
|
-
<span class='type'>(<tt>
|
|
382
|
+
<span class='type'>(<tt>Typhoeus::Response</tt>)</span>
|
|
383
383
|
|
|
384
384
|
|
|
385
385
|
|
|
@@ -546,7 +546,7 @@
|
|
|
546
546
|
<div class="method_details ">
|
|
547
547
|
<h3 class="signature " id="multipart_complete-instance_method">
|
|
548
548
|
|
|
549
|
-
#<strong>multipart_complete</strong>(apikey, filename, filesize, mimetype, start_response, parts_and_etags, options, intelligent = false) ⇒ <tt>
|
|
549
|
+
#<strong>multipart_complete</strong>(apikey, filename, filesize, mimetype, start_response, parts_and_etags, options, intelligent = false) ⇒ <tt>Typhoeus::Response</tt>
|
|
550
550
|
|
|
551
551
|
|
|
552
552
|
|
|
@@ -633,7 +633,7 @@
|
|
|
633
633
|
<span class='name'>start_response</span>
|
|
634
634
|
|
|
635
635
|
|
|
636
|
-
<span class='type'>(<tt>
|
|
636
|
+
<span class='type'>(<tt>Typhoeus::Response</tt>)</span>
|
|
637
637
|
|
|
638
638
|
|
|
639
639
|
|
|
@@ -700,7 +700,7 @@
|
|
|
700
700
|
<li>
|
|
701
701
|
|
|
702
702
|
|
|
703
|
-
<span class='type'>(<tt>
|
|
703
|
+
<span class='type'>(<tt>Typhoeus::Response</tt>)</span>
|
|
704
704
|
|
|
705
705
|
|
|
706
706
|
|
|
@@ -783,7 +783,7 @@
|
|
|
783
783
|
<span class='kw'>end</span>
|
|
784
784
|
<span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='id identifier rubyid_data'>data</span><span class='period'>.</span><span class='id identifier rubyid_merge!'>merge!</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_options'>options</span>
|
|
785
785
|
|
|
786
|
-
<span class='const'>
|
|
786
|
+
<span class='const'>Typhoeus</span><span class='period'>.</span><span class='id identifier rubyid_post'>post</span><span class='lparen'>(</span>
|
|
787
787
|
<span class='const'><span class='object_link'><a href="FilestackConfig.html" title="FilestackConfig (class)">FilestackConfig</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FilestackConfig.html#MULTIPART_COMPLETE_URL-constant" title="FilestackConfig::MULTIPART_COMPLETE_URL (constant)">MULTIPART_COMPLETE_URL</a></span></span><span class='comma'>,</span> <span class='label'>parameters:</span> <span class='id identifier rubyid_data'>data</span><span class='comma'>,</span>
|
|
788
788
|
<span class='label'>headers:</span> <span class='const'><span class='object_link'><a href="FilestackConfig.html" title="FilestackConfig (class)">FilestackConfig</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FilestackConfig.html#HEADERS-constant" title="FilestackConfig::HEADERS (constant)">HEADERS</a></span></span>
|
|
789
789
|
<span class='rparen'>)</span>
|
|
@@ -796,7 +796,7 @@
|
|
|
796
796
|
<div class="method_details ">
|
|
797
797
|
<h3 class="signature " id="multipart_start-instance_method">
|
|
798
798
|
|
|
799
|
-
#<strong>multipart_start</strong>(apikey, filename, filesize, mimetype, security, options) ⇒ <tt>
|
|
799
|
+
#<strong>multipart_start</strong>(apikey, filename, filesize, mimetype, security, options) ⇒ <tt>Typhoeus::Response</tt>
|
|
800
800
|
|
|
801
801
|
|
|
802
802
|
|
|
@@ -918,7 +918,7 @@
|
|
|
918
918
|
<li>
|
|
919
919
|
|
|
920
920
|
|
|
921
|
-
<span class='type'>(<tt>
|
|
921
|
+
<span class='type'>(<tt>Typhoeus::Response</tt>)</span>
|
|
922
922
|
|
|
923
923
|
|
|
924
924
|
|
|
@@ -982,7 +982,7 @@
|
|
|
982
982
|
<span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:signature</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_security'>security</span><span class='period'>.</span><span class='id identifier rubyid_signature'>signature</span>
|
|
983
983
|
<span class='kw'>end</span>
|
|
984
984
|
|
|
985
|
-
<span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='const'>
|
|
985
|
+
<span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='const'>Typhoeus</span><span class='period'>.</span><span class='id identifier rubyid_post'>post</span><span class='lparen'>(</span>
|
|
986
986
|
<span class='const'><span class='object_link'><a href="FilestackConfig.html" title="FilestackConfig (class)">FilestackConfig</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FilestackConfig.html#MULTIPART_START_URL-constant" title="FilestackConfig::MULTIPART_START_URL (constant)">MULTIPART_START_URL</a></span></span><span class='comma'>,</span> <span class='label'>parameters:</span> <span class='id identifier rubyid_params'>params</span><span class='comma'>,</span>
|
|
987
987
|
<span class='label'>headers:</span> <span class='const'><span class='object_link'><a href="FilestackConfig.html" title="FilestackConfig (class)">FilestackConfig</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FilestackConfig.html#HEADERS-constant" title="FilestackConfig::HEADERS (constant)">HEADERS</a></span></span>
|
|
988
988
|
<span class='rparen'>)</span>
|
|
@@ -1000,7 +1000,7 @@
|
|
|
1000
1000
|
<div class="method_details ">
|
|
1001
1001
|
<h3 class="signature " id="multipart_upload-instance_method">
|
|
1002
1002
|
|
|
1003
|
-
#<strong>multipart_upload</strong>(apikey, filepath, security, options, timeout, intelligent: false) ⇒ <tt>
|
|
1003
|
+
#<strong>multipart_upload</strong>(apikey, filepath, security, options, timeout, intelligent: false) ⇒ <tt>Typhoeus::Response</tt>
|
|
1004
1004
|
|
|
1005
1005
|
|
|
1006
1006
|
|
|
@@ -1090,7 +1090,7 @@
|
|
|
1090
1090
|
<li>
|
|
1091
1091
|
|
|
1092
1092
|
|
|
1093
|
-
<span class='type'>(<tt>
|
|
1093
|
+
<span class='type'>(<tt>Typhoeus::Response</tt>)</span>
|
|
1094
1094
|
|
|
1095
1095
|
|
|
1096
1096
|
|
|
@@ -1345,7 +1345,7 @@
|
|
|
1345
1345
|
<div class="method_details ">
|
|
1346
1346
|
<h3 class="signature " id="upload_chunk-instance_method">
|
|
1347
1347
|
|
|
1348
|
-
#<strong>upload_chunk</strong>(job, apikey, filepath, options) ⇒ <tt>
|
|
1348
|
+
#<strong>upload_chunk</strong>(job, apikey, filepath, options) ⇒ <tt>Typhoeus::Response</tt>
|
|
1349
1349
|
|
|
1350
1350
|
|
|
1351
1351
|
|
|
@@ -1451,7 +1451,7 @@
|
|
|
1451
1451
|
<li>
|
|
1452
1452
|
|
|
1453
1453
|
|
|
1454
|
-
<span class='type'>(<tt>
|
|
1454
|
+
<span class='type'>(<tt>Typhoeus::Response</tt>)</span>
|
|
1455
1455
|
|
|
1456
1456
|
|
|
1457
1457
|
|
|
@@ -1515,11 +1515,11 @@
|
|
|
1515
1515
|
<span class='label'>file:</span> <span class='const'>Tempfile</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_job'>job</span><span class='lbracket'>[</span><span class='symbol'>:filename</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
|
1516
1516
|
<span class='rbrace'>}</span>
|
|
1517
1517
|
<span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='id identifier rubyid_data'>data</span><span class='period'>.</span><span class='id identifier rubyid_merge!'>merge!</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_options'>options</span>
|
|
1518
|
-
<span class='id identifier rubyid_fs_response'>fs_response</span> <span class='op'>=</span> <span class='const'>
|
|
1518
|
+
<span class='id identifier rubyid_fs_response'>fs_response</span> <span class='op'>=</span> <span class='const'>Typhoeus</span><span class='period'>.</span><span class='id identifier rubyid_post'>post</span><span class='lparen'>(</span>
|
|
1519
1519
|
<span class='const'><span class='object_link'><a href="FilestackConfig.html" title="FilestackConfig (class)">FilestackConfig</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FilestackConfig.html#MULTIPART_UPLOAD_URL-constant" title="FilestackConfig::MULTIPART_UPLOAD_URL (constant)">MULTIPART_UPLOAD_URL</a></span></span><span class='comma'>,</span> <span class='label'>parameters:</span> <span class='id identifier rubyid_data'>data</span><span class='comma'>,</span>
|
|
1520
1520
|
<span class='label'>headers:</span> <span class='const'><span class='object_link'><a href="FilestackConfig.html" title="FilestackConfig (class)">FilestackConfig</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FilestackConfig.html#HEADERS-constant" title="FilestackConfig::HEADERS (constant)">HEADERS</a></span></span>
|
|
1521
1521
|
<span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_body'>body</span>
|
|
1522
|
-
<span class='const'>
|
|
1522
|
+
<span class='const'>Typhoeus</span><span class='period'>.</span><span class='id identifier rubyid_put'>put</span><span class='lparen'>(</span>
|
|
1523
1523
|
<span class='id identifier rubyid_fs_response'>fs_response</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>url</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>headers:</span> <span class='id identifier rubyid_fs_response'>fs_response</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>headers</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>parameters:</span> <span class='id identifier rubyid_chunk'>chunk</span>
|
|
1524
1524
|
<span class='rparen'>)</span>
|
|
1525
1525
|
<span class='kw'>end</span></pre>
|
data/docs/Transform.html
CHANGED
|
@@ -249,7 +249,7 @@
|
|
|
249
249
|
<li class="public ">
|
|
250
250
|
<span class="summary_signature">
|
|
251
251
|
|
|
252
|
-
<a href="#debug-instance_method" title="#debug (instance method)">#<strong>debug</strong> ⇒
|
|
252
|
+
<a href="#debug-instance_method" title="#debug (instance method)">#<strong>debug</strong> ⇒ Typhoeus::Response </a>
|
|
253
253
|
|
|
254
254
|
|
|
255
255
|
|
|
@@ -805,7 +805,7 @@ chaining</p>
|
|
|
805
805
|
<div class="method_details ">
|
|
806
806
|
<h3 class="signature " id="debug-instance_method">
|
|
807
807
|
|
|
808
|
-
#<strong>debug</strong> ⇒ <tt>
|
|
808
|
+
#<strong>debug</strong> ⇒ <tt>Typhoeus::Response</tt>
|
|
809
809
|
|
|
810
810
|
|
|
811
811
|
|
|
@@ -827,7 +827,7 @@ chaining</p>
|
|
|
827
827
|
<li>
|
|
828
828
|
|
|
829
829
|
|
|
830
|
-
<span class='type'>(<tt>
|
|
830
|
+
<span class='type'>(<tt>Typhoeus::Response</tt>)</span>
|
|
831
831
|
|
|
832
832
|
|
|
833
833
|
|
data/docs/UploadUtils.html
CHANGED
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
<li class="public ">
|
|
142
142
|
<span class="summary_signature">
|
|
143
143
|
|
|
144
|
-
<a href="#make_call-instance_method" title="#make_call (instance method)">#<strong>make_call</strong>(url, action, parameters: nil, headers: nil) ⇒
|
|
144
|
+
<a href="#make_call-instance_method" title="#make_call (instance method)">#<strong>make_call</strong>(url, action, parameters: nil, headers: nil) ⇒ Typhoeus::Request </a>
|
|
145
145
|
|
|
146
146
|
|
|
147
147
|
|
|
@@ -165,7 +165,7 @@
|
|
|
165
165
|
<li class="public ">
|
|
166
166
|
<span class="summary_signature">
|
|
167
167
|
|
|
168
|
-
<a href="#send_upload-instance_method" title="#send_upload (instance method)">#<strong>send_upload</strong>(apikey, filepath: nil, external_url: nil, security: nil, options: nil, storage: 'S3') ⇒
|
|
168
|
+
<a href="#send_upload-instance_method" title="#send_upload (instance method)">#<strong>send_upload</strong>(apikey, filepath: nil, external_url: nil, security: nil, options: nil, storage: 'S3') ⇒ Typhoeus::Response </a>
|
|
169
169
|
|
|
170
170
|
|
|
171
171
|
|
|
@@ -344,7 +344,7 @@
|
|
|
344
344
|
<div class="method_details ">
|
|
345
345
|
<h3 class="signature " id="make_call-instance_method">
|
|
346
346
|
|
|
347
|
-
#<strong>make_call</strong>(url, action, parameters: nil, headers: nil) ⇒ <tt>
|
|
347
|
+
#<strong>make_call</strong>(url, action, parameters: nil, headers: nil) ⇒ <tt>Typhoeus::Request</tt>
|
|
348
348
|
|
|
349
349
|
|
|
350
350
|
|
|
@@ -419,7 +419,7 @@
|
|
|
419
419
|
<li>
|
|
420
420
|
|
|
421
421
|
|
|
422
|
-
<span class='type'>(<tt>
|
|
422
|
+
<span class='type'>(<tt>Typhoeus::Request</tt>)</span>
|
|
423
423
|
|
|
424
424
|
|
|
425
425
|
|
|
@@ -453,7 +453,7 @@
|
|
|
453
453
|
<span class='kw'>else</span>
|
|
454
454
|
<span class='const'><span class='object_link'><a href="FilestackConfig.html" title="FilestackConfig (class)">FilestackConfig</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FilestackConfig.html#HEADERS-constant" title="FilestackConfig::HEADERS (constant)">HEADERS</a></span></span>
|
|
455
455
|
<span class='kw'>end</span>
|
|
456
|
-
<span class='const'>
|
|
456
|
+
<span class='const'>Typhoeus</span><span class='period'>.</span><span class='id identifier rubyid_public_send'>public_send</span><span class='lparen'>(</span>
|
|
457
457
|
<span class='id identifier rubyid_action'>action</span><span class='comma'>,</span> <span class='id identifier rubyid_url'>url</span><span class='comma'>,</span> <span class='label'>parameters:</span> <span class='id identifier rubyid_parameters'>parameters</span><span class='comma'>,</span> <span class='label'>headers:</span> <span class='id identifier rubyid_headers'>headers</span>
|
|
458
458
|
<span class='rparen'>)</span>
|
|
459
459
|
<span class='kw'>end</span></pre>
|
|
@@ -465,7 +465,7 @@
|
|
|
465
465
|
<div class="method_details ">
|
|
466
466
|
<h3 class="signature " id="send_upload-instance_method">
|
|
467
467
|
|
|
468
|
-
#<strong>send_upload</strong>(apikey, filepath: nil, external_url: nil, security: nil, options: nil, storage: 'S3') ⇒ <tt>
|
|
468
|
+
#<strong>send_upload</strong>(apikey, filepath: nil, external_url: nil, security: nil, options: nil, storage: 'S3') ⇒ <tt>Typhoeus::Response</tt>
|
|
469
469
|
|
|
470
470
|
|
|
471
471
|
|
|
@@ -587,7 +587,7 @@
|
|
|
587
587
|
<li>
|
|
588
588
|
|
|
589
589
|
|
|
590
|
-
<span class='type'>(<tt>
|
|
590
|
+
<span class='type'>(<tt>Typhoeus::Response</tt>)</span>
|
|
591
591
|
|
|
592
592
|
|
|
593
593
|
|
data/filestack-ruby.gemspec
CHANGED
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
23
23
|
spec.require_paths = ["lib"]
|
|
24
24
|
|
|
25
|
-
spec.add_dependency "
|
|
25
|
+
spec.add_dependency "typhoeus", "~> 1.1"
|
|
26
26
|
spec.add_dependency "parallel", "~> 1.11.2"
|
|
27
27
|
spec.add_dependency "mimemagic", "~> 0.3.2"
|
|
28
28
|
spec.add_dependency "progress_bar"
|
|
@@ -31,4 +31,4 @@ Gem::Specification.new do |spec|
|
|
|
31
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
|
32
32
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
33
33
|
spec.add_development_dependency "simplecov", "~> 0.14"
|
|
34
|
-
end
|
|
34
|
+
end
|
|
@@ -33,7 +33,7 @@ module FilestackCommon
|
|
|
33
33
|
# @param [String] url The url of the Filehandle
|
|
34
34
|
# to be deleted (includes security)
|
|
35
35
|
#
|
|
36
|
-
# @return [
|
|
36
|
+
# @return [Typhoeus::Response]
|
|
37
37
|
def send_delete(handle, apikey, security)
|
|
38
38
|
return 'Delete requires security' if security.nil?
|
|
39
39
|
signature = security.signature
|
|
@@ -35,14 +35,14 @@ class FilestackFilelink
|
|
|
35
35
|
#
|
|
36
36
|
# @param [String] filepath The local destination of the
|
|
37
37
|
# downloaded filelink
|
|
38
|
-
# @return [
|
|
38
|
+
# @return [Typhoeus::Response]
|
|
39
39
|
def download(filepath)
|
|
40
40
|
send_download(url, filepath)
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
# Delete filelink
|
|
44
44
|
#
|
|
45
|
-
# @return [
|
|
45
|
+
# @return [Typhoeus::Response]
|
|
46
46
|
def delete
|
|
47
47
|
send_delete(handle, apikey, security)
|
|
48
48
|
end
|
|
@@ -51,7 +51,7 @@ class FilestackFilelink
|
|
|
51
51
|
#
|
|
52
52
|
# @param [String] filepath filepath of file to upload
|
|
53
53
|
#
|
|
54
|
-
# @return [
|
|
54
|
+
# @return [Typhoeus::Response]
|
|
55
55
|
def overwrite(filepath)
|
|
56
56
|
send_overwrite(filepath, handle, apikey, security)
|
|
57
57
|
end
|
|
@@ -73,7 +73,7 @@ class FilestackFilelink
|
|
|
73
73
|
|
|
74
74
|
# Return metadata for file handle
|
|
75
75
|
#
|
|
76
|
-
# @return [
|
|
76
|
+
# @return [Typhoeus::Response]
|
|
77
77
|
def metadata(params = {})
|
|
78
78
|
send_metadata(@handle, @security, params)
|
|
79
79
|
end
|
|
@@ -3,14 +3,13 @@ require 'digest'
|
|
|
3
3
|
require 'mimemagic'
|
|
4
4
|
require 'json'
|
|
5
5
|
require 'parallel'
|
|
6
|
-
require '
|
|
6
|
+
require 'typhoeus'
|
|
7
7
|
require 'progress_bar'
|
|
8
8
|
require 'filestack/config'
|
|
9
9
|
require 'filestack/utils/utils'
|
|
10
10
|
|
|
11
11
|
include UploadUtils
|
|
12
12
|
include IntelligentUtils
|
|
13
|
-
Unirest.timeout(30)
|
|
14
13
|
# Includes all the utility functions for Filestack multipart uploads
|
|
15
14
|
module MultipartUploadUtils
|
|
16
15
|
def get_file_info(file)
|
|
@@ -34,7 +33,7 @@ module MultipartUploadUtils
|
|
|
34
33
|
# @param [Hash] options User-defined options for
|
|
35
34
|
# multipart uploads
|
|
36
35
|
#
|
|
37
|
-
# @return [
|
|
36
|
+
# @return [Typhoeus::Response]
|
|
38
37
|
def multipart_start(apikey, filename, filesize, mimetype, security, options)
|
|
39
38
|
params = {
|
|
40
39
|
apikey: apikey,
|
|
@@ -53,8 +52,8 @@ module MultipartUploadUtils
|
|
|
53
52
|
params[:signature] = security.signature
|
|
54
53
|
end
|
|
55
54
|
|
|
56
|
-
response =
|
|
57
|
-
FilestackConfig::MULTIPART_START_URL,
|
|
55
|
+
response = Typhoeus.post(
|
|
56
|
+
FilestackConfig::MULTIPART_START_URL, body: params,
|
|
58
57
|
headers: FilestackConfig::HEADERS
|
|
59
58
|
)
|
|
60
59
|
if response.code == 200
|
|
@@ -70,7 +69,7 @@ module MultipartUploadUtils
|
|
|
70
69
|
# @param [String] filename Name of incoming file
|
|
71
70
|
# @param [String] filepath Local path to file
|
|
72
71
|
# @param [Int] filesize Size of incoming file
|
|
73
|
-
# @param [
|
|
72
|
+
# @param [Typhoeus::Response] start_response Response body from
|
|
74
73
|
# multipart_start
|
|
75
74
|
# @param [Hash] options User-defined options for
|
|
76
75
|
# multipart uploads
|
|
@@ -109,7 +108,7 @@ module MultipartUploadUtils
|
|
|
109
108
|
jobs
|
|
110
109
|
end
|
|
111
110
|
|
|
112
|
-
|
|
111
|
+
|
|
113
112
|
# Uploads one chunk of the file
|
|
114
113
|
#
|
|
115
114
|
# @param [Hash] job Hash of options needed
|
|
@@ -121,12 +120,12 @@ module MultipartUploadUtils
|
|
|
121
120
|
# @param [Hash] options User-defined options for
|
|
122
121
|
# multipart uploads
|
|
123
122
|
#
|
|
124
|
-
# @return [
|
|
123
|
+
# @return [Typhoeus::Response]
|
|
125
124
|
def upload_chunk(job, apikey, filepath, options)
|
|
126
125
|
file = File.open(filepath)
|
|
127
126
|
file.seek(job[:seek])
|
|
128
127
|
chunk = file.read(FilestackConfig::DEFAULT_CHUNK_SIZE)
|
|
129
|
-
|
|
128
|
+
|
|
130
129
|
md5 = Digest::MD5.new
|
|
131
130
|
md5 << chunk
|
|
132
131
|
data = {
|
|
@@ -141,12 +140,12 @@ module MultipartUploadUtils
|
|
|
141
140
|
file: Tempfile.new(job[:filename])
|
|
142
141
|
}
|
|
143
142
|
data = data.merge!(options) if options
|
|
144
|
-
fs_response =
|
|
145
|
-
FilestackConfig::MULTIPART_UPLOAD_URL,
|
|
143
|
+
fs_response = Typhoeus.post(
|
|
144
|
+
FilestackConfig::MULTIPART_UPLOAD_URL, body: data,
|
|
146
145
|
headers: FilestackConfig::HEADERS
|
|
147
146
|
).body
|
|
148
|
-
|
|
149
|
-
fs_response['url'], headers: fs_response['headers'],
|
|
147
|
+
Typhoeus.put(
|
|
148
|
+
fs_response['url'], headers: fs_response['headers'], body: chunk
|
|
150
149
|
)
|
|
151
150
|
end
|
|
152
151
|
# Runs all jobs in parallel
|
|
@@ -164,7 +163,7 @@ module MultipartUploadUtils
|
|
|
164
163
|
response = upload_chunk(
|
|
165
164
|
job, apikey, filepath, options
|
|
166
165
|
)
|
|
167
|
-
if response.code == 200
|
|
166
|
+
if response.code == 200
|
|
168
167
|
bar.increment!
|
|
169
168
|
part = job[:part]
|
|
170
169
|
etag = response.headers[:etag]
|
|
@@ -179,7 +178,7 @@ module MultipartUploadUtils
|
|
|
179
178
|
# @param [String] filename Name of incoming file
|
|
180
179
|
# @param [Int] filesize Size of incoming file
|
|
181
180
|
# @param [String] mimetype Mimetype of incoming file
|
|
182
|
-
# @param [
|
|
181
|
+
# @param [Typhoeus::Response] start_response Response body from
|
|
183
182
|
# multipart_start
|
|
184
183
|
# @param [FilestackSecurity] security Security object with
|
|
185
184
|
# policy/signature
|
|
@@ -189,7 +188,7 @@ module MultipartUploadUtils
|
|
|
189
188
|
# @param [Hash] options User-defined options for
|
|
190
189
|
# multipart uploads
|
|
191
190
|
#
|
|
192
|
-
# @return [
|
|
191
|
+
# @return [Typhoeus::Response]
|
|
193
192
|
def multipart_complete(apikey, filename, filesize, mimetype, start_response, parts_and_etags, options, intelligent = false)
|
|
194
193
|
if !intelligent
|
|
195
194
|
data = {
|
|
@@ -220,8 +219,8 @@ module MultipartUploadUtils
|
|
|
220
219
|
end
|
|
221
220
|
data = data.merge!(options) if options
|
|
222
221
|
|
|
223
|
-
|
|
224
|
-
FilestackConfig::MULTIPART_COMPLETE_URL,
|
|
222
|
+
Typhoeus.post(
|
|
223
|
+
FilestackConfig::MULTIPART_COMPLETE_URL, body: data,
|
|
225
224
|
headers: FilestackConfig::HEADERS
|
|
226
225
|
)
|
|
227
226
|
end
|
|
@@ -235,7 +234,7 @@ module MultipartUploadUtils
|
|
|
235
234
|
# @param [Hash] options User-defined options for
|
|
236
235
|
# multipart uploads
|
|
237
236
|
#
|
|
238
|
-
# @return [
|
|
237
|
+
# @return [Typhoeus::Response]
|
|
239
238
|
def multipart_upload(apikey, filepath, security, options, timeout, intelligent: false)
|
|
240
239
|
filename, filesize, mimetype = get_file_info(filepath)
|
|
241
240
|
start_response = multipart_start(
|
|
@@ -267,7 +266,7 @@ module MultipartUploadUtils
|
|
|
267
266
|
response_complete = multipart_complete(
|
|
268
267
|
apikey, filename, filesize, mimetype,
|
|
269
268
|
start_response, nil, options, intelligent
|
|
270
|
-
)
|
|
269
|
+
)
|
|
271
270
|
end
|
|
272
271
|
}
|
|
273
272
|
rescue
|