uploadcare-ruby 2.1.2 → 3.1.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/.github/workflows/gem-push.yml +20 -0
- data/.github/workflows/ruby.yml +52 -0
- data/.gitignore +13 -6
- data/.rspec +2 -0
- data/.rubocop.yml +33 -0
- data/.yardopts +4 -0
- data/CHANGELOG.md +29 -47
- data/DEVELOPMENT.md +18 -0
- data/Gemfile +2 -0
- data/LICENSE +1 -1
- data/README.md +433 -527
- data/Rakefile +5 -5
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/uploadcare/api/api.rb +25 -0
- data/lib/uploadcare/client/conversion/base_conversion_client.rb +59 -0
- data/lib/uploadcare/client/conversion/document_conversion_client.rb +41 -0
- data/lib/uploadcare/client/conversion/video_conversion_client.rb +46 -0
- data/lib/uploadcare/client/file_client.rb +44 -0
- data/lib/uploadcare/client/file_list_client.rb +46 -0
- data/lib/uploadcare/client/group_client.rb +45 -0
- data/lib/uploadcare/client/multipart_upload/chunks_client.rb +57 -0
- data/lib/uploadcare/client/multipart_upload_client.rb +64 -0
- data/lib/uploadcare/client/project_client.rb +18 -0
- data/lib/uploadcare/client/rest_client.rb +74 -0
- data/lib/uploadcare/client/rest_group_client.rb +23 -0
- data/lib/uploadcare/client/upload_client.rb +43 -0
- data/lib/uploadcare/client/uploader_client.rb +101 -0
- data/lib/uploadcare/client/webhook_client.rb +47 -0
- data/lib/uploadcare/concern/error_handler.rb +54 -0
- data/lib/uploadcare/concern/throttle_handler.rb +25 -0
- data/lib/uploadcare/concern/upload_error_handler.rb +32 -0
- data/lib/uploadcare/entity/conversion/base_converter.rb +36 -0
- data/lib/uploadcare/entity/conversion/document_converter.rb +15 -0
- data/lib/uploadcare/entity/conversion/video_converter.rb +15 -0
- data/lib/uploadcare/entity/decorator/paginator.rb +79 -0
- data/lib/uploadcare/entity/entity.rb +18 -0
- data/lib/uploadcare/entity/file.rb +106 -0
- data/lib/uploadcare/entity/file_list.rb +31 -0
- data/lib/uploadcare/entity/group.rb +40 -0
- data/lib/uploadcare/entity/group_list.rb +24 -0
- data/lib/uploadcare/entity/project.rb +13 -0
- data/lib/uploadcare/entity/uploader.rb +81 -0
- data/lib/uploadcare/entity/webhook.rb +14 -0
- data/lib/uploadcare/exception/conversion_error.rb +8 -0
- data/lib/uploadcare/exception/request_error.rb +9 -0
- data/lib/uploadcare/exception/throttle_error.rb +16 -0
- data/lib/uploadcare/param/authentication_header.rb +25 -0
- data/lib/uploadcare/param/conversion/document/processing_job_url_builder.rb +39 -0
- data/lib/uploadcare/param/conversion/video/processing_job_url_builder.rb +64 -0
- data/lib/uploadcare/param/param.rb +10 -0
- data/lib/uploadcare/param/secure_auth_header.rb +37 -0
- data/lib/uploadcare/param/simple_auth_header.rb +14 -0
- data/lib/uploadcare/param/upload/signature_generator.rb +24 -0
- data/lib/uploadcare/param/upload/upload_params_generator.rb +23 -0
- data/lib/uploadcare/param/user_agent.rb +21 -0
- data/lib/uploadcare/ruby/version.rb +5 -0
- data/lib/uploadcare.rb +36 -32
- data/uploadcare-ruby.gemspec +50 -37
- metadata +107 -113
- data/.travis.yml +0 -26
- data/UPGRADE_NOTES.md +0 -36
- data/lib/uploadcare/api/file_api.rb +0 -7
- data/lib/uploadcare/api/file_list_api.rb +0 -19
- data/lib/uploadcare/api/file_storage_api.rb +0 -34
- data/lib/uploadcare/api/group_api.rb +0 -38
- data/lib/uploadcare/api/group_list_api.rb +0 -17
- data/lib/uploadcare/api/project_api.rb +0 -9
- data/lib/uploadcare/api/raw_api.rb +0 -38
- data/lib/uploadcare/api/uploading_api/upload_params.rb +0 -72
- data/lib/uploadcare/api/uploading_api.rb +0 -71
- data/lib/uploadcare/api/validators/file_list_options_validator.rb +0 -73
- data/lib/uploadcare/api/validators/group_list_options_validator.rb +0 -49
- data/lib/uploadcare/api.rb +0 -26
- data/lib/uploadcare/errors/errors.rb +0 -64
- data/lib/uploadcare/resources/file.rb +0 -164
- data/lib/uploadcare/resources/file_list.rb +0 -14
- data/lib/uploadcare/resources/group.rb +0 -115
- data/lib/uploadcare/resources/group_list.rb +0 -14
- data/lib/uploadcare/resources/project.rb +0 -13
- data/lib/uploadcare/resources/resource_list.rb +0 -83
- data/lib/uploadcare/rest/auth/auth.rb +0 -31
- data/lib/uploadcare/rest/auth/secure.rb +0 -43
- data/lib/uploadcare/rest/auth/simple.rb +0 -16
- data/lib/uploadcare/rest/connections/api_connection.rb +0 -53
- data/lib/uploadcare/rest/connections/upload_connection.rb +0 -22
- data/lib/uploadcare/rest/middlewares/auth_middleware.rb +0 -24
- data/lib/uploadcare/rest/middlewares/parse_json_middleware.rb +0 -33
- data/lib/uploadcare/rest/middlewares/raise_error_middleware.rb +0 -21
- data/lib/uploadcare/utils/parser.rb +0 -71
- data/lib/uploadcare/utils/user_agent.rb +0 -44
- data/lib/uploadcare/version.rb +0 -3
- data/spec/api/file_list_api_spec.rb +0 -95
- data/spec/api/file_storage_api_spec.rb +0 -88
- data/spec/api/group_list_api_spec.rb +0 -59
- data/spec/api/raw_api_spec.rb +0 -25
- data/spec/api/uploading_api/upload_params_spec.rb +0 -99
- data/spec/api/uploading_api_spec.rb +0 -59
- data/spec/resources/file_list_spec.rb +0 -25
- data/spec/resources/file_spec.rb +0 -223
- data/spec/resources/group_list_spec.rb +0 -25
- data/spec/resources/group_spec.rb +0 -101
- data/spec/resources/operations_spec.rb +0 -59
- data/spec/resources/project_spec.rb +0 -21
- data/spec/rest/api_connection_spec.rb +0 -68
- data/spec/rest/auth/secure_spec.rb +0 -66
- data/spec/rest/auth/simple_spec.rb +0 -31
- data/spec/rest/errors_spec.rb +0 -75
- data/spec/rest/upload_connection_spec.rb +0 -19
- data/spec/shared/resource_list.rb +0 -188
- data/spec/spec_helper.rb +0 -54
- data/spec/uploadcare_spec.rb +0 -43
- data/spec/utils/parser_spec.rb +0 -85
- data/spec/utils/user_agent_spec.rb +0 -46
- data/spec/view.png +0 -0
- data/spec/view2.jpg +0 -0
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Uploadcare::Connections::Auth::Secure do
|
|
4
|
-
describe '#apply' do
|
|
5
|
-
let(:env){ Faraday::Env.new(:get, nil, URI::HTTP.build(host: 'example.com'), nil, {}) }
|
|
6
|
-
subject{ env.request_headers }
|
|
7
|
-
|
|
8
|
-
before(:each) do
|
|
9
|
-
described_class.new(public_key: 'pub', private_key: 'priv').apply(env)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "adds Authorization header to env's request_headers" do
|
|
13
|
-
expect(subject).to include('Authorization')
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "adds Date header to env's request_headers" do
|
|
17
|
-
expect(subject).to include('Date')
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "uses secure authorization" do
|
|
21
|
-
expect(subject['Authorization']).to match /Uploadcare pub:.+/
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe 'signature' do
|
|
26
|
-
let(:uri){ URI::HTTP.build(host: 'example.com', path: '/path', query: 'test=1') }
|
|
27
|
-
let(:headers){ {'Content-Type' => 'application/x-www-form-urlencoded'} }
|
|
28
|
-
let(:env){ Faraday::Env.new(:post, 'url=encoded&test=body', uri, nil, headers) }
|
|
29
|
-
|
|
30
|
-
subject{ env.request_headers }
|
|
31
|
-
|
|
32
|
-
before(:each) do
|
|
33
|
-
allow(Time).to receive(:now).and_return(Time.parse('2017.02.02 12:58:50 +0000'))
|
|
34
|
-
described_class.new(public_key: 'pub', private_key: 'priv').apply(env)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "counts signature correctly" do
|
|
38
|
-
expected = '71b61ed67d16f48d2e46a4ee72ca12025aeb8d1f'
|
|
39
|
-
expect(subject['Authorization']).to eq "Uploadcare pub:#{expected}"
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
describe 'integration' do
|
|
45
|
-
let(:api){ Uploadcare::Api.new(auth_scheme: :secure) }
|
|
46
|
-
let(:file){ api.upload IMAGE_URL }
|
|
47
|
-
|
|
48
|
-
before(:each) do
|
|
49
|
-
# ensure that secure auth is being used
|
|
50
|
-
expect_any_instance_of(described_class).to receive(:apply).at_least(4).times.and_call_original
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it 'auth works with real requests' do
|
|
54
|
-
# request with url params
|
|
55
|
-
expect{ api.get('/files/', limit: 1) }.not_to raise_error
|
|
56
|
-
# request with an url-encoded body
|
|
57
|
-
expect{
|
|
58
|
-
retry_if(Uploadcare::Error::RequestError::BadRequest) do
|
|
59
|
-
api.post('/files/', source: file.uuid)
|
|
60
|
-
end
|
|
61
|
-
}.not_to raise_error
|
|
62
|
-
# request with an empty body and a redirect
|
|
63
|
-
expect{ api.delete("/files/#{file.uuid}/storage/") }.not_to raise_error
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Uploadcare::Connections::Auth::Simple do
|
|
4
|
-
let(:env){ Faraday::Env.new(nil, nil, nil, nil, {}) }
|
|
5
|
-
subject{ described_class.new(public_key: 'pub', private_key: 'priv') }
|
|
6
|
-
|
|
7
|
-
describe 'apply' do
|
|
8
|
-
it "adds Authorization header to env's request_headers" do
|
|
9
|
-
subject.apply(env)
|
|
10
|
-
expect(env.request_headers).to include('Authorization')
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "sets Authorization header's value correctly" do
|
|
14
|
-
subject.apply(env)
|
|
15
|
-
expect(env.request_headers['Authorization']).to eq "Uploadcare.Simple pub:priv"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
describe 'integration' do
|
|
20
|
-
let(:api){ Uploadcare::Api.new(auth_scheme: :simple) }
|
|
21
|
-
|
|
22
|
-
before(:each) do
|
|
23
|
-
# ensure that simple auth is being used
|
|
24
|
-
expect_any_instance_of(described_class).to receive(:apply).and_call_original
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it 'auth works with real requests' do
|
|
28
|
-
expect{ api.get('/files/') }.not_to raise_error
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
data/spec/rest/errors_spec.rb
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'uri'
|
|
3
|
-
require 'socket'
|
|
4
|
-
|
|
5
|
-
describe Uploadcare::Error do
|
|
6
|
-
before(:all) do
|
|
7
|
-
@settings = Uploadcare.default_settings
|
|
8
|
-
@codes = [400,401,403,404,406,408,422,429,500,502,503,504]
|
|
9
|
-
@connection = Uploadcare::Connections::ApiConnection.new(@settings)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it 'Error codes should be accesbile' do
|
|
13
|
-
Uploadcare::Error.errors.keys.should == @codes
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it 'Errors should be kind of requested codes' do
|
|
17
|
-
not_found = Uploadcare::Error.errors[404]
|
|
18
|
-
not_found.new('File not found').should be_kind_of(Uploadcare::Error::RequestError::NotFound)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it 'errors should have meaningfull messages' do
|
|
22
|
-
not_found = Uploadcare::Error.errors[404]
|
|
23
|
-
error = not_found.new
|
|
24
|
-
error.message.should == "HTTP 404 - the requested resource could not be found."
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it 'Should raise an error' do
|
|
28
|
-
error = Uploadcare::Error::RequestError::NotFound
|
|
29
|
-
expect{ @connection.send :get, '/random_url/', {} }.to raise_error(error)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "should escape particular error" do
|
|
33
|
-
error = Uploadcare::Error::RequestError::NotFound
|
|
34
|
-
expect do
|
|
35
|
-
begin
|
|
36
|
-
@connection.send :get, '/random_url/', {}
|
|
37
|
-
rescue error => e
|
|
38
|
-
nil
|
|
39
|
-
end
|
|
40
|
-
end.to_not raise_error
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it 'should escape common request error' do
|
|
44
|
-
error = Uploadcare::Error::RequestError
|
|
45
|
-
expect do
|
|
46
|
-
begin
|
|
47
|
-
@connection.send :get, '/random_url/', {}
|
|
48
|
-
rescue error => e
|
|
49
|
-
nil
|
|
50
|
-
end
|
|
51
|
-
end.to_not raise_error
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it 'should escape generic uploadcare service error' do
|
|
55
|
-
error = Uploadcare::Error
|
|
56
|
-
expect do
|
|
57
|
-
begin
|
|
58
|
-
@connection.send :get, '/random_url/', {}
|
|
59
|
-
rescue error => e
|
|
60
|
-
nil
|
|
61
|
-
end
|
|
62
|
-
end.to_not raise_error
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it 'should escape generic uploadcare service error' do
|
|
66
|
-
error = StandardError
|
|
67
|
-
expect do
|
|
68
|
-
begin
|
|
69
|
-
@connection.send :get, '/random_url/', {}
|
|
70
|
-
rescue error => e
|
|
71
|
-
nil
|
|
72
|
-
end
|
|
73
|
-
end.to_not raise_error
|
|
74
|
-
end
|
|
75
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'uri'
|
|
3
|
-
require 'socket'
|
|
4
|
-
|
|
5
|
-
describe Uploadcare::Connections::UploadConnection do
|
|
6
|
-
before(:all) do
|
|
7
|
-
@settings = Uploadcare.default_settings
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it 'should initialize upload connection' do
|
|
11
|
-
expect {Uploadcare::Connections::UploadConnection.new(@settings)}.to_not raise_error
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it 'should use ParseJson and RaiseError middleware' do
|
|
15
|
-
connection = Uploadcare::Connections::UploadConnection.new(@settings)
|
|
16
|
-
connection.builder.handlers.include?(Uploadcare::Connections::Response::ParseJson).should == true
|
|
17
|
-
connection.builder.handlers.include?(Uploadcare::Connections::Response::RaiseError).should == true
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
shared_examples 'resource list' do
|
|
4
|
-
describe '#options' do
|
|
5
|
-
subject{ @list.options }
|
|
6
|
-
|
|
7
|
-
it{ is_expected.to be_a(Hash) }
|
|
8
|
-
it{ is_expected.to be_frozen }
|
|
9
|
-
|
|
10
|
-
it 'stores options' do
|
|
11
|
-
expect( subject ).to eq(limit: 1)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
describe '#meta' do
|
|
16
|
-
subject{ @list.meta }
|
|
17
|
-
|
|
18
|
-
it{ is_expected.to be_a(Hash) }
|
|
19
|
-
it{ is_expected.to be_frozen }
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
describe '#total' do
|
|
23
|
-
subject{ @list.total }
|
|
24
|
-
|
|
25
|
-
it{ is_expected.to be_an(Integer) }
|
|
26
|
-
|
|
27
|
-
it 'returns a "total" value from metadata' do
|
|
28
|
-
expect( subject ).to eq @list.meta["total"]
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe '#loaded' do
|
|
33
|
-
subject{ @list.loaded }
|
|
34
|
-
|
|
35
|
-
it{ is_expected.to be_an(Integer) }
|
|
36
|
-
|
|
37
|
-
it 'contains currently loaded objects count' do
|
|
38
|
-
size = rand(2..10)
|
|
39
|
-
allow(@list).to receive(:objects){ Array.new(size) }
|
|
40
|
-
|
|
41
|
-
expect( subject ).to eq(size)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
describe '#fully_loaded?' do
|
|
46
|
-
subject{ @list.fully_loaded? }
|
|
47
|
-
|
|
48
|
-
context 'if there is no more next pages left' do
|
|
49
|
-
before { allow(@list).to receive(:meta){ {"next" => nil} } }
|
|
50
|
-
it { is_expected.to be_truthy }
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
context 'if there is a next page' do
|
|
54
|
-
before { allow(@list).to receive(:meta){ {"next" => 'example.com'} } }
|
|
55
|
-
it { is_expected.to be_falsey }
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
describe '#each' do
|
|
60
|
-
it 'when called without a block, returns an Enumerator' do
|
|
61
|
-
expect( subject.each ).to be_an(Enumerator)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it 'when called with a block, returns self' do
|
|
65
|
-
allow(subject).to receive(:meta){ {"next" => nil} }
|
|
66
|
-
expect( subject.each{|o| nil } ).to eq(subject)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it 'when called with a break inside a block, returns nil' do
|
|
70
|
-
expect( subject.each{|o| break } ).to be_nil
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
describe '#[]' do
|
|
75
|
-
subject{ @list.dup }
|
|
76
|
-
|
|
77
|
-
it "returns instances of a resource class" do
|
|
78
|
-
expect( subject[0] ).to be_a(resource_class)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it 'loads additional objects when needed' do
|
|
82
|
-
expect(@api).to receive(:get)
|
|
83
|
-
.with(subject.meta["next"]).and_call_original
|
|
84
|
-
|
|
85
|
-
expect { subject[1] }.to change { subject.objects.size }.by(1)
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
describe 'enumerable interface' do
|
|
90
|
-
subject{ @list.dup }
|
|
91
|
-
|
|
92
|
-
it 'is an Enumerable' do
|
|
93
|
-
expect( subject ).to be_an(Enumerable)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
it 'iterates through objects' do
|
|
97
|
-
i, uuids = 0, []
|
|
98
|
-
subject.each{|object| uuids << object.uuid; i+=1; break if i >= 2 }
|
|
99
|
-
|
|
100
|
-
expect(uuids).to eq([subject[0].uuid, subject[1].uuid])
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it 'loads additional objects when needed' do
|
|
104
|
-
expect(@api).to receive(:get)
|
|
105
|
-
.with(subject.meta["next"]).and_call_original
|
|
106
|
-
|
|
107
|
-
objects = subject.first(2)
|
|
108
|
-
|
|
109
|
-
expect(objects.size).to eq(2)
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
it 'doesn\'t load more objects than needed' do
|
|
113
|
-
expect(@api).to receive(:get).once.and_call_original
|
|
114
|
-
|
|
115
|
-
objects = subject.first(2)
|
|
116
|
-
|
|
117
|
-
expect(objects.size).to eq(2)
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
it "loads different objects" do
|
|
121
|
-
expect(@api).to receive(:get)
|
|
122
|
-
.with(subject.meta["next"]).and_call_original
|
|
123
|
-
|
|
124
|
-
objects = subject.first(2)
|
|
125
|
-
|
|
126
|
-
expect(objects[0].uuid).not_to eq(objects[1].uuid)
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
it 'stops loading objects when no objects left' do
|
|
130
|
-
allow(@api).to receive(:get).and_wrap_original do |m, *args|
|
|
131
|
-
m.call(*args).tap{|data| data["next"] = nil}
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
uuids = subject.map{|object| object.uuid}
|
|
135
|
-
|
|
136
|
-
expect( uuids.size ).to eq(2)
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
it 'preserves loaded objects' do
|
|
140
|
-
expect( subject.loaded ).to eq(1)
|
|
141
|
-
|
|
142
|
-
subject.first(2)
|
|
143
|
-
|
|
144
|
-
expect( subject.loaded ).to eq(2)
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
it 'updates #meta with data from last api response' do
|
|
148
|
-
new_meta = {}
|
|
149
|
-
allow(@api).to receive(:get).and_wrap_original do |m, *args|
|
|
150
|
-
m.call(*args).tap{|data| new_meta = data.reject{|k,_| k == "results"}}
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
subject.first(2)
|
|
154
|
-
|
|
155
|
-
expect( subject.meta ).to eq(new_meta)
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
if Gem.ruby_version >= Gem::Version.new('2.0.0')
|
|
159
|
-
context 'when lazy enumerator is used' do
|
|
160
|
-
it 'preserves loaded objects' do
|
|
161
|
-
expect(subject.loaded).to eq 1
|
|
162
|
-
|
|
163
|
-
subject.lazy.first(2)
|
|
164
|
-
|
|
165
|
-
expect(subject.loaded).to eq 2
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
context 'when a block passed to an enumerator method contains a break' do
|
|
171
|
-
it 'preserves loaded objects' do
|
|
172
|
-
i = 0
|
|
173
|
-
subject.each{|o| i+= 1; break if i >= 2}
|
|
174
|
-
|
|
175
|
-
expect( subject.loaded ).to eq(2)
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
context 'when a block passed to an enumerator method raises an exception' do
|
|
180
|
-
it 'preserves loaded objects' do
|
|
181
|
-
i = 0
|
|
182
|
-
subject.each{|o| i += 1; raise if i>= 2} rescue nil
|
|
183
|
-
|
|
184
|
-
expect( subject.loaded ).to eq(2)
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
end
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
|
2
|
-
$LOAD_PATH << File.join(File.dirname(__FILE__))
|
|
3
|
-
|
|
4
|
-
require 'rubygems'
|
|
5
|
-
require 'pry'
|
|
6
|
-
require 'rspec'
|
|
7
|
-
require 'uploadcare'
|
|
8
|
-
require 'yaml'
|
|
9
|
-
|
|
10
|
-
require 'coveralls'
|
|
11
|
-
Coveralls.wear!
|
|
12
|
-
|
|
13
|
-
CONFIG = Uploadcare.default_settings.merge!(
|
|
14
|
-
public_key: ENV['UPLOADCARE_PUBLIC_KEY'] || 'demopublickey',
|
|
15
|
-
private_key: ENV['UPLOADCARE_SECRET_KEY'] || 'demoprivatekey',
|
|
16
|
-
)
|
|
17
|
-
UUID_REGEX = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
|
|
18
|
-
|
|
19
|
-
API = Uploadcare::Api.new(CONFIG)
|
|
20
|
-
IMAGE_URL = "http://macaw.co/images/macaw-logo.png"
|
|
21
|
-
|
|
22
|
-
FILE1 = File.open(File.join(File.dirname(__FILE__), 'view.png'))
|
|
23
|
-
FILE2 = File.open(File.join(File.dirname(__FILE__), 'view2.jpg'))
|
|
24
|
-
FILES_ARY = [FILE1, FILE2]
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
config_file = File.join(File.dirname(__FILE__), 'config.yml')
|
|
28
|
-
if File.exists?(config_file)
|
|
29
|
-
CONFIG.update Hash[YAML.parse_file(config_file).to_ruby.map{|a, b| [a.to_sym, b]}]
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
if CONFIG[:public_key] == 'demopublickey'
|
|
33
|
-
RSpec.configure do |c|
|
|
34
|
-
c.before(:example, :payed_feature){ skip "Unavailable for demo account" }
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
Dir[File.join(File.dirname(__FILE__), 'shared/*.rb')].each{|path| require path}
|
|
39
|
-
|
|
40
|
-
def retry_if(error, retries=10, &block)
|
|
41
|
-
block.call
|
|
42
|
-
rescue error
|
|
43
|
-
raise if retries <= 0
|
|
44
|
-
sleep 0.2
|
|
45
|
-
retry_if(error, retries-1, &block)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def wait_until_ready(file)
|
|
49
|
-
unless file.is_ready
|
|
50
|
-
sleep 0.2
|
|
51
|
-
file.load_data!
|
|
52
|
-
wait_until_ready(file)
|
|
53
|
-
end
|
|
54
|
-
end
|
data/spec/uploadcare_spec.rb
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Uploadcare do
|
|
4
|
-
around do |example|
|
|
5
|
-
orig_stderr = $stderr
|
|
6
|
-
$stderr = StringIO.new
|
|
7
|
-
|
|
8
|
-
example.call
|
|
9
|
-
|
|
10
|
-
$stderr = orig_stderr
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
describe '::user_agent' do
|
|
14
|
-
subject(:user_agent) { described_class.user_agent(options) }
|
|
15
|
-
let(:options) { {user_agent: 'user/agent'} }
|
|
16
|
-
let(:user_agent_builder) { instance_double('Uploadcare::UserAgent') }
|
|
17
|
-
|
|
18
|
-
it 'returns user agent string' do
|
|
19
|
-
allow(Uploadcare::UserAgent).to receive(:new) { user_agent_builder }
|
|
20
|
-
expect(user_agent_builder).to receive(:call).with(options) { 'user/agent' }
|
|
21
|
-
|
|
22
|
-
expect(user_agent).to eq('user/agent')
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it 'is deprecated' do
|
|
26
|
-
user_agent
|
|
27
|
-
|
|
28
|
-
$stderr.rewind
|
|
29
|
-
expect($stderr.string).to start_with('[DEPRECATION] `Uploadcare::user_agent`')
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
describe '::USER_AGENT' do
|
|
34
|
-
it { expect(described_class::USER_AGENT).not_to be_nil }
|
|
35
|
-
|
|
36
|
-
it 'is deprecated' do
|
|
37
|
-
described_class::USER_AGENT
|
|
38
|
-
|
|
39
|
-
$stderr.rewind
|
|
40
|
-
expect($stderr.string).to start_with('[DEPRECATION] `Uploadcare::USER_AGENT`')
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
data/spec/utils/parser_spec.rb
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Uploadcare::Parser do
|
|
4
|
-
before :all do
|
|
5
|
-
# https://ucarecdn.com/be4e24fb-2cad-476f-9417-ba95e3fefbf2~3/-/crop/123/-/fromat/png/
|
|
6
|
-
@uuid = "be4e24fb-2cad-476f-9417-ba95e3fefbf2"
|
|
7
|
-
@count = "12"
|
|
8
|
-
@operations = "-/crop/123/-/fromat/png/"
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "should parse file uuid string" do
|
|
12
|
-
string = "#{@uuid}"
|
|
13
|
-
|
|
14
|
-
parsed = Uploadcare::Parser.parse(string)
|
|
15
|
-
|
|
16
|
-
expect(parsed).to be_kind_of(Uploadcare::Parser::File)
|
|
17
|
-
expect(parsed.uuid).to eq @uuid
|
|
18
|
-
expect(parsed.count).to be_nil
|
|
19
|
-
expect(parsed.operations).to be_kind_of(Array)
|
|
20
|
-
expect(parsed.operations).to be_empty
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "should parse file cdn string without operations string" do
|
|
24
|
-
string = "https://ucarecdn.com/#{@uuid}/"
|
|
25
|
-
|
|
26
|
-
parsed = Uploadcare::Parser.parse(string)
|
|
27
|
-
|
|
28
|
-
expect(parsed).to be_kind_of(Uploadcare::Parser::File)
|
|
29
|
-
expect(parsed.uuid).to eq @uuid
|
|
30
|
-
expect(parsed.count).to be_nil
|
|
31
|
-
expect(parsed.operations).to be_kind_of(Array)
|
|
32
|
-
expect(parsed.operations).to be_empty
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "should parse file cdn string with operations string" do
|
|
36
|
-
string = "https://ucarecdn.com/#{@uuid}/#{@operations}"
|
|
37
|
-
|
|
38
|
-
parsed = Uploadcare::Parser.parse(string)
|
|
39
|
-
|
|
40
|
-
expect(parsed).to be_kind_of(Uploadcare::Parser::File)
|
|
41
|
-
expect(parsed.uuid).to eq @uuid
|
|
42
|
-
expect(parsed.count).to be_nil
|
|
43
|
-
expect(parsed.operations).to be_kind_of(Array)
|
|
44
|
-
expect(parsed.operations).not_to be_empty
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "should parse group uuid string" do
|
|
48
|
-
string = "#{@uuid}~#{@count}"
|
|
49
|
-
|
|
50
|
-
parsed = Uploadcare::Parser.parse(string)
|
|
51
|
-
|
|
52
|
-
expect(parsed).to be_kind_of(Uploadcare::Parser::Group)
|
|
53
|
-
expect(parsed.uuid).to eq "#{@uuid}~#{@count}"
|
|
54
|
-
expect(parsed.count).not_to be_nil
|
|
55
|
-
expect(parsed.count).to eq @count
|
|
56
|
-
expect(parsed.operations).to be_kind_of(Array)
|
|
57
|
-
expect(parsed.operations).to be_empty
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "should parse file cdn string without operations string" do
|
|
61
|
-
string = "https://ucarecdn.com/#{@uuid}~#{@count}/"
|
|
62
|
-
|
|
63
|
-
parsed = Uploadcare::Parser.parse(string)
|
|
64
|
-
|
|
65
|
-
expect(parsed).to be_kind_of(Uploadcare::Parser::Group)
|
|
66
|
-
expect(parsed.uuid).to eq "#{@uuid}~#{@count}"
|
|
67
|
-
expect(parsed.count).not_to be_nil
|
|
68
|
-
expect(parsed.count).to eq @count
|
|
69
|
-
expect(parsed.operations).to be_kind_of(Array)
|
|
70
|
-
expect(parsed.operations).to be_empty
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it "should parse file cdn string with operations string" do
|
|
74
|
-
string = "https://ucarecdn.com/#{@uuid}~#{@count}/#{@operations}"
|
|
75
|
-
|
|
76
|
-
parsed = Uploadcare::Parser.parse(string)
|
|
77
|
-
|
|
78
|
-
expect(parsed).to be_kind_of(Uploadcare::Parser::Group)
|
|
79
|
-
expect(parsed.uuid).to eq "#{@uuid}~#{@count}"
|
|
80
|
-
expect(parsed.count).not_to be_nil
|
|
81
|
-
expect(parsed.count).to eq @count
|
|
82
|
-
expect(parsed.operations).to be_kind_of(Array)
|
|
83
|
-
expect(parsed.operations).not_to be_empty
|
|
84
|
-
end
|
|
85
|
-
end
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Uploadcare::UserAgent do
|
|
4
|
-
subject(:user_agent) { described_class.new.call(options) }
|
|
5
|
-
|
|
6
|
-
before do
|
|
7
|
-
stub_const('Uploadcare::VERSION', '123')
|
|
8
|
-
allow(Gem).to receive(:ruby_version) { '456' }
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
context 'when user_agent option is set' do
|
|
12
|
-
let(:options) do
|
|
13
|
-
{ user_agent: 'predefined user agent' }
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it { is_expected.to eq('predefined user agent') }
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
context 'when user_agent_environment option is set' do
|
|
20
|
-
let(:options) do
|
|
21
|
-
{
|
|
22
|
-
public_key: 'pubkey',
|
|
23
|
-
user_agent_environment: {
|
|
24
|
-
framework_name: 'rails',
|
|
25
|
-
framework_version: '5.1.0',
|
|
26
|
-
extension_name: 'UploadcareRails',
|
|
27
|
-
extension_version: '1.1.0'
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it do
|
|
33
|
-
is_expected.to eq(
|
|
34
|
-
'UploadcareRuby/123/pubkey (Ruby/456; rails/5.1.0; UploadcareRails/1.1.0)'
|
|
35
|
-
)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
context 'when user_agent_environment option is not set' do
|
|
40
|
-
let(:options) do
|
|
41
|
-
{ public_key: 'pubkey' }
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it { is_expected.to eq('UploadcareRuby/123/pubkey (Ruby/456)') }
|
|
45
|
-
end
|
|
46
|
-
end
|
data/spec/view.png
DELETED
|
Binary file
|
data/spec/view2.jpg
DELETED
|
Binary file
|