files.com 1.0.35 → 1.0.36
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/_VERSION +1 -1
- data/files.com.gemspec +1 -1
- data/lib/files.com/api_client.rb +40 -15
- data/lib/files.com/models/file.rb +14 -10
- data/spec/models/file_spec.rb +31 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06f7e1e1686656a44e8ebc1e30684c7d1dcc9262cddfaf269cff3f7df8e8dc97
|
4
|
+
data.tar.gz: e37f73015d704139ee38a89223976b0846b9cebfbe10f270032d7a6829e6ca12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35d8d4efb868ec674125be3e092216c0bbae7daf5292fc97418ab36be472ca6570f1cdcd83b467ec345d980786feb7ac31836dcd7b71dcbc364a259b15bb8c7e
|
7
|
+
data.tar.gz: c1ec9327fbe25deb422da0f22662ef17bc3dcb8e4643f72f82fa7ff6ce1075677659b5c9b69721a1de8f425debd9406197ea2486ceeeb7dc9b0bfc7fc5bd62ef
|
data/_VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.36
|
data/files.com.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.description = "The Files.com Ruby client."
|
12
12
|
s.license = "MIT"
|
13
13
|
s.required_ruby_version = ">= 2.3"
|
14
|
-
s.add_dependency 'faraday', '>= 0.
|
14
|
+
s.add_dependency 'faraday', '>= 0.17.3'
|
15
15
|
s.add_dependency 'net-http-persistent'
|
16
16
|
s.add_dependency 'addressable', "~> 2.7.0"
|
17
17
|
|
data/lib/files.com/api_client.rb
CHANGED
@@ -14,29 +14,41 @@ module Files
|
|
14
14
|
Thread.current[:files_api_client] || default_client
|
15
15
|
end
|
16
16
|
|
17
|
+
# net_http_persistent does not support streaming downloads with faraday when directly downloading from S3
|
18
|
+
# falling back to net_http.
|
19
|
+
def self.download_client
|
20
|
+
Thread.current[:files_api_client_download_client] ||= ApiClient.new(download_conn)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.download_conn
|
24
|
+
Thread.current[:files_api_client_download_conn] ||= build_default_conn(force_net_http: true)
|
25
|
+
end
|
26
|
+
|
17
27
|
def self.default_client
|
18
28
|
Thread.current[:files_api_client_default_client] ||= ApiClient.new(default_conn)
|
19
29
|
end
|
20
30
|
|
21
31
|
def self.default_conn
|
22
|
-
Thread.current[:files_api_client_default_conn] ||=
|
23
|
-
|
24
|
-
builder.use Faraday::Request::Multipart
|
25
|
-
builder.use Faraday::Request::UrlEncoded
|
26
|
-
builder.use Faraday::Response::RaiseError
|
27
|
-
|
28
|
-
if Gem.win_platform? || RUBY_PLATFORM == "java"
|
29
|
-
builder.adapter :net_http
|
30
|
-
else
|
31
|
-
builder.adapter :net_http_persistent
|
32
|
-
end
|
33
|
-
end
|
32
|
+
Thread.current[:files_api_client_default_conn] ||= build_default_conn
|
33
|
+
end
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
def self.build_default_conn(force_net_http: false)
|
36
|
+
conn = Faraday.new do |builder|
|
37
|
+
builder.use Faraday::Request::Multipart
|
38
|
+
builder.use Faraday::Request::UrlEncoded
|
39
|
+
builder.use Faraday::Response::RaiseError
|
37
40
|
|
38
|
-
|
41
|
+
if Gem.win_platform? || RUBY_PLATFORM == "java" || force_net_http
|
42
|
+
builder.adapter :net_http
|
43
|
+
else
|
44
|
+
builder.adapter :net_http_persistent
|
45
|
+
end
|
39
46
|
end
|
47
|
+
|
48
|
+
conn.proxy = Files.proxy if Files.proxy
|
49
|
+
conn.ssl.verify = true
|
50
|
+
|
51
|
+
conn
|
40
52
|
end
|
41
53
|
|
42
54
|
def self.should_retry?(error, num_retries)
|
@@ -132,6 +144,19 @@ module Files
|
|
132
144
|
end
|
133
145
|
end
|
134
146
|
|
147
|
+
def stream_download(uri, io)
|
148
|
+
if conn.adapter == Faraday::Adapter::NetHttp
|
149
|
+
remote_request(:get, uri) do |req|
|
150
|
+
req.options.on_data = proc do |chunk, _overall_received_bytes|
|
151
|
+
io.write(chunk)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
else
|
155
|
+
response = remote_request(:get, download_uri_with_load)
|
156
|
+
io.write(response.body)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
135
160
|
def cursor
|
136
161
|
@last_response.http_headers["x-files-cursor"]
|
137
162
|
end
|
@@ -149,13 +149,15 @@ module Files
|
|
149
149
|
|
150
150
|
def self.upload_chunks(io, path, options, upload = nil, etags = [])
|
151
151
|
etags ||= []
|
152
|
+
bytes_written = 0
|
152
153
|
loop do
|
153
154
|
upload = FileAction.begin_upload(path, { ref: upload&.ref, part: (upload&.part_number || 0) + 1 }, options)
|
154
155
|
buf = io.read(upload.partsize) || ""
|
156
|
+
bytes_written += buf.length
|
155
157
|
method = upload.http_method.downcase.to_sym
|
156
158
|
response = client(options).remote_request(method, upload.upload_uri, { "Content-Length": buf.length.to_s }, buf)
|
157
159
|
etags << { etag: response.headers["ETag"], part: upload.part_number }
|
158
|
-
return upload, etags if io.eof?
|
160
|
+
return upload, etags, bytes_written if io.eof?
|
159
161
|
end
|
160
162
|
end
|
161
163
|
|
@@ -303,8 +305,7 @@ module Files
|
|
303
305
|
end
|
304
306
|
|
305
307
|
def download_content(io)
|
306
|
-
|
307
|
-
io.write(response.body)
|
308
|
+
Files::ApiClient::download_client.stream_download(download_uri_with_load, io)
|
308
309
|
end
|
309
310
|
|
310
311
|
def each(*args, &block)
|
@@ -363,8 +364,8 @@ module Files
|
|
363
364
|
if mode.include? "w"
|
364
365
|
@write_io.rewind if @write_io.is_a?(StringIO)
|
365
366
|
|
366
|
-
@bytes_written
|
367
|
-
@
|
367
|
+
@upload, @etags, bytes_written = File.upload_chunks(@write_io, path, options, @upload, @etags)
|
368
|
+
@bytes_written += bytes_written
|
368
369
|
elsif mode.include? "a"
|
369
370
|
raise NotImplementedError
|
370
371
|
end
|
@@ -388,11 +389,14 @@ module Files
|
|
388
389
|
|
389
390
|
def read_io
|
390
391
|
@read_io ||= begin
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
392
|
+
r, w = IO.pipe
|
393
|
+
Thread.new do
|
394
|
+
download_content(w)
|
395
|
+
ensure
|
396
|
+
w.close
|
397
|
+
end
|
398
|
+
r
|
399
|
+
end
|
396
400
|
end
|
397
401
|
|
398
402
|
def internal_encoding(*_args)
|
data/spec/models/file_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "spec_helper"
|
2
|
+
require "tempfile"
|
2
3
|
|
3
4
|
RSpec.describe Files::File, :with_test_folder do
|
4
5
|
describe "#read" do
|
@@ -14,6 +15,20 @@ RSpec.describe Files::File, :with_test_folder do
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
18
|
+
describe "#read_io" do
|
19
|
+
before do
|
20
|
+
Files::File.open(test_folder.join("read.txt").to_s, 'w', options) do |f|
|
21
|
+
f.write("contents")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns an IO Object" do
|
25
|
+
file = Files::File.find(test_folder.join("read.txt").to_s, {}, options)
|
26
|
+
expect(file.read_io.class).to eq(IO)
|
27
|
+
expect(file.read_io.read).to eq("contents")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
17
32
|
describe "#write" do
|
18
33
|
it "can take string" do
|
19
34
|
Files::File.open(test_folder.join("write-as-string.txt").to_s, 'w', options) do |f|
|
@@ -32,5 +47,21 @@ RSpec.describe Files::File, :with_test_folder do
|
|
32
47
|
file = Files::File.find(test_folder.join("write-as-io.txt").to_s, {}, options)
|
33
48
|
expect(file.read).to eq("I am a string via IO")
|
34
49
|
end
|
50
|
+
|
51
|
+
it "can take an IO without #size" do
|
52
|
+
temp_file = Tempfile.new("testing_io.txt")
|
53
|
+
|
54
|
+
temp_file.write("I am a string via IO")
|
55
|
+
temp_file.rewind
|
56
|
+
fd = IO.sysopen(temp_file.path)
|
57
|
+
io = IO.new(fd)
|
58
|
+
|
59
|
+
file = Files::File.open(test_folder.join("write-as-io.txt").to_s, 'w', options) do |f|
|
60
|
+
f.write(io)
|
61
|
+
end
|
62
|
+
|
63
|
+
expect(file.read).to eq("I am a string via IO")
|
64
|
+
temp_file.close
|
65
|
+
end
|
35
66
|
end
|
36
67
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: files.com
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.36
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- files.com
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.17.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.17.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: net-http-persistent
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|