uploadcare-ruby 2.1.2 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  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 +33 -0
  7. data/.yardopts +4 -0
  8. data/CHANGELOG.md +29 -47
  9. data/DEVELOPMENT.md +18 -0
  10. data/Gemfile +2 -0
  11. data/LICENSE +1 -1
  12. data/README.md +433 -527
  13. data/Rakefile +5 -5
  14. data/bin/console +15 -0
  15. data/bin/setup +8 -0
  16. data/lib/uploadcare/api/api.rb +25 -0
  17. data/lib/uploadcare/client/conversion/base_conversion_client.rb +59 -0
  18. data/lib/uploadcare/client/conversion/document_conversion_client.rb +41 -0
  19. data/lib/uploadcare/client/conversion/video_conversion_client.rb +46 -0
  20. data/lib/uploadcare/client/file_client.rb +44 -0
  21. data/lib/uploadcare/client/file_list_client.rb +46 -0
  22. data/lib/uploadcare/client/group_client.rb +45 -0
  23. data/lib/uploadcare/client/multipart_upload/chunks_client.rb +57 -0
  24. data/lib/uploadcare/client/multipart_upload_client.rb +64 -0
  25. data/lib/uploadcare/client/project_client.rb +18 -0
  26. data/lib/uploadcare/client/rest_client.rb +74 -0
  27. data/lib/uploadcare/client/rest_group_client.rb +23 -0
  28. data/lib/uploadcare/client/upload_client.rb +43 -0
  29. data/lib/uploadcare/client/uploader_client.rb +101 -0
  30. data/lib/uploadcare/client/webhook_client.rb +47 -0
  31. data/lib/uploadcare/concern/error_handler.rb +54 -0
  32. data/lib/uploadcare/concern/throttle_handler.rb +25 -0
  33. data/lib/uploadcare/concern/upload_error_handler.rb +32 -0
  34. data/lib/uploadcare/entity/conversion/base_converter.rb +36 -0
  35. data/lib/uploadcare/entity/conversion/document_converter.rb +15 -0
  36. data/lib/uploadcare/entity/conversion/video_converter.rb +15 -0
  37. data/lib/uploadcare/entity/decorator/paginator.rb +79 -0
  38. data/lib/uploadcare/entity/entity.rb +18 -0
  39. data/lib/uploadcare/entity/file.rb +106 -0
  40. data/lib/uploadcare/entity/file_list.rb +31 -0
  41. data/lib/uploadcare/entity/group.rb +40 -0
  42. data/lib/uploadcare/entity/group_list.rb +24 -0
  43. data/lib/uploadcare/entity/project.rb +13 -0
  44. data/lib/uploadcare/entity/uploader.rb +81 -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/lib/uploadcare.rb +36 -32
  60. data/uploadcare-ruby.gemspec +50 -37
  61. metadata +107 -113
  62. data/.travis.yml +0 -26
  63. data/UPGRADE_NOTES.md +0 -36
  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/upload_params.rb +0 -72
  72. data/lib/uploadcare/api/uploading_api.rb +0 -71
  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/api.rb +0 -26
  76. data/lib/uploadcare/errors/errors.rb +0 -64
  77. data/lib/uploadcare/resources/file.rb +0 -164
  78. data/lib/uploadcare/resources/file_list.rb +0 -14
  79. data/lib/uploadcare/resources/group.rb +0 -115
  80. data/lib/uploadcare/resources/group_list.rb +0 -14
  81. data/lib/uploadcare/resources/project.rb +0 -13
  82. data/lib/uploadcare/resources/resource_list.rb +0 -83
  83. data/lib/uploadcare/rest/auth/auth.rb +0 -31
  84. data/lib/uploadcare/rest/auth/secure.rb +0 -43
  85. data/lib/uploadcare/rest/auth/simple.rb +0 -16
  86. data/lib/uploadcare/rest/connections/api_connection.rb +0 -53
  87. data/lib/uploadcare/rest/connections/upload_connection.rb +0 -22
  88. data/lib/uploadcare/rest/middlewares/auth_middleware.rb +0 -24
  89. data/lib/uploadcare/rest/middlewares/parse_json_middleware.rb +0 -33
  90. data/lib/uploadcare/rest/middlewares/raise_error_middleware.rb +0 -21
  91. data/lib/uploadcare/utils/parser.rb +0 -71
  92. data/lib/uploadcare/utils/user_agent.rb +0 -44
  93. data/lib/uploadcare/version.rb +0 -3
  94. data/spec/api/file_list_api_spec.rb +0 -95
  95. data/spec/api/file_storage_api_spec.rb +0 -88
  96. data/spec/api/group_list_api_spec.rb +0 -59
  97. data/spec/api/raw_api_spec.rb +0 -25
  98. data/spec/api/uploading_api/upload_params_spec.rb +0 -99
  99. data/spec/api/uploading_api_spec.rb +0 -59
  100. data/spec/resources/file_list_spec.rb +0 -25
  101. data/spec/resources/file_spec.rb +0 -223
  102. data/spec/resources/group_list_spec.rb +0 -25
  103. data/spec/resources/group_spec.rb +0 -101
  104. data/spec/resources/operations_spec.rb +0 -59
  105. data/spec/resources/project_spec.rb +0 -21
  106. data/spec/rest/api_connection_spec.rb +0 -68
  107. data/spec/rest/auth/secure_spec.rb +0 -66
  108. data/spec/rest/auth/simple_spec.rb +0 -31
  109. data/spec/rest/errors_spec.rb +0 -75
  110. data/spec/rest/upload_connection_spec.rb +0 -19
  111. data/spec/shared/resource_list.rb +0 -188
  112. data/spec/spec_helper.rb +0 -54
  113. data/spec/uploadcare_spec.rb +0 -43
  114. data/spec/utils/parser_spec.rb +0 -85
  115. data/spec/utils/user_agent_spec.rb +0 -46
  116. data/spec/view.png +0 -0
  117. data/spec/view2.jpg +0 -0
