uploadcare-ruby 1.2.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -1
  3. data/.rspec +1 -0
  4. data/.travis.yml +19 -5
  5. data/CHANGELOG.md +12 -30
  6. data/README.md +149 -72
  7. data/Rakefile +1 -1
  8. data/UPGRADE_NOTES.md +36 -0
  9. data/lib/uploadcare.rb +16 -22
  10. data/lib/uploadcare/api.rb +3 -1
  11. data/lib/uploadcare/api/file_list_api.rb +15 -4
  12. data/lib/uploadcare/api/file_storage_api.rb +34 -0
  13. data/lib/uploadcare/api/group_list_api.rb +13 -4
  14. data/lib/uploadcare/api/raw_api.rb +10 -16
  15. data/lib/uploadcare/api/uploading_api.rb +45 -84
  16. data/lib/uploadcare/api/uploading_api/upload_params.rb +72 -0
  17. data/lib/uploadcare/api/validators/file_list_options_validator.rb +73 -0
  18. data/lib/uploadcare/api/validators/group_list_options_validator.rb +49 -0
  19. data/lib/uploadcare/resources/file_list.rb +6 -33
  20. data/lib/uploadcare/resources/group_list.rb +6 -23
  21. data/lib/uploadcare/resources/resource_list.rb +83 -0
  22. data/lib/uploadcare/rest/connections/api_connection.rb +25 -3
  23. data/lib/uploadcare/rest/connections/upload_connection.rb +3 -2
  24. data/lib/uploadcare/version.rb +1 -1
  25. data/spec/api/file_list_api_spec.rb +95 -0
  26. data/spec/api/file_storage_api_spec.rb +88 -0
  27. data/spec/api/group_list_api_spec.rb +59 -0
  28. data/spec/api/raw_api_spec.rb +12 -12
  29. data/spec/api/uploading_api/upload_params_spec.rb +99 -0
  30. data/spec/api/uploading_api_spec.rb +59 -0
  31. data/spec/resources/file_list_spec.rb +13 -52
  32. data/spec/resources/file_spec.rb +6 -3
  33. data/spec/resources/group_list_spec.rb +15 -20
  34. data/spec/rest/api_connection_spec.rb +1 -1
  35. data/spec/shared/resource_list.rb +188 -0
  36. data/spec/spec_helper.rb +11 -1
  37. data/spec/uploadcare_spec.rb +9 -32
  38. data/spec/utils/parser_spec.rb +34 -36
  39. data/uploadcare-ruby.gemspec +7 -6
  40. metadata +52 -37
  41. data/lib/uploadcare/utils/user_agent.rb +0 -44
  42. data/spec/uploading/uploading_multiple_spec.rb +0 -43
  43. data/spec/uploading/uploading_spec.rb +0 -40
  44. data/spec/utils/user_agent_spec.rb +0 -46
@@ -1,44 +0,0 @@
1
- module Uploadcare
2
- # Determines User-Agent string either taking it from settings or building
3
- # in accordance with common Uploadcare format
4
- #
5
- class UserAgent
6
- # @param options [Hash]
7
- # @option options [String] :user_agent (nil)
8
- # @option options [String] :public_key (nil)
9
- # @option options [String] :user_agent_environment (nil)
10
- # @return [String]
11
- #
12
- def call(options)
13
- return options[:user_agent].to_s if options[:user_agent]
14
-
15
- user_agent_string(
16
- options.fetch(:public_key, nil),
17
- options.fetch(:user_agent_environment, {})
18
- )
19
- end
20
-
21
- private
22
-
23
- def user_agent_string(public_key, extensions)
24
- format(
25
- '%<library>s/%<pubkey>s (%<environment>s)',
26
- library: versioned('UploadcareRuby', Uploadcare::VERSION),
27
- pubkey: public_key,
28
- environment: environment_string(extensions)
29
- )
30
- end
31
-
32
- def environment_string(extensions)
33
- [
34
- versioned('Ruby', Gem.ruby_version),
35
- versioned(extensions[:framework_name], extensions[:framework_version]),
36
- versioned(extensions[:extension_name], extensions[:extension_version])
37
- ].compact.join('; ')
38
- end
39
-
40
- def versioned(name, version = nil)
41
- name ? [name, version].compact.join('/') : nil
42
- end
43
- end
44
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
- require 'uri'
3
- require 'socket'
4
-
5
- describe Uploadcare::Api do
6
- before :all do
7
- @api = API
8
- @files_ary = FILES_ARY
9
- end
10
-
11
- it "it should upload multiple files" do
12
- expect {files = @api.upload @files_ary}.to_not raise_error
13
- end
14
-
15
- it "should retunrn an array of files" do
16
- files = @api.upload @files_ary
17
- files.should be_kind_of(Array)
18
- end
19
-
20
- it "each in array should be UC file object" do
21
- files = @api.upload @files_ary
22
- files.each do |f|
23
- f.should be_kind_of(Uploadcare::Api::File)
24
- end
25
- end
26
-
27
- it "each in array should have valid UUID" do
28
- files = @api.upload @files_ary
29
- files.each do |f|
30
- f.should respond_to(:uuid)
31
- f.uuid.should match(UUID_REGEX)
32
- end
33
- end
34
-
35
- it "each in array should load data for uploaded file" do
36
- files = @api.upload @files_ary
37
- files.each do |f|
38
- f.should respond_to(:load_data)
39
- expect {f.load_data}.to_not raise_error
40
- end
41
- end
42
- end
43
-
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
- require 'uri'
3
- require 'socket'
4
-
5
- describe Uploadcare::Api do
6
- before :all do
7
- @api = API
8
- @file = FILE1
9
- @url = IMAGE_URL
10
- end
11
-
12
- it 'should upload file or url' do
13
- file = @api.upload @file
14
- file.should be_an_instance_of Uploadcare::Api::File
15
- end
16
-
17
- it 'should raise an error when neither file nor url given' do
18
- expect { @api.upload 12 }.to raise_error
19
- end
20
-
21
- it 'should upload file' do
22
- file = @api.upload @file
23
- file.should be_an_instance_of Uploadcare::Api::File
24
- end
25
-
26
- it 'should upload from url' do
27
- file = @api.upload @url
28
- file.should be_an_instance_of Uploadcare::Api::File
29
- end
30
-
31
- it 'should not upload from invalid url' do
32
- expect { @api.upload 'not.url.' }.to raise_error
33
- end
34
-
35
- it 'uploaded file should have valid UUID' do
36
- file = @api.upload @url
37
- file.should be_an_instance_of Uploadcare::Api::File
38
- file.uuid.should match UUID_REGEX
39
- end
40
- 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