uploadcare-ruby 2.1.1 → 3.1.0.pre.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- 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 +32 -0
- data/.yardopts +4 -0
- data/CHANGELOG.md +33 -34
- data/DEVELOPMENT.md +18 -0
- data/Gemfile +2 -0
- data/LICENSE +1 -1
- data/README.md +369 -546
- data/Rakefile +5 -5
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/uploadcare.rb +36 -26
- data/lib/uploadcare/api/api.rb +25 -0
- data/lib/uploadcare/client/conversion/base_conversion_client.rb +54 -0
- data/lib/uploadcare/client/conversion/document_conversion_client.rb +38 -0
- data/lib/uploadcare/client/conversion/video_conversion_client.rb +42 -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 +48 -0
- data/lib/uploadcare/client/multipart_upload_client.rb +67 -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 +36 -0
- data/lib/uploadcare/client/uploader_client.rb +109 -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/decorator/paginator.rb +79 -0
- data/lib/uploadcare/entity/document_converter.rb +26 -0
- data/lib/uploadcare/entity/entity.rb +18 -0
- data/lib/uploadcare/entity/file.rb +81 -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 +75 -0
- data/lib/uploadcare/entity/video_converter.rb +26 -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/uploadcare-ruby.gemspec +50 -37
- metadata +109 -115
- data/.travis.yml +0 -26
- data/UPGRADE_NOTES.md +0 -36
- data/lib/uploadcare/api.rb +0 -26
- 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.rb +0 -71
- data/lib/uploadcare/api/uploading_api/upload_params.rb +0 -72
- 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/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 -16
- 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,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Uploadcare::Api::GroupList do
|
4
|
-
before :all do
|
5
|
-
@api = API
|
6
|
-
|
7
|
-
# ensure that current project has at least three groups
|
8
|
-
count = @api.get('/groups/', limit: 3)['results'].size
|
9
|
-
(3 - count).times{ @api.create_group([@api.upload(IMAGE_URL)]) } if count < 3
|
10
|
-
|
11
|
-
@list = @api.group_list(limit: 1)
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:resource_class){ Uploadcare::Api::Group }
|
15
|
-
subject{ @list }
|
16
|
-
|
17
|
-
it_behaves_like 'resource list'
|
18
|
-
|
19
|
-
describe '#objects' do
|
20
|
-
subject{ @list.objects }
|
21
|
-
|
22
|
-
it{ is_expected.to all(be_a(resource_class)) }
|
23
|
-
it{ is_expected.not_to include(be_loaded) }
|
24
|
-
end
|
25
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'uri'
|
3
|
-
require 'socket'
|
4
|
-
|
5
|
-
describe Uploadcare::Api::Group do
|
6
|
-
before :all do
|
7
|
-
@api = API
|
8
|
-
@files = @api.upload FILES_ARY
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should return group object" do
|
12
|
-
group = @api.create_group @files
|
13
|
-
group.should be_kind_of(Uploadcare::Api::Group)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should have valid UUID and count of files" do
|
17
|
-
group = @api.create_group @files
|
18
|
-
group.should respond_to(:uuid)
|
19
|
-
group.should respond_to(:files_count)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should may have files" do
|
23
|
-
group = @api.create_group @files
|
24
|
-
group.should respond_to(:files)
|
25
|
-
group.files.should be_kind_of(Array)
|
26
|
-
group.files.each do |file|
|
27
|
-
file.should be_kind_of(Uploadcare::Api::File)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should create group by id" do
|
32
|
-
group = @api.create_group @files
|
33
|
-
|
34
|
-
expect {group_uloaded = @api.group group.uuid}.to_not raise_error
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should create loaded and unloaded groups" do
|
38
|
-
group = @api.create_group @files
|
39
|
-
group_uloaded = @api.group group.uuid
|
40
|
-
group.is_loaded?.should be true
|
41
|
-
group_uloaded.is_loaded?.should be false
|
42
|
-
end
|
43
|
-
|
44
|
-
it "group should load data" do
|
45
|
-
group = @api.create_group @files
|
46
|
-
group_uloaded = @api.group group.uuid
|
47
|
-
group_uloaded.should respond_to(:load_data)
|
48
|
-
expect {group_uloaded.load_data}.to_not raise_error
|
49
|
-
group_uloaded.is_loaded?.should be true
|
50
|
-
end
|
51
|
-
|
52
|
-
it "group should store itself" do
|
53
|
-
group = @api.create_group @files
|
54
|
-
expect {group.store}.to_not raise_error
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should be able to tell when group is stored" do
|
58
|
-
group = @api.create_group @files
|
59
|
-
group_unloaded = @api.group group.uuid
|
60
|
-
|
61
|
-
group_unloaded.is_loaded?.should == false
|
62
|
-
group_unloaded.is_stored?.should == nil
|
63
|
-
|
64
|
-
group_unloaded.load
|
65
|
-
group_unloaded.is_stored?.should == false
|
66
|
-
|
67
|
-
group_unloaded.store
|
68
|
-
group_unloaded.is_stored?.should == true
|
69
|
-
end
|
70
|
-
|
71
|
-
it "group should have datetime attributes" do
|
72
|
-
group = @api.create_group @files
|
73
|
-
group.should respond_to(:datetime_created)
|
74
|
-
group.should respond_to(:datetime_stored)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "group should have datetime_created as DateTime object" do
|
78
|
-
group = @api.create_group @files
|
79
|
-
group.datetime_created.should be_kind_of(DateTime)
|
80
|
-
end
|
81
|
-
|
82
|
-
it "group should have datetime_created as DateTime object" do
|
83
|
-
group = @api.create_group @files
|
84
|
-
group.store
|
85
|
-
group.datetime_stored.should be_kind_of(DateTime)
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should return cdn string for file in group by it index" do
|
89
|
-
group = @api.create_group @files
|
90
|
-
|
91
|
-
file_cdn_url = group.file_cdn_url(0)
|
92
|
-
|
93
|
-
file_cdn_url.should be_kind_of(String)
|
94
|
-
file_cdn_url.should == group.cdn_url + "nth/0/"
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'should raise an error if index is greater than files count in group' do
|
98
|
-
group = @api.create_group @files
|
99
|
-
expect {group.file_cdn_url(5)}.to raise_error ArgumentError
|
100
|
-
end
|
101
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'uri'
|
3
|
-
require 'socket'
|
4
|
-
|
5
|
-
describe Uploadcare::Api::File do
|
6
|
-
before :all do
|
7
|
-
@api = API
|
8
|
-
@file = @api.upload IMAGE_URL
|
9
|
-
end
|
10
|
-
|
11
|
-
it "freshly uploaded file should have empty operations list" do
|
12
|
-
@file.should respond_to :operations
|
13
|
-
@file.operations.should be_kind_of(Array)
|
14
|
-
@file.operations.should be_empty
|
15
|
-
end
|
16
|
-
|
17
|
-
it "file created from uuid should be not loaded and without operations" do
|
18
|
-
file = @api.file @file.uuid
|
19
|
-
file.is_loaded?.should be false
|
20
|
-
file.operations.should be_empty
|
21
|
-
end
|
22
|
-
|
23
|
-
it "file created from url without operations should be not be loaded and have no operations" do
|
24
|
-
file = @api.file @file.cdn_url
|
25
|
-
file.is_loaded?.should be false
|
26
|
-
file.operations.should be_empty
|
27
|
-
end
|
28
|
-
|
29
|
-
it "file created from url with operations should be not be loaded and have operations" do
|
30
|
-
file = @api.file @file.cdn_url + "-/crop/150x150/center/-/format/png/"
|
31
|
-
file.is_loaded?.should be false
|
32
|
-
file.operations.should_not be_empty
|
33
|
-
end
|
34
|
-
|
35
|
-
it "file should have methods for construct cdn urls with or without cdn operations" do
|
36
|
-
@file.should respond_to(:cdn_url_with_operations)
|
37
|
-
@file.should respond_to(:cdn_url_without_operations)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "file should construct cdn_url with and without opreations" do
|
41
|
-
url_without_operations = @file.cdn_url
|
42
|
-
url_with_operations = @file.cdn_url + "-/crop/150x150/center/-/format/png/"
|
43
|
-
|
44
|
-
file = @api.file url_with_operations
|
45
|
-
|
46
|
-
file.cdn_url.should == (url_without_operations)
|
47
|
-
file.cdn_url(true).should == (url_with_operations)
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should works also with exact methods' do
|
51
|
-
url_without_operations = @file.cdn_url.to_s
|
52
|
-
url_with_operations = @file.cdn_url + "-/crop/150x150/center/-/format/png/"
|
53
|
-
|
54
|
-
file = @api.file url_with_operations
|
55
|
-
|
56
|
-
file.cdn_url_with_operations.should == (url_with_operations)
|
57
|
-
file.cdn_url_without_operations.should == (url_without_operations)
|
58
|
-
end
|
59
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'uri'
|
3
|
-
require 'socket'
|
4
|
-
|
5
|
-
describe Uploadcare::Api::Project do
|
6
|
-
before :all do
|
7
|
-
@api = API
|
8
|
-
@project = @api.project
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should instantiated project" do
|
12
|
-
@project.should be_kind_of Uploadcare::Api::Project
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should respond to project api methods" do
|
16
|
-
@project.should respond_to :collaborators
|
17
|
-
@project.should respond_to :name
|
18
|
-
@project.should respond_to :pub_key
|
19
|
-
@project.should respond_to :autostore_enabled
|
20
|
-
end
|
21
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'uri'
|
3
|
-
require 'socket'
|
4
|
-
|
5
|
-
describe Uploadcare::Connections::ApiConnection do
|
6
|
-
let(:settings){ Uploadcare.default_settings }
|
7
|
-
|
8
|
-
it 'is initializable with default settings' do
|
9
|
-
expect {described_class.new(settings)}.to_not raise_error
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
describe 'default request headers' do
|
14
|
-
subject{ described_class.new(settings).headers }
|
15
|
-
|
16
|
-
it 'includes correct Accept header' do
|
17
|
-
expected = "application/vnd.uploadcare-v#{settings[:api_version]}+json"
|
18
|
-
expect(subject['Accept']).to eq expected
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'includes correct User-Agent header' do
|
22
|
-
expected = Uploadcare::UserAgent.new.call(settings)
|
23
|
-
expect(subject['User-Agent']).to eq expected
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
describe 'middleware' do
|
29
|
-
subject{ described_class.new(settings).builder.handlers }
|
30
|
-
|
31
|
-
it 'uses Request::Auth middleware' do
|
32
|
-
expect(subject).to include(Uploadcare::Connections::Request::Auth)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'uses Response::ParseJson middleware' do
|
36
|
-
expect(subject).to include(Uploadcare::Connections::Response::ParseJson)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'uses Response::RaiseError middleware' do
|
40
|
-
expect(subject).to include(Uploadcare::Connections::Response::RaiseError)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
describe 'auth scheme' do
|
46
|
-
it 'uses simple auth when auth_scheme: :simple setting is provided' do
|
47
|
-
expect(Uploadcare::Connections::Auth::Simple).to receive(:new)
|
48
|
-
described_class.new(settings.merge(auth_scheme: :simple))
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'uses secure auth when auth_scheme: :secure setting is provided' do
|
52
|
-
expect(Uploadcare::Connections::Auth::Secure).to receive(:new)
|
53
|
-
described_class.new(settings.merge(auth_scheme: :secure))
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'raises KeyError when :auth_scheme options is not provided' do
|
57
|
-
expect{
|
58
|
-
described_class.new(settings.reject{|k,_| k == :auth_scheme})
|
59
|
-
}.to raise_error(KeyError)
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'raises ArgumentError when provided :auth_scheme is unknown' do
|
63
|
-
expect{
|
64
|
-
described_class.new(settings.merge(auth_scheme: :unknown))
|
65
|
-
}.to raise_error(ArgumentError)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -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
|