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.
Files changed (116) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/gem-push.yml +20 -0
  3. data/.github/workflows/ruby.yml +52 -0
  4. data/.gitignore +13 -6
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +32 -0
  7. data/.yardopts +4 -0
  8. data/CHANGELOG.md +33 -34
  9. data/DEVELOPMENT.md +18 -0
  10. data/Gemfile +2 -0
  11. data/LICENSE +1 -1
  12. data/README.md +369 -546
  13. data/Rakefile +5 -5
  14. data/bin/console +15 -0
  15. data/bin/setup +8 -0
  16. data/lib/uploadcare.rb +36 -26
  17. data/lib/uploadcare/api/api.rb +25 -0
  18. data/lib/uploadcare/client/conversion/base_conversion_client.rb +54 -0
  19. data/lib/uploadcare/client/conversion/document_conversion_client.rb +38 -0
  20. data/lib/uploadcare/client/conversion/video_conversion_client.rb +42 -0
  21. data/lib/uploadcare/client/file_client.rb +44 -0
  22. data/lib/uploadcare/client/file_list_client.rb +46 -0
  23. data/lib/uploadcare/client/group_client.rb +45 -0
  24. data/lib/uploadcare/client/multipart_upload/chunks_client.rb +48 -0
  25. data/lib/uploadcare/client/multipart_upload_client.rb +67 -0
  26. data/lib/uploadcare/client/project_client.rb +18 -0
  27. data/lib/uploadcare/client/rest_client.rb +74 -0
  28. data/lib/uploadcare/client/rest_group_client.rb +23 -0
  29. data/lib/uploadcare/client/upload_client.rb +36 -0
  30. data/lib/uploadcare/client/uploader_client.rb +109 -0
  31. data/lib/uploadcare/client/webhook_client.rb +47 -0
  32. data/lib/uploadcare/concern/error_handler.rb +54 -0
  33. data/lib/uploadcare/concern/throttle_handler.rb +25 -0
  34. data/lib/uploadcare/concern/upload_error_handler.rb +32 -0
  35. data/lib/uploadcare/entity/decorator/paginator.rb +79 -0
  36. data/lib/uploadcare/entity/document_converter.rb +26 -0
  37. data/lib/uploadcare/entity/entity.rb +18 -0
  38. data/lib/uploadcare/entity/file.rb +81 -0
  39. data/lib/uploadcare/entity/file_list.rb +31 -0
  40. data/lib/uploadcare/entity/group.rb +40 -0
  41. data/lib/uploadcare/entity/group_list.rb +24 -0
  42. data/lib/uploadcare/entity/project.rb +13 -0
  43. data/lib/uploadcare/entity/uploader.rb +75 -0
  44. data/lib/uploadcare/entity/video_converter.rb +26 -0
  45. data/lib/uploadcare/entity/webhook.rb +14 -0
  46. data/lib/uploadcare/exception/conversion_error.rb +8 -0
  47. data/lib/uploadcare/exception/request_error.rb +9 -0
  48. data/lib/uploadcare/exception/throttle_error.rb +16 -0
  49. data/lib/uploadcare/param/authentication_header.rb +25 -0
  50. data/lib/uploadcare/param/conversion/document/processing_job_url_builder.rb +39 -0
  51. data/lib/uploadcare/param/conversion/video/processing_job_url_builder.rb +64 -0
  52. data/lib/uploadcare/param/param.rb +10 -0
  53. data/lib/uploadcare/param/secure_auth_header.rb +37 -0
  54. data/lib/uploadcare/param/simple_auth_header.rb +14 -0
  55. data/lib/uploadcare/param/upload/signature_generator.rb +24 -0
  56. data/lib/uploadcare/param/upload/upload_params_generator.rb +23 -0
  57. data/lib/uploadcare/param/user_agent.rb +21 -0
  58. data/lib/uploadcare/ruby/version.rb +5 -0
  59. data/uploadcare-ruby.gemspec +50 -37
  60. metadata +109 -115
  61. data/.travis.yml +0 -26
  62. data/UPGRADE_NOTES.md +0 -36
  63. data/lib/uploadcare/api.rb +0 -26
  64. data/lib/uploadcare/api/file_api.rb +0 -7
  65. data/lib/uploadcare/api/file_list_api.rb +0 -19
  66. data/lib/uploadcare/api/file_storage_api.rb +0 -34
  67. data/lib/uploadcare/api/group_api.rb +0 -38
  68. data/lib/uploadcare/api/group_list_api.rb +0 -17
  69. data/lib/uploadcare/api/project_api.rb +0 -9
  70. data/lib/uploadcare/api/raw_api.rb +0 -38
  71. data/lib/uploadcare/api/uploading_api.rb +0 -71
  72. data/lib/uploadcare/api/uploading_api/upload_params.rb +0 -72
  73. data/lib/uploadcare/api/validators/file_list_options_validator.rb +0 -73
  74. data/lib/uploadcare/api/validators/group_list_options_validator.rb +0 -49
  75. data/lib/uploadcare/errors/errors.rb +0 -64
  76. data/lib/uploadcare/resources/file.rb +0 -164
  77. data/lib/uploadcare/resources/file_list.rb +0 -14
  78. data/lib/uploadcare/resources/group.rb +0 -115
  79. data/lib/uploadcare/resources/group_list.rb +0 -14
  80. data/lib/uploadcare/resources/project.rb +0 -13
  81. data/lib/uploadcare/resources/resource_list.rb +0 -83
  82. data/lib/uploadcare/rest/auth/auth.rb +0 -31
  83. data/lib/uploadcare/rest/auth/secure.rb +0 -43
  84. data/lib/uploadcare/rest/auth/simple.rb +0 -16
  85. data/lib/uploadcare/rest/connections/api_connection.rb +0 -53
  86. data/lib/uploadcare/rest/connections/upload_connection.rb +0 -22
  87. data/lib/uploadcare/rest/middlewares/auth_middleware.rb +0 -24
  88. data/lib/uploadcare/rest/middlewares/parse_json_middleware.rb +0 -33
  89. data/lib/uploadcare/rest/middlewares/raise_error_middleware.rb +0 -21
  90. data/lib/uploadcare/utils/parser.rb +0 -71
  91. data/lib/uploadcare/utils/user_agent.rb +0 -44
  92. data/lib/uploadcare/version.rb +0 -3
  93. data/spec/api/file_list_api_spec.rb +0 -95
  94. data/spec/api/file_storage_api_spec.rb +0 -88
  95. data/spec/api/group_list_api_spec.rb +0 -59
  96. data/spec/api/raw_api_spec.rb +0 -25
  97. data/spec/api/uploading_api/upload_params_spec.rb +0 -99
  98. data/spec/api/uploading_api_spec.rb +0 -59
  99. data/spec/resources/file_list_spec.rb +0 -25
  100. data/spec/resources/file_spec.rb +0 -223
  101. data/spec/resources/group_list_spec.rb +0 -25
  102. data/spec/resources/group_spec.rb +0 -101
  103. data/spec/resources/operations_spec.rb +0 -59
  104. data/spec/resources/project_spec.rb +0 -21
  105. data/spec/rest/api_connection_spec.rb +0 -68
  106. data/spec/rest/auth/secure_spec.rb +0 -66
  107. data/spec/rest/auth/simple_spec.rb +0 -31
  108. data/spec/rest/errors_spec.rb +0 -75
  109. data/spec/rest/upload_connection_spec.rb +0 -19
  110. data/spec/shared/resource_list.rb +0 -188
  111. data/spec/spec_helper.rb +0 -54
  112. data/spec/uploadcare_spec.rb +0 -16
  113. data/spec/utils/parser_spec.rb +0 -85
  114. data/spec/utils/user_agent_spec.rb +0 -46
  115. data/spec/view.png +0 -0
  116. data/spec/view2.jpg +0 -0
