uploadcare-rails 2.1.1 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/lib/uploadcare/rails/api/rest/addons_api.rb +54 -0
  3. data/lib/uploadcare/rails/api/rest/base.rb +3 -2
  4. data/lib/uploadcare/rails/api/rest/conversion_api.rb +8 -8
  5. data/lib/uploadcare/rails/api/rest/file_api.rb +20 -13
  6. data/lib/uploadcare/rails/api/rest/file_metadata_api.rb +42 -0
  7. data/lib/uploadcare/rails/api/rest/group_api.rb +12 -6
  8. data/lib/uploadcare/rails/api/rest/project_api.rb +1 -1
  9. data/lib/uploadcare/rails/api/rest/webhook_api.rb +6 -6
  10. data/lib/uploadcare/rails/api/upload/base.rb +2 -0
  11. data/lib/uploadcare/rails/api/upload/upload_api.rb +4 -4
  12. data/lib/uploadcare/rails/configuration.rb +3 -1
  13. data/lib/uploadcare/rails/objects/group.rb +1 -3
  14. data/lib/uploadcare/rails/transformations/image_transformations.rb +1 -1
  15. data/lib/uploadcare/rails/version.rb +1 -1
  16. data/lib/uploadcare-rails.rb +2 -0
  17. metadata +31 -126
  18. data/spec/fixtures/kitten.jpeg +0 -0
  19. data/spec/fixtures/vcr_cassettes/conversion_api_convert_document.yml +0 -62
  20. data/spec/fixtures/vcr_cassettes/conversion_api_convert_document_with_error.yml +0 -62
  21. data/spec/fixtures/vcr_cassettes/conversion_api_convert_video.yml +0 -62
  22. data/spec/fixtures/vcr_cassettes/conversion_api_convert_video_with_error.yml +0 -62
  23. data/spec/fixtures/vcr_cassettes/conversion_api_get_document_conversion_status.yml +0 -59
  24. data/spec/fixtures/vcr_cassettes/conversion_api_get_video_conversion_status.yml +0 -59
  25. data/spec/fixtures/vcr_cassettes/file_api_copy_file.yml +0 -60
  26. data/spec/fixtures/vcr_cassettes/file_api_delete_file.yml +0 -58
  27. data/spec/fixtures/vcr_cassettes/file_api_delete_files.yml +0 -58
  28. data/spec/fixtures/vcr_cassettes/file_api_get_file.yml +0 -58
  29. data/spec/fixtures/vcr_cassettes/file_api_get_files.yml +0 -61
  30. data/spec/fixtures/vcr_cassettes/file_api_load_file.yml +0 -57
  31. data/spec/fixtures/vcr_cassettes/file_api_store_file.yml +0 -58
  32. data/spec/fixtures/vcr_cassettes/file_api_store_files.yml +0 -57
  33. data/spec/fixtures/vcr_cassettes/group_api_create_group.yml +0 -57
  34. data/spec/fixtures/vcr_cassettes/group_api_get_group.yml +0 -52
  35. data/spec/fixtures/vcr_cassettes/group_api_get_groups.yml +0 -57
  36. data/spec/fixtures/vcr_cassettes/group_api_store_group.yml +0 -57
  37. data/spec/fixtures/vcr_cassettes/project_api_get_project.yml +0 -59
  38. data/spec/fixtures/vcr_cassettes/upload_upload_many_files.yml +0 -55
  39. data/spec/fixtures/vcr_cassettes/upload_upload_one_file.yml +0 -105
  40. data/spec/fixtures/vcr_cassettes/upload_upload_one_file_from_cdn.yml +0 -111
  41. data/spec/fixtures/vcr_cassettes/webhook_api_create_webhook.yml +0 -59
  42. data/spec/fixtures/vcr_cassettes/webhook_api_delete_webhook.yml +0 -57
  43. data/spec/fixtures/vcr_cassettes/webhook_api_get_webhooks.yml +0 -59
  44. data/spec/fixtures/vcr_cassettes/webhook_api_update_webhook.yml +0 -59
  45. data/spec/generators/uploadcare_config_generator_spec.rb +0 -31
  46. data/spec/spec_helper.rb +0 -26
  47. data/spec/support/generators.rb +0 -41
  48. data/spec/support/vcr.rb +0 -14
  49. data/spec/uploadcare/rails/action_view/uploadcare_uploader_tags_spec.rb +0 -40
  50. data/spec/uploadcare/rails/action_view/uploadcare_widget_tags_spec.rb +0 -46
  51. data/spec/uploadcare/rails/active_record/mount_uploadcare_file_spec.rb +0 -33
  52. data/spec/uploadcare/rails/active_record/mount_uploadcare_group_spec.rb +0 -32
  53. data/spec/uploadcare/rails/api/rest/conversion_api_spec.rb +0 -110
  54. data/spec/uploadcare/rails/api/rest/file_api_spec.rb +0 -85
  55. data/spec/uploadcare/rails/api/rest/group_api_spec.rb +0 -61
  56. data/spec/uploadcare/rails/api/rest/project_api_spec.rb +0 -33
  57. data/spec/uploadcare/rails/api/rest/webhook_api_spec.rb +0 -67
  58. data/spec/uploadcare/rails/api/upload/upload_api_spec.rb +0 -82
  59. data/spec/uploadcare/rails/jobs/delete_file_job_spec.rb +0 -15
  60. data/spec/uploadcare/rails/jobs/store_file_job_spec.rb +0 -15
  61. data/spec/uploadcare/rails/jobs/store_group_job_spec.rb +0 -15
  62. data/spec/uploadcare/rails/objects/file_spec.rb +0 -77
  63. data/spec/uploadcare/rails/objects/group_spec.rb +0 -87
  64. data/spec/uploadcare/rails/services/id_extractor_spec.rb +0 -26
  65. data/spec/uploadcare/rails/transformations/image_transformations_spec.rb +0 -120
  66. data/spec/uploadcare/rails_spec.rb +0 -7
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/api/rest/webhook_api'
5
-
6
- module Uploadcare
7
- module Rails
8
- module Api
9
- module Rest
10
- RSpec.describe WebhookApi do
11
- subject { Uploadcare::WebhookApi }
12
-
13
- context 'when checking methods' do
14
- it 'responds to expected REST methods' do
15
- %i[get_webhooks create_webhook update_webhook delete_webhook].each do |method|
16
- expect(subject).to respond_to(method)
17
- end
18
- end
19
- end
20
-
21
- context 'when sending requests', :aggregate_failures do
22
- it 'gets webhooks info' do
23
- VCR.use_cassette('webhook_api_get_webhooks') do
24
- response = subject.get_webhooks
25
- expect(response).not_to be_empty
26
- end
27
- end
28
-
29
- it 'creates a webhook', :aggregate_failures do
30
- VCR.use_cassette('webhook_api_create_webhook') do
31
- response = subject.create_webhook(
32
- 'https://ucarecdn.com/3542c513-5cf4-4adb-97b0-bfa7fbd31fb5/11.png',
33
- signing_secret: '1234'
34
- )
35
- %w[id created updated event target_url project is_active].each do |key|
36
- expect(response).to have_key(key)
37
- end
38
- end
39
- end
40
-
41
- it 'updates a webhook', :aggregate_failures do
42
- VCR.use_cassette('webhook_api_update_webhook') do
43
- new_target_url = 'https://ucarecdn.com/3542c513-5cf4-4adb-97b0-bfa7fbd31fb5/11.png'
44
- response = subject.update_webhook(
45
- '811134',
46
- target_url: new_target_url,
47
- is_active: false,
48
- signing_secret: '1234'
49
- )
50
- expect(response['target_url']).to eq(new_target_url)
51
- expect(response['is_active']).to eq(false)
52
- end
53
- end
54
-
55
- it 'deletes a webhook', :aggregate_failures do
56
- VCR.use_cassette('webhook_api_delete_webhook') do
57
- target_url = 'https://ucarecdn.com/3542c513-5cf4-4adb-97b0-bfa7fbd31fb5/11.png'
58
- response = subject.delete_webhook(target_url)
59
- expect(response).to be_success
60
- end
61
- end
62
- end
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,82 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/api/upload/upload_api'
5
-
6
- # These specs include specs from uploadcare-ruby to check proper work with different rails versions.
7
- # They probably will be moved to the uploadcare-ruby gem in future releases.
8
- module Uploadcare
9
- module Rails
10
- module Api
11
- module Upload
12
- RSpec.describe UploadApi do
13
- subject { Uploadcare::UploadApi }
14
-
15
- context 'when checking methods' do
16
- it 'responds to expected REST methods' do
17
- %i[upload_file upload_files].each do |method|
18
- expect(subject).to respond_to(method)
19
- end
20
- end
21
- end
22
-
23
- context 'when sending requests' do
24
- context 'and when uploading a single file' do
25
- context 'and when uploading is successful' do
26
- shared_examples 'uploads a single file' do
27
- it 'uploads a file' do
28
- VCR.use_cassette(cassete) do
29
- upload = subject.upload_file(file)
30
- expect(upload).to be_kind_of(file_type_in_response)
31
- end
32
- end
33
- end
34
-
35
- it_behaves_like 'uploads a single file' do
36
- let(:cassete) { 'upload_upload_one_file_from_cdn' }
37
- let(:file) { ::File.open('spec/fixtures/kitten.jpeg') }
38
- let(:file_type_in_response) { Uploadcare::Entity::File }
39
- end
40
-
41
- it_behaves_like 'uploads a single file' do
42
- let(:cassete) { 'upload_upload_one_file' }
43
- let(:file) { 'https://ucarecdn.com/c3328b8f-1b27-48ca-aebe-591924011efc/thumbnail_0.jpg' }
44
- let(:file_type_in_response) { Array }
45
- end
46
- end
47
-
48
- context 'and when uploading is failed' do
49
- subject { super().upload_file([]) }
50
-
51
- it 'raises an error' do
52
- expect { subject }.to raise_error(TypeError)
53
- end
54
- end
55
- end
56
-
57
- context 'and when uploading a several files' do
58
- let(:file) { ::File.open('spec/fixtures/kitten.jpeg') }
59
-
60
- context 'and when uploading is successful' do
61
- it 'uploads a file' do
62
- VCR.use_cassette('upload_upload_many_files') do
63
- upload = subject.upload_files([file])
64
- expect(upload).to be_kind_of(Array)
65
- end
66
- end
67
- end
68
-
69
- context 'and when uploading is failed' do
70
- subject { super().upload_files(file) }
71
-
72
- it 'raises an error' do
73
- expect { subject }.to raise_error(TypeError)
74
- end
75
- end
76
- end
77
- end
78
- end
79
- end
80
- end
81
- end
82
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/jobs/delete_file_job'
5
-
6
- RSpec.describe Uploadcare::Rails::DeleteFileJob, type: :job do
7
- describe '#perform_later' do
8
- it 'performs a delete file job' do
9
- ActiveJob::Base.queue_adapter = :test
10
- expect do
11
- described_class.perform_later(SecureRandom.uuid)
12
- end.to change(ActiveJob::Base.queue_adapter.enqueued_jobs, :size).by(1)
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/jobs/store_file_job'
5
-
6
- RSpec.describe Uploadcare::Rails::StoreFileJob, type: :job do
7
- describe '#perform_later' do
8
- it 'performs a store file job' do
9
- ActiveJob::Base.queue_adapter = :test
10
- expect do
11
- described_class.perform_later(SecureRandom.uuid)
12
- end.to change(ActiveJob::Base.queue_adapter.enqueued_jobs, :size).by(1)
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/jobs/store_group_job'
5
-
6
- RSpec.describe Uploadcare::Rails::StoreGroupJob, type: :job do
7
- describe '#perform_later' do
8
- it 'performs a store file group job' do
9
- ActiveJob::Base.queue_adapter = :test
10
- expect do
11
- described_class.perform_later('id')
12
- end.to change(ActiveJob::Base.queue_adapter.enqueued_jobs, :size).by(1)
13
- end
14
- end
15
- end
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/objects/file'
5
- require 'rails/all'
6
-
7
- describe Uploadcare::Rails::File do
8
- let(:file) do
9
- described_class.new(
10
- cdn_url: 'https://ucarecdn.com/5ae54c37-754c-4982-8de4-3f242a88ce17/',
11
- uuid: '5ae54c37-754c-4982-8de4-3f242a88ce17'
12
- )
13
- end
14
- let(:cache) { Rails.cache }
15
- let(:config) { OpenStruct.new(cache_files: true) }
16
- let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
17
-
18
- before do
19
- allow(Rails).to receive(:cache).and_return(memory_store)
20
- allow(Uploadcare::Rails).to receive(:configuration).and_return(config)
21
- Rails.cache.clear
22
- end
23
-
24
- context 'when checking file storing' do
25
- it 'stores a file', :aggregate_failures do
26
- VCR.use_cassette 'file_api_store_file' do
27
- response = file.store
28
- expect(response[:uuid]).to eq file.uuid
29
- expect(file.loaded?).to be_truthy
30
- end
31
- end
32
- end
33
-
34
- context 'when checking file deleting' do
35
- it 'deletes a file' do
36
- VCR.use_cassette 'file_api_delete_file' do
37
- response = file.delete
38
- expect(response[:uuid]).to eq file.uuid
39
- end
40
- end
41
- end
42
-
43
- context 'when checking file to_s method' do
44
- it 'check the :to_s method' do
45
- expect(file.to_s).to eq file.cdn_url
46
- end
47
- end
48
-
49
- context 'when checking file loading' do
50
- it 'checks that a file is not loaded by default' do
51
- expect(file.loaded?).to be_falsey
52
- end
53
-
54
- it 'checks that a file is loaded' do
55
- VCR.use_cassette 'file_api_get_file' do
56
- file.load
57
- expect(file.loaded?).to be_truthy
58
- end
59
- end
60
- end
61
-
62
- context 'when checking url transformations' do
63
- subject { file.transform_url(**transformation_args) }
64
-
65
- let(:transformator_class) { Uploadcare::Rails::Transformations::ImageTransformations }
66
- let(:transformation_args) { { resize: '300x500' } }
67
- let(:transformations) { '/resize/300x500/' }
68
- let(:new_url) { "#{file.cdn_url}-#{transformations}" }
69
-
70
- before { allow(transformator_class).to receive_message_chain(:new, :call).and_return(transformations) }
71
-
72
- it 'checks that the transformator received :new method', :aggregate_failures do
73
- expect(transformator_class).to receive(:new).with(transformation_args)
74
- expect(subject).to eq new_url
75
- end
76
- end
77
- end
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/objects/group'
5
- require 'rails/all'
6
-
7
- describe Uploadcare::Rails::Group do
8
- let(:group) do
9
- described_class.new(
10
- cdn_url: 'https://ucarecdn.com/aeaeeb8d-43bc-444d-954f-a171fd872e58~2/',
11
- id: 'aeaeeb8d-43bc-444d-954f-a171fd872e58~2',
12
- files_count: '2'
13
- )
14
- end
15
- let(:cache) { Rails.cache }
16
- let(:config) { OpenStruct.new(cache_files: true) }
17
- let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
18
-
19
- before do
20
- allow(Rails).to receive(:cache).and_return(memory_store)
21
- allow(Uploadcare::Rails).to receive(:configuration).and_return(config)
22
- Rails.cache.clear
23
- end
24
-
25
- context 'when checking group storing' do
26
- it 'stores a group', :aggregate_failures do
27
- VCR.use_cassette 'group_api_store_group' do
28
- response = group.store
29
- expect(response[:id]).to eq group.id
30
- expect(group.loaded?).to be_truthy
31
- end
32
- end
33
- end
34
-
35
- context 'when checking group to_s method' do
36
- it 'returns the cdn_url of a group' do
37
- expect(group.to_s).to eq group.cdn_url
38
- end
39
- end
40
-
41
- context 'when checking group loading' do
42
- let(:group) do
43
- described_class.new(
44
- cdn_url: 'https://ucarecdn.com/8b1362ed-b477-4a15-819a-2c6bb497d8bd~3/',
45
- id: '8b1362ed-b477-4a15-819a-2c6bb497d8bd~3',
46
- files_count: '2'
47
- )
48
- end
49
-
50
- it 'checks that a group is not loaded by default' do
51
- expect(group.loaded?).to be_falsey
52
- end
53
-
54
- it 'checks that a group is loaded' do
55
- VCR.use_cassette 'group_api_get_group' do
56
- group.load
57
- expect(group.loaded?).to be_truthy
58
- end
59
- end
60
- end
61
-
62
- context 'when checking file urls' do
63
- let(:expected_urls) { Array.new(group.files_count.to_i) { |index| "#{group.cdn_url}nth/#{index}/" } }
64
-
65
- it 'returns file urls of a group' do
66
- expect(group.file_urls).to contain_exactly(*expected_urls)
67
- end
68
- end
69
-
70
- context 'when checking file urls transformations' do
71
- subject { group.transform_file_urls(**transformation_args) }
72
-
73
- let(:transformator_class) { Uploadcare::Rails::Transformations::ImageTransformations }
74
- let(:transformation_args) { { resize: '300x500' } }
75
- let(:transformations) { '/resize/300x500/' }
76
- let(:expected_urls) do
77
- Array.new(group.files_count.to_i) { |index| "#{group.cdn_url}nth/#{index}/-#{transformations}" }
78
- end
79
-
80
- before { allow(transformator_class).to receive_message_chain(:new, :call).and_return(transformations) }
81
-
82
- it 'sends a :new method to the transformator_class', :aggregate_failures do
83
- expect(transformator_class).to receive(:new).with(transformation_args)
84
- expect(subject).to contain_exactly(*expected_urls)
85
- end
86
- end
87
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/services/id_extractor'
5
-
6
- describe Uploadcare::Rails::IdExtractor, type: :service do
7
- subject { described_class.call(cdn_url, regex) }
8
-
9
- let(:uuid) { 'a5c4b078-39ec-424d-8a51-1eb15c673e49' }
10
-
11
- context 'when extracting a UUID from a cdn_urls' do
12
- let(:regex) { /\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b/ }
13
-
14
- [
15
- 'https://ucarecdn.com/:uuid/',
16
- "https://ucarecdn.com/:uuid/-/overlay/#{SecureRandom.uuid}/",
17
- "https://ucarecdn.com/:uuid/image-#{SecureRandom.uuid}.jpg"
18
- ].each do |masked_url|
19
- let(:cdn_url) { masked_url.gsub(':uuid', uuid) }
20
-
21
- it "extracts an UUID from the cdn_url - #{masked_url}" do
22
- expect(subject).to eq uuid
23
- end
24
- end
25
- end
26
- end
@@ -1,120 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'uploadcare/rails/transformations/image_transformations'
5
-
6
- describe Uploadcare::Rails::Transformations::ImageTransformations do
7
- subject { described_class.new(**arguments).call }
8
-
9
- let(:arguments) do
10
- {
11
- # Resize and crop
12
- preview: '300x500',
13
- resize: '300x500',
14
- smart_resize: '300x500',
15
- crop: {
16
- dimensions: '300x500',
17
- coords: '2400,700',
18
- alignment: 'center'
19
- },
20
- scale_crop: {
21
- dimensions: '300x500',
22
- offsets: '50%,50%',
23
- smart_mode: 'smart'
24
- },
25
- setfill: 'ece3d2',
26
- # Compression
27
- format: 'png',
28
- quality: 'smart',
29
- progressive: 'yes',
30
- gif2video: true,
31
- # Colors
32
- brightness: '50',
33
- exposure: '50',
34
- gamma: '50',
35
- contrast: '50',
36
- saturation: '50',
37
- vibrance: '50',
38
- warmth: '50',
39
- enhance: '50',
40
- grayscale: true,
41
- invert: true,
42
- filter: {
43
- name: 'adaris',
44
- amount: 50
45
- },
46
- srgb: 'fast',
47
- max_icc_size: 2,
48
- # Blur and sharpen
49
- blur: {
50
- strength: 50,
51
- amount: 90
52
- },
53
- blur_region: {
54
- dimensions: '300x500',
55
- coords: '2400,700',
56
- strength: 50
57
- },
58
- sharp: 50,
59
- # Overlay
60
- overlay: {
61
- uuid: 'self',
62
- relative_dimensions: '50%x50%',
63
- relative_coordinates: 'center',
64
- opacity: '20p'
65
- },
66
- # Rotate and flip
67
- autorotate: 'yes',
68
- rotate: 90,
69
- flip: true,
70
- mirror: true
71
- }
72
- end
73
- let(:expected_string) do
74
- "/preview/#{arguments[:preview]}/-" \
75
- "/resize/#{arguments[:resize]}/-" \
76
- "/smart_resize/#{arguments[:smart_resize]}/-" \
77
- "/crop/#{arguments[:crop].values.join('/')}/-" \
78
- "/scale_crop/#{arguments[:scale_crop].values.join('/')}/-" \
79
- "/setfill/#{arguments[:setfill]}/-" \
80
- "/format/#{arguments[:format]}/-" \
81
- "/quality/#{arguments[:quality]}/-" \
82
- "/progressive/#{arguments[:progressive]}/-" \
83
- '/gif2video/-' \
84
- "/brightness/#{arguments[:brightness]}/-" \
85
- "/exposure/#{arguments[:exposure]}/-" \
86
- "/gamma/#{arguments[:gamma]}/-" \
87
- "/contrast/#{arguments[:contrast]}/-" \
88
- "/saturation/#{arguments[:saturation]}/-" \
89
- "/vibrance/#{arguments[:vibrance]}/-" \
90
- "/warmth/#{arguments[:warmth]}/-" \
91
- "/enhance/#{arguments[:enhance]}/-" \
92
- '/grayscale/-' \
93
- '/invert/-' \
94
- "/filter/#{arguments[:filter].values.join('/')}/-" \
95
- "/srgb/#{arguments[:srgb]}/-" \
96
- "/max_icc_size/#{arguments[:max_icc_size]}/-" \
97
- "/blur/#{arguments[:blur].values.join('/')}/-" \
98
- "/blur_region/#{arguments[:blur_region].values.join('/')}/-" \
99
- "/sharp/#{arguments[:sharp]}/-" \
100
- "/overlay/#{arguments[:overlay].values.join('/')}/-" \
101
- "/autorotate/#{arguments[:autorotate]}/-" \
102
- "/rotate/#{arguments[:rotate]}/-" \
103
- '/flip/-' \
104
- '/mirror/'
105
- end
106
-
107
- it 'builds image transformations params url' do
108
- expect(subject).to eq expected_string
109
- end
110
-
111
- context 'when sending invalid data' do
112
- context 'and when including spaces in params' do
113
- let(:arguments) { { preview: '300x 500' } }
114
-
115
- it 'removes all spaces from the result string' do
116
- expect(subject).not_to match(/\s/)
117
- end
118
- end
119
- end
120
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe Uploadcare::Rails do
4
- it 'has a version number' do
5
- expect(Uploadcare::Rails::VERSION).not_to be nil
6
- end
7
- end