@@ -1,31 +0,0 @@
1
- module Uploadcare
2
- module Connections
3
- module Auth
4
-
5
- def self.strategy(options)
6
- auth_scheme = options.fetch(:auth_scheme)
7
-
8
- unless [:simple, :secure].include?(auth_scheme)
9
- raise ArgumentError, "Unknown auth_scheme: '#{auth_scheme}'"
10
- end
11
-
12
- klass = const_get(auth_scheme.capitalize)
13
- klass.new(options)
14
- end
15
-
16
- class Base
17
- attr_reader :public_key, :private_key
18
-
19
- def initialize(options)
20
- @public_key = options.fetch(:public_key)
21
- @private_key = options.fetch(:private_key)
22
- end
23
-
24
- def apply(env)
25
- raise NotImplementedError
26
- end
27
- end
28
-
29
- end
30
- end
31
- end
@@ -1,43 +0,0 @@
1
- require 'time'
2
-
3
- module Uploadcare
4
- module Connections
5
- module Auth
6
- class Secure < Base
7
-
8
- def apply(env)
9
- date = Time.now.utc
10
- headers(env, date).each{|k, v| env.request_headers[k] = v}
11
- env
12
- end
13
-
14
- private
15
-
16
- def headers(env, date)
17
- {
18
- "Date" => date.rfc2822,
19
- "Authorization" => "Uploadcare #{public_key}:#{signature(env, date)}"
20
- }
21
- end
22
-
23
- def signature(env, date)
24
- sign_string = sign_string(env, date)
25
- digest = OpenSSL::Digest.new('sha1')
26
-
27
- OpenSSL::HMAC.hexdigest(digest, private_key, sign_string)
28
- end
29
-
30
- def sign_string(env, date)
31
- verb = env.method.upcase.to_s
32
- uri = env.url.request_uri
33
- date_header = date.rfc2822
34
- content_type = env.request_headers['Content-Type']
35
- content_md5 = OpenSSL::Digest.new('md5').hexdigest(env.body || "")
36
-
37
- [verb, content_md5, content_type, date_header, uri].join("\n")
38
- end
39
-
40
- end
41
- end
42
- end
43
- end
@@ -1,16 +0,0 @@
1
- module Uploadcare
2
- module Connections
3
- module Auth
4
- class Simple < Base
5
-
6
- def apply(env)
7
- auth_string = "Uploadcare.Simple #{public_key}:#{private_key}"
8
- env.request_headers['Authorization'] = auth_string
9
-
10
- env
11
- end
12
-
13
- end
14
- end
15
- end
16
- end
@@ -1,53 +0,0 @@
1
- require 'faraday'
2
- require "faraday_middleware"
3
-
4
- module Uploadcare
5
- module Connections
6
- class ApiConnection < Faraday::Connection
7
-
8
- def initialize options
9
- super options[:api_url_base] do |frd|
10
- auth_strategy = Auth.strategy(options)
11
-
12
- frd.headers['Accept'] = "application/vnd.uploadcare-v#{options[:api_version]}+json"
13
- frd.headers['User-Agent'] = UserAgent.new.call(options)
14
-
15
- # order of middleware matters!
16
-
17
- # :json middleware changes request body and thus should be before
18
- # uploadcare_auth which uses it to sign requests when secure auth
19
- # strategy is being used
20
- frd.request :json
21
- frd.request :uploadcare_auth, auth_strategy
22
-
23
- frd.response :uploadcare_raise_error
24
- frd.response :follow_redirects, limit: 3, callback: lambda{|old, env| auth_strategy.apply(env) }
25
- frd.response :uploadcare_parse_json
26
-
27
- frd.adapter :net_http # actually, default adapter, just to be clear
28
- end
29
- end
30
-
31
- # NOTE: Faraday doesn't support body in DELETE requests, but
32
- # Uploadcare API v0.5 requires clients to send array of UUIDs with
33
- # `DELETE /files/storage/` requests.
34
- #
35
- # This is on override of the original Faraday::Connection#delete method.
36
- #
37
- # As for now, there are no DELETE requests in Uploadcare REST API
38
- # which require params to be sent as URI params, so for simplicity
39
- # this method send all params in a body.
40
- def delete(url = nil, params = nil, headers = nil)
41
- run_request(:delete, url, nil, headers) { |request|
42
- # Original line from Faraday::Connection#delete method
43
- # request.params.update(params) if params
44
-
45
- # Monkey patch
46
- request.body = params if params
47
-
48
- yield(request) if block_given?
49
- }
50
- end
51
- end
52
- end
53
- end
@@ -1,22 +0,0 @@
1
- require "faraday"
2
-
3
- module Uploadcare
4
- module Connections
5
- class UploadConnection < Faraday::Connection
6
- def initialize options
7
- ca_path = '/etc/ssl/certs' if File.exists?('/etc/ssl/certs')
8
-
9
- super ssl: { ca_path: ca_path }, url: options[:upload_url_base] do |frd|
10
- frd.request :multipart
11
- frd.request :url_encoded
12
- frd.headers['User-Agent'] = UserAgent.new.call(options)
13
-
14
- frd.response :uploadcare_raise_error
15
- frd.response :uploadcare_parse_json
16
-
17
- frd.adapter :net_http
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,24 +0,0 @@
1
- require 'faraday'
2
-
3
- module Uploadcare
4
- module Connections
5
- module Request
6
- class Auth < Faraday::Middleware
7
- attr_reader :auth_strategy
8
-
9
- def initialize(app=nil, auth_strategy)
10
- @auth_strategy = auth_strategy
11
- super(app)
12
- end
13
-
14
- def call(env)
15
- auth_strategy.apply(env)
16
- @app.call(env)
17
- end
18
-
19
- end
20
- end
21
- end
22
- end
23
-
24
- Faraday::Request.register_middleware uploadcare_auth: Uploadcare::Connections::Request::Auth
@@ -1,33 +0,0 @@
1
- require 'faraday'
2
- require 'json'
3
-
4
- module Uploadcare
5
- module Connections
6
- module Response
7
- class ParseJson < Faraday::Response::Middleware
8
- WHITESPACE_REGEX = /\A^\s*$\z/
9
-
10
- ERROR_CODES = [400, 401, 403, 404, 406, 408, 422, 429, 500, 502, 503, 504]
11
-
12
- def parse(body)
13
- case body
14
- when WHITESPACE_REGEX, nil
15
- nil
16
- else
17
- JSON.parse(body)
18
- end
19
- end
20
-
21
- def on_complete(response)
22
- response[:body] = parse(response[:body]) if respond_to?(:parse) && !ERROR_CODES.include?(response[:status])
23
- end
24
-
25
- def unparsable_status_codes
26
- [204, 301, 302, 304]
27
- end
28
- end
29
- end
30
- end
31
- end
32
-
33
- Faraday::Response.register_middleware :uploadcare_parse_json => Uploadcare::Connections::Response::ParseJson
@@ -1,21 +0,0 @@
1
- require 'faraday'
2
-
3
- module Uploadcare
4
- module Connections
5
- module Response
6
- class RaiseError < Faraday::Response::Middleware
7
- def on_complete(response)
8
- @error_codes = Uploadcare::Error.errors.keys
9
- @status = response[:status]
10
-
11
- if @error_codes.include?(@status)
12
- error = Uploadcare::Error.errors[@status].new
13
- fail(error)
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
20
-
21
- Faraday::Response.register_middleware :uploadcare_raise_error => Uploadcare::Connections::Response::RaiseError
@@ -1,71 +0,0 @@
1
- require 'ostruct'
2
-
3
- module Uploadcare
4
- module Parser
5
-
6
- META_URL = /
7
- (?<uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12} # base uuid
8
- ~?(?<count>\d+)?) # optional count
9
- (?:\/-\/(?<operations>.*?))?\/?$ # optional operations
10
- /ix
11
-
12
- def self.parse_file_string string
13
- result = Uploadcare::Parser.parse(string)
14
-
15
- unless result.is_a?(Uploadcare::Parser::File)
16
- msg = "invalid CDN URL or UUID was given for file: #{uuid_or_cdn_url}."
17
- if result.is_a?(Uploadcare::Parser::Group)
18
- msg = msg + "\n Group UUID was given. Try call @api.group if it is what you intended."
19
- end
20
- raise msg
21
- end
22
-
23
- result
24
- end
25
-
26
-
27
- def self.parse_group_string string
28
- result = Uploadcare::Parser.parse(string)
29
-
30
- unless result.is_a?(Uploadcare::Parser::Group)
31
- msg = "invalid CDN URL or UUID was given for group: #{uuid_or_cdn_url}."
32
- if result.is_a?(Uploadcare::Parser::File)
33
- msg = msg + "\n File UUID was given. Try call @api.file if it is what you intended."
34
- end
35
- raise msg
36
- end
37
-
38
- result
39
- end
40
-
41
- def self.parse string
42
- matched = META_URL.match(string)
43
-
44
- # just a simple hash - easy to pass next
45
- captured = Hash[ matched.names.zip( matched.captures ) ]
46
-
47
- # raise an error if no uuid was given in the sting
48
- raise "Invalid UUID or url was given" if captured["uuid"].nil?
49
-
50
- # operations sring to array of operations
51
- if captured["operations"]
52
- captured["operations"] = captured["operations"].split("/-/")
53
- else
54
- captured["operations"] = []
55
- end
56
-
57
- # if count was given - it is a group
58
- if captured["count"]
59
- obj = Group.new captured
60
- else
61
- obj = File.new captured
62
- end
63
- end
64
-
65
- class File < OpenStruct
66
- end
67
-
68
- class Group < OpenStruct
69
- end
70
- end
71
- end
@@ -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,3 +0,0 @@
1
- module Uploadcare
2
- VERSION = '2.1.2'.freeze
3
- end
@@ -1,95 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Uploadcare::FileListApi do
4
- let(:api){ API }
5
- subject{ api.file_list(limit: 1) }
6
-
7
- before(:each){ allow(api).to receive(:get){ {'results' => []} } }
8
-
9
- it 'returns a file list' do
10
- expect( subject ).to be_a(Uploadcare::Api::FileList)
11
- end
12
-
13
- it 'stores options in a file 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.file_list }.not_to raise_error
20
- end
21
-
22
- it "validates that options don't have unsupported keys" do
23
- expect{ api.file_list(unknown: 1) }.to raise_error(ArgumentError)
24
- end
25
-
26
- it 'validates that :limit is an integer from 1 to 1000' do
27
- expect{ api.file_list(limit: 1) }.not_to raise_error
28
- expect{ api.file_list(limit: 395) }.not_to raise_error
29
- expect{ api.file_list(limit: 1000) }.not_to raise_error
30
-
31
- expect{ api.file_list(limit: 1.0) }.to raise_error(ArgumentError)
32
- expect{ api.file_list(limit: -1) }.to raise_error(ArgumentError)
33
- expect{ api.file_list(limit: 0) }.to raise_error(ArgumentError)
34
- expect{ api.file_list(limit: 1001) }.to raise_error(ArgumentError)
35
- expect{ api.file_list(limit: false) }.to raise_error(ArgumentError)
36
- end
37
-
38
- it 'validates that :stored is a boolean' do
39
- expect{ api.file_list(stored: true) }.not_to raise_error
40
- expect{ api.file_list(stored: false) }.not_to raise_error
41
-
42
- expect{ api.file_list(stored: 'yes') }.to raise_error(ArgumentError)
43
- end
44
-
45
- it 'validates that :removed is a boolean' do
46
- expect{ api.file_list(removed: true) }.not_to raise_error
47
- expect{ api.file_list(removed: false) }.not_to raise_error
48
-
49
- expect{ api.file_list(removed: 'yes') }.to raise_error(ArgumentError)
50
- end
51
-
52
- valid_ordering = %w{size -size datetime_uploaded -datetime_uploaded}
53
- it "validates that :ordering is in [#{valid_ordering.join(', ')}]" do
54
- valid_ordering.each do |valid_value|
55
- expect{ api.file_list(ordering: valid_value) }.not_to raise_error
56
- end
57
-
58
- expect{ api.file_list(ordering: 'yes') }.to raise_error(ArgumentError)
59
- end
60
-
61
- describe 'from' do
62
- context 'when ordering is "size" or "-size"' do
63
- let(:opts){ {ordering: ['size', '-size'].sample} }
64
-
65
- it 'validates that :from is a non-negative integer' do
66
- valid = [0, 100500]
67
- valid.each do |value|
68
- expect{ api.file_list(opts.merge(from: value)) }.not_to raise_error
69
- end
70
-
71
- invalid = [-1, 200.0, "string", false]
72
- invalid.each do |value|
73
- expect{ api.file_list(opts.merge(from: value)) }.to raise_error(ArgumentError)
74
- end
75
- end
76
- end
77
-
78
- context 'when ordering is "datetime_uploaded", "-datetime_uploaded" or nil' do
79
- let(:opts){ {ordering: ['datetime_uploaded', '-datetime_uploaded', nil].sample} }
80
-
81
- it 'validates that :from.to_s is a iso8601 string' do
82
- valid = [DateTime.now, DateTime.now.iso8601, "2017-01-01T15"]
83
- valid.each do |value|
84
- expect{ api.file_list(opts.merge(from: value)) }.not_to raise_error
85
- end
86
-
87
- invalid = [Date.today, Time.now, DateTime.now.rfc2822, "2017-01-01", 123, false]
88
- invalid.each do |value|
89
- expect{ api.file_list(opts.merge(from: value)) }.to raise_error(ArgumentError)
90
- end
91
- end
92
- end
93
- end
94
- end
95
- end
@@ -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