@@ -1,88 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Uploadcare::FileStorageApi do
4
- let(:api){ API }
5
- let(:file){ api.file_list(limit: 1).first || api.upload(IMAGE_URL) }
6
-
7
- shared_examples 'batch action on files' do
8
- let(:uuids) { ["dc2c175d-a3b5-4435-b4f4-fae77bbe5597", "cea319aa-6e17-4172-8722-8dd7c459a523"] }
9
- let(:files) { uuids.map { |uuid| Uploadcare::Api::File.new(api, uuid) } }
10
- let(:api_endpoint) { "/files/storage/" }
11
-
12
- it 'accepts array of uuids' do
13
- expect(api).to receive(http_method)
14
- expect { subject.call(uuids) }.not_to raise_error
15
- end
16
-
17
- it 'accepts enumerable containing Uploadcare::Api::File objects' do
18
- expect(api).to receive(http_method)
19
- expect { subject.call(files) }.not_to raise_error
20
- end
21
-
22
- it 'converts Uploadcare::Api::File-s to uuids' do
23
- expect(api).to receive(http_method).with(api_endpoint, uuids)
24
- subject.call(files)
25
- end
26
-
27
- context 'when input contains something other than UUIDs or Uploadcare::Api::File-s' do
28
- it 'raises ArgumentError' do
29
- ['not-an-uuid', nil, 1].each do |wrong_input_value|
30
- expect { subject.call([wrong_input_value]) }.to raise_error(ArgumentError)
31
- end
32
- end
33
- end
34
-
35
- it 'raises ArgumentError if input size is grater then max batch size' do
36
- stub_const("Uploadcare::FileStorageApi::MAX_BATCH_SIZE", 1)
37
- expect { subject.call(uuids) }.to raise_error(ArgumentError)
38
- end
39
- end
40
-
41
- describe '#store_files' do
42
- let(:http_method) { :put }
43
- subject { ->(objects) { api.store_files(objects) } }
44
-
45
- it_behaves_like 'batch action on files'
46
-
47
- describe 'integration test' do
48
- before { file.tap { |f| wait_until_ready(f) }.delete if file.stored? }
49
- subject(:store_files) { -> { api.store_files([file]) } }
50
-
51
- it 'stores files with given uuids' do
52
- is_expected.to change { file.load!.stored? }.from(false).to(true)
53
- end
54
-
55
- it 'returns the API response' do
56
- expect(store_files.call).to include(
57
- "status" => "ok",
58
- "problems" => {},
59
- "result" => [be_a(Hash)]
60
- )
61
- end
62
- end
63
- end
64
-
65
- describe '#delete_files' do
66
- let(:http_method) { :delete }
67
- subject { ->(objects) { api.delete_files(objects) } }
68
-
69
- it_behaves_like 'batch action on files'
70
-
71
- describe 'integration test' do
72
- before { file.store if file.deleted? }
73
- subject(:delete_files) { -> { api.delete_files([file]) } }
74
-
75
- it 'deletes files with given uuids' do
76
- is_expected.to change { file.load!.deleted? }.from(false).to(true)
77
- end
78
-
79
- it 'returns the API response' do
80
- expect(delete_files.call).to include(
81
- "status" => "ok",
82
- "problems" => {},
83
- "result" => [be_a(Hash)]
84
- )
85
- end
86
- end
87
- end
88
- end
@@ -1,59 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Uploadcare::GroupListApi do
4
- let(:api){ API }
5
- subject{ api.group_list(limit: 1) }
6
-
7
- before(:each){ allow(api).to receive(:get){ {'results' => []} } }
8
-
9
- it 'returns a group list' do
10
- expect( subject ).to be_a(Uploadcare::Api::GroupList)
11
- end
12
-
13
- it 'stores options in a group list object' do
14
- expect( subject.options ).to eq({limit: 1})
15
- end
16
-
17
- describe 'validation' do
18
- it 'passes validation when no options given' do
19
- expect{ api.group_list }.not_to raise_error
20
- end
21
-
22
- it "validates that options don't have unsupported keys" do
23
- expect{ api.group_list(unknown: 1) }.to raise_error(ArgumentError)
24
- end
25
-
26
- it 'validates that :limit is an integer from 1 to 1000' do
27
- [1, 359, 1000].each do |v|
28
- expect{ api.group_list(limit: v) }.not_to raise_error
29
- end
30
-
31
- [1.0, -1, 0, 1001, false].each do |v|
32
- expect{ api.group_list(limit: v) }.to raise_error(ArgumentError)
33
- end
34
- end
35
-
36
- valid_ordering = %w{datetime_created -datetime_created}
37
- it "validates that :ordering is in [#{valid_ordering.join(', ')}]" do
38
- valid_ordering.each do |valid_value|
39
- expect{ api.group_list(ordering: valid_value) }.not_to raise_error
40
- end
41
-
42
- expect{ api.group_list(ordering: 'yes') }.to raise_error(ArgumentError)
43
- end
44
-
45
- describe 'from' do
46
- it 'validates that :from.to_s is a iso8601 string' do
47
- valid = [DateTime.now, DateTime.now.iso8601, "2017-01-01T15"]
48
- valid.each do |value|
49
- expect{ api.group_list(from: value) }.not_to raise_error
50
- end
51
-
52
- invalid = [Date.today, Time.now, DateTime.now.rfc2822, "2017-01-01", 123, false]
53
- invalid.each do |value|
54
- expect{ api.group_list(from: value) }.to raise_error(ArgumentError)
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
- require 'uri'
3
- require 'socket'
4
-
5
- describe Uploadcare::Api do
6
- subject(:api) { Uploadcare::Api.new(CONFIG) }
7
-
8
- it "should initialize api" do
9
- is_expected.to be_an_instance_of(Uploadcare::Api)
10
- end
11
-
12
- it 'should respond to request methods' do
13
- is_expected.to respond_to :request
14
- is_expected.to respond_to :get
15
- is_expected.to respond_to :post
16
- is_expected.to respond_to :put
17
- is_expected.to respond_to :delete
18
- end
19
-
20
- context 'when performing requests' do
21
- subject(:request) { api.request }
22
-
23
- it { is_expected.to be_a Hash }
24
- end
25
- end
@@ -1,99 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Uploadcare::UploadingApi::UploadParams do
4
- shared_examples 'handles store flag' do |key_name|
5
- let(:true_value) { 1 }
6
- let(:false_value) { 0 }
7
-
8
- context 'when neither global nor per-request store option is set' do
9
- it { is_expected.not_to include(key_name) }
10
- end
11
-
12
- context 'accepts :auto value in :store option' do
13
- before { request_options.merge!(store: :auto) }
14
- it { is_expected.to include(key_name => 'auto') }
15
- end
16
-
17
- context 'when only global :autostore option is set' do
18
- context 'to true' do
19
- before { global_options.merge!(autostore: true) }
20
- it { is_expected.to include(key_name => true_value) }
21
- end
22
-
23
- context 'to false' do
24
- before { global_options.merge!(autostore: false) }
25
- it { is_expected.to include(key_name => false_value) }
26
- end
27
- end
28
-
29
- context 'per-request :store option is set' do
30
- context 'to true' do
31
- before { request_options.merge!(store: true) }
32
- it { is_expected.to include(key_name => true_value) }
33
- end
34
-
35
- context 'to false' do
36
- before { request_options.merge!(store: false) }
37
- it { is_expected.to include(key_name => false_value) }
38
- end
39
- end
40
-
41
- context 'when both global and per-request store options are set' do
42
- before do
43
- global_options.merge!(autostore: false)
44
- request_options.merge!(store: true)
45
- end
46
-
47
- it 'per-request :store option has higher presidence' do
48
- is_expected.to include(key_name => true_value)
49
- end
50
- end
51
- end
52
-
53
- let(:global_options) { {public_key: 'test_public_key'} }
54
- let(:request_options) { {} }
55
-
56
- describe '#for_url_upload' do
57
- let(:url) { 'http://example.com/image.jpg' }
58
- subject(:upload_params) do
59
- described_class.new(global_options, request_options).for_url_upload(url)
60
- end
61
-
62
- it { is_expected.to include(source_url: URI.parse(url)) }
63
- it { is_expected.to include(pub_key: 'test_public_key') }
64
- it_behaves_like 'handles store flag', :store
65
-
66
- context 'works with https URLs' do
67
- let(:url) { 'https://example.com/image.jpg' }
68
- it { expect { upload_params }.not_to raise_error }
69
- end
70
-
71
- context 'if url is not http/https' do
72
- let(:url) { 'ftp://example.com/image.jpg' }
73
- it { expect { upload_params }.to raise_error(ArgumentError) }
74
- end
75
- end
76
-
77
- describe '#for_file_upload' do
78
- let(:files) { FILES_ARY } # contains 2 files, first is png, second is jpg
79
- subject(:upload_params) do
80
- described_class.new(global_options, request_options).for_file_upload(files)
81
- end
82
-
83
- it { is_expected.to include(UPLOADCARE_PUB_KEY: 'test_public_key') }
84
- it_behaves_like 'handles store flag', :UPLOADCARE_STORE
85
-
86
- context 'file params' do
87
- subject(:file_params) { upload_params.select { |k, _| k =~ /^file\[\d+\]/ }.values }
88
-
89
- it { expect(file_params.size).to eq(files.size) }
90
- it { is_expected.to all(be_a(Faraday::UploadIO)) }
91
- it { is_expected.to all(satisfy { |file| file.content_type =~ /image\/(png|jpeg)/}) }
92
- end
93
-
94
- context 'when any of given objects is not a File' do
95
- let(:files) { FILES_ARY + ['not a File'] }
96
- it { expect {upload_params}.to raise_error(ArgumentError) }
97
- end
98
- end
99
- end
@@ -1,59 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Uploadcare::Api do
4
- shared_examples 'respects :store option' do
5
- context 'respects :store option' do
6
- let(:upload_options) { {store: store} }
7
- subject { Array(uploaded).map(&:load_data) }
8
-
9
- context 'when :store option is true' do
10
- let(:store) { true }
11
- it { is_expected.to all(be_stored) }
12
- end
13
-
14
- define_negated_matcher :be_not_stored, :be_stored
15
- context 'when :store option is false' do
16
- let(:store) { false }
17
- it { is_expected.to all(be_not_stored) }
18
- end
19
- end
20
- end
21
-
22
- let(:api) { API }
23
- let(:upload_options) { {} }
24
-
25
- context 'when uploading single object' do
26
- subject(:uploaded) { api.upload(object, upload_options) }
27
-
28
- context 'when uploading a file' do
29
- let(:object) { FILE1 }
30
-
31
- it { is_expected.to be_a(Uploadcare::Api::File) }
32
- it { is_expected.to have_attributes(uuid: match(UUID_REGEX)) }
33
- include_examples 'respects :store option'
34
- end
35
-
36
- context 'when uploading from url' do
37
- let(:object) { IMAGE_URL }
38
-
39
- it { is_expected.to be_a(Uploadcare::Api::File) }
40
- it { is_expected.to have_attributes(uuid: match(UUID_REGEX)) }
41
- it { expect { api.upload('invalid.url.') }.to raise_error(ArgumentError) }
42
- include_examples 'respects :store option'
43
- end
44
- end
45
-
46
- context 'when loading multiple objects' do
47
- before(:all) { @uploaded_files = API.upload(FILES_ARY) }
48
- subject(:uploaded) { @uploaded_files.dup }
49
-
50
- it { is_expected.to be_a(Array) }
51
- it { is_expected.to all(be_a(Uploadcare::Api::File)) }
52
- it { is_expected.to all(have_attributes(uuid: match(UUID_REGEX))) }
53
- it { expect { uploaded.map(&:load_data) }.not_to raise_error }
54
- end
55
-
56
- context 'when given object is not a File, Array or String' do
57
- it { expect { api.upload(12) }.to raise_error(ArgumentError) }
58
- end
59
- end
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Uploadcare::Api::FileList do
4
- before :all do
5
- @api = API
6
-
7
- # ensure that current project has at least three files
8
- count = @api.get('/files/', limit: 3)['results'].size
9
- (3 - count).times{ @api.upload(IMAGE_URL) } if count < 3
10
-
11
- @list = @api.file_list(limit: 1)
12
- end
13
-
14
- let(:resource_class){ Uploadcare::Api::File }
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.to all(be_loaded) }
24
- end
25
- end
@@ -1,223 +0,0 @@
1
- require 'spec_helper'
2
- require 'uri'
3
- require 'socket'
4
- require 'securerandom'
5
-
6
- describe Uploadcare::Api::File do
7
- let(:api) { API }
8
- let(:file) { api.upload IMAGE_URL }
9
-
10
- it 'is an instance of File' do
11
- expect(file).to be_an_instance_of Uploadcare::Api::File
12
- end
13
-
14
- it 'is not initialized without correct UUID given' do
15
- expect {Uploadcare::Api::File.new(api, "not-uuid")}.to raise_error NoMethodError
16
- end
17
-
18
- it 'has a valid url' do
19
- expect(file.uuid).to match UUID_REGEX
20
- end
21
-
22
- it 'returns a public url' do
23
- expect(file).to respond_to :cdn_url
24
- expect(file).to respond_to :public_url
25
- end
26
-
27
- it 'has a public url that is valid' do
28
- url = file.cdn_url
29
- uri = URI.parse(url)
30
- expect(uri).to be_kind_of(URI::HTTP)
31
- end
32
-
33
- it 'is able to load image data' do
34
- expect {file.load_data}.to_not raise_error
35
- end
36
-
37
- it 'stores itself' do
38
- expect { file.store }.to_not raise_error
39
- end
40
-
41
- it 'responds with nil for :stored? and :deleted? methods unless loaded' do
42
- expect(file.is_loaded?).to be false
43
- expect(file.is_stored?).to be_nil
44
- expect(file.is_deleted?).to be_nil
45
- end
46
-
47
- it 'is able to tell thenever file was stored' do
48
- file.load
49
- expect(file.stored?).to be(true)
50
- wait_until_ready(file)
51
- file.delete
52
- expect(file.stored?).to be(false)
53
- end
54
-
55
- it 'deletes itself' do
56
- expect { file.delete }.to_not raise_error
57
- end
58
-
59
- it 'is able to tell thenever file was deleted' do
60
- file.load
61
- file.is_deleted?.should == false
62
- wait_until_ready(file)
63
- file.delete
64
- expect(file.is_deleted?).to be true
65
- end
66
-
67
- it 'constructs file from uuid' do
68
- uuid_file = api.file file.uuid
69
- expect(uuid_file).to be_kind_of(Uploadcare::Api::File)
70
- end
71
-
72
- it 'constructs file from cdn url' do
73
- url = file.cdn_url + "-/crop/150x150/center/-/format/png/"
74
- file = api.file url
75
- expect(file).to be_kind_of(Uploadcare::Api::File)
76
- end
77
-
78
- it 'responds to datetime_ methods' do
79
- file.load
80
- expect(file).to respond_to(:datetime_original)
81
- expect(file).to respond_to(:datetime_uploaded)
82
- expect(file).to respond_to(:datetime_stored)
83
- expect(file).to respond_to(:datetime_removed)
84
- end
85
-
86
- it 'responds to datetime_uploaded' do
87
- file.load
88
- expect(file.datetime_uploaded).to be_kind_of(DateTime)
89
- end
90
-
91
- it 'responds to datetime_stored' do
92
- file.load
93
- file.store
94
- expect(file.datetime_stored).to be_kind_of(DateTime)
95
- end
96
-
97
- it 'responds to datetime_removed' do
98
- file.load
99
- wait_until_ready(file)
100
- file.delete
101
- expect(file.datetime_removed).to be_kind_of(DateTime)
102
- expect(file.datetime_deleted).to be_kind_of(DateTime)
103
- expect(file.datetime_removed).to eq file.datetime_deleted
104
- end
105
-
106
-
107
- it 'copies itself' do
108
- # This can cause "File is not ready yet" error if ran too early
109
- # In this case we retry it 3 times before giving up
110
- result = retry_if(Uploadcare::Error::RequestError::BadRequest){file.copy}
111
- expect(result).to be_kind_of(Hash)
112
- expect(result["type"]).to eq "file"
113
- end
114
-
115
-
116
- describe '#internal_copy' do
117
- describe 'integration' do
118
- it 'creates an internal copy of the file' do
119
- response = retry_if(Uploadcare::Error::RequestError::BadRequest){file.internal_copy}
120
-
121
- expect( response['type'] ).to eq 'file'
122
- expect( response['result']['uuid'] ).not_to eq file.uuid
123
- end
124
- end
125
-
126
- describe 'params' do
127
- let(:url_without_ops){ api.file(SecureRandom.uuid).cdn_url }
128
- let(:url_with_ops){ url_without_ops + "-/crop/5x5/center/" }
129
- let(:file){ api.file(url_with_ops) }
130
-
131
- context 'if no params given' do
132
- it 'requests server to create an unstored copy with operataions applied' do
133
- expect(api).to receive(:post)
134
- .with('/files/', source: url_with_ops)
135
-
136
- file.internal_copy
137
- end
138
- end
139
-
140
- context 'if strip_operations: true given' do
141
- it 'passes url without operations as a source for a copy' do
142
- expect(api).to receive(:post)
143
- .with('/files/', source: url_without_ops)
144
-
145
- file.internal_copy(strip_operations: true)
146
- end
147
- end
148
-
149
- context 'if store: true given' do
150
- it 'requests server to create a stored copy' do
151
- expect(api).to receive(:post)
152
- .with('/files/', source: url_with_ops, store: true)
153
-
154
- file.internal_copy(store: true)
155
- end
156
- end
157
- end
158
- end
159
-
160
-
161
- describe '#external_copy' do
162
- let(:target){ 'with-prefix' }
163
-
164
- describe 'integration', :payed_feature do
165
- it 'creates an external copy of the file' do
166
- response = retry_if(Uploadcare::Error::RequestError::BadRequest) do
167
- file.external_copy(target)
168
- end
169
-
170
- expect( response['type'] ).to eq 'url'
171
- expect( response['result'] ).to match(URI.regexp)
172
- end
173
- end
174
-
175
- describe 'params' do
176
- let(:url_without_ops){ api.file(SecureRandom.uuid).cdn_url }
177
- let(:url_with_ops){ url_without_ops + "-/resize/50x50/" }
178
- let(:file){ api.file(url_with_ops) }
179
-
180
- context 'if only target is given' do
181
- it 'requests server to create a private copy with default name and with operataions applied' do
182
- expect(api).to receive(:post)
183
- .with('/files/', source: url_with_ops, target: target)
184
-
185
- file.external_copy(target)
186
- end
187
- end
188
-
189
- context 'if target is not given' do
190
- it 'raises ArgumentError' do
191
- expect{ file.external_copy }.to raise_error(ArgumentError)
192
- end
193
- end
194
-
195
- context 'if strip_operations: true given' do
196
- it 'passes url without operations as a source for a copy' do
197
- expect(api).to receive(:post)
198
- .with('/files/', source: url_without_ops, target: target)
199
-
200
- file.external_copy(target, strip_operations: true)
201
- end
202
- end
203
-
204
- context 'if :make_public given' do
205
- it 'requests server to create a copy with correspondent permissions' do
206
- expect(api).to receive(:post)
207
- .with('/files/', source: url_with_ops, target: target, make_public: false)
208
-
209
- file.external_copy(target, make_public: false)
210
- end
211
- end
212
-
213
- context 'if :pattern given' do
214
- it 'requests server to apply given pattern to name of a copy' do
215
- expect(api).to receive(:post)
216
- .with('/files/', source: url_with_ops, target: target, pattern: 'test')
217
-
218
- file.external_copy(target, pattern: 'test')
219
- end
220
- end
221
- end
222
- end
223
- end