uploadcare-ruby 3.0.3 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +21 -7
- data/README.md +348 -34
- data/lib/uploadcare/client/conversion/base_conversion_client.rb +59 -0
- data/lib/uploadcare/client/conversion/document_conversion_client.rb +41 -0
- data/lib/uploadcare/client/conversion/video_conversion_client.rb +46 -0
- data/lib/uploadcare/client/file_list_client.rb +4 -4
- data/lib/uploadcare/client/group_client.rb +1 -1
- data/lib/uploadcare/client/multipart_upload/chunks_client.rb +16 -5
- data/lib/uploadcare/client/multipart_upload_client.rb +14 -12
- data/lib/uploadcare/client/project_client.rb +1 -1
- data/lib/uploadcare/client/rest_client.rb +6 -5
- data/lib/uploadcare/client/rest_group_client.rb +2 -2
- data/lib/uploadcare/client/upload_client.rb +8 -0
- data/lib/uploadcare/client/uploader_client.rb +25 -17
- data/lib/uploadcare/client/webhook_client.rb +9 -5
- data/lib/uploadcare/concern/error_handler.rb +2 -2
- data/lib/uploadcare/entity/conversion/base_converter.rb +36 -0
- data/lib/uploadcare/entity/conversion/document_converter.rb +15 -0
- data/lib/uploadcare/entity/conversion/video_converter.rb +15 -0
- data/lib/uploadcare/entity/decorator/paginator.rb +5 -7
- data/lib/uploadcare/entity/file.rb +40 -4
- data/lib/uploadcare/entity/file_list.rb +1 -0
- data/lib/uploadcare/entity/group.rb +1 -2
- data/lib/uploadcare/entity/uploader.rb +11 -3
- data/lib/uploadcare/exception/conversion_error.rb +8 -0
- data/lib/uploadcare/exception/throttle_error.rb +2 -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/user_agent.rb +1 -1
- data/lib/uploadcare/ruby/version.rb +1 -1
- data/uploadcare-ruby.gemspec +1 -1
- metadata +14 -5
@@ -18,7 +18,7 @@ module Uploadcare
|
|
18
18
|
# @option options [Boolean] :store (false) whether to store file on servers.
|
19
19
|
def self.upload(object, **options)
|
20
20
|
if big_file?(object)
|
21
|
-
|
21
|
+
multipart_upload(object, **options)
|
22
22
|
elsif file?(object)
|
23
23
|
upload_file(object, **options)
|
24
24
|
elsif object.is_a?(Array)
|
@@ -43,8 +43,8 @@ module Uploadcare
|
|
43
43
|
end
|
44
44
|
|
45
45
|
# upload file of size above 10mb (involves multipart upload)
|
46
|
-
def self.
|
47
|
-
response = MultipartUploaderClient.new.upload(file)
|
46
|
+
def self.multipart_upload(file, **options, &block)
|
47
|
+
response = MultipartUploaderClient.new.upload(file, **options, &block)
|
48
48
|
Uploadcare::Entity::File.new(response.success)
|
49
49
|
end
|
50
50
|
|
@@ -52,9 +52,17 @@ module Uploadcare
|
|
52
52
|
# @param url [String]
|
53
53
|
def self.upload_from_url(url, **options)
|
54
54
|
response = UploaderClient.new.upload_from_url(url, **options)
|
55
|
+
return response.success[:token] unless response.success[:files]
|
56
|
+
|
55
57
|
response.success[:files].map { |file_data| Uploadcare::Entity::File.new(file_data) }
|
56
58
|
end
|
57
59
|
|
60
|
+
# gets a status of upload from url
|
61
|
+
# @param url [String]
|
62
|
+
def self.get_upload_from_url_status(token)
|
63
|
+
UploaderClient.new.get_upload_from_url_status(token)
|
64
|
+
end
|
65
|
+
|
58
66
|
class << self
|
59
67
|
private
|
60
68
|
|
@@ -5,8 +5,10 @@ module Uploadcare
|
|
5
5
|
# Exception for throttled requests
|
6
6
|
class ThrottleError < StandardError
|
7
7
|
attr_reader :timeout
|
8
|
+
|
8
9
|
# @param timeout [Float] Amount of seconds the request have been throttled for
|
9
10
|
def initialize(timeout = 10.0)
|
11
|
+
super
|
10
12
|
@timeout = timeout
|
11
13
|
end
|
12
14
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Uploadcare
|
4
|
+
module Param
|
5
|
+
module Conversion
|
6
|
+
module Document
|
7
|
+
class ProcessingJobUrlBuilder
|
8
|
+
class << self
|
9
|
+
def call(uuid:, format: nil, page: nil)
|
10
|
+
[
|
11
|
+
uuid_part(uuid),
|
12
|
+
format_part(format),
|
13
|
+
page_part(page)
|
14
|
+
].compact.join('-')
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def uuid_part(uuid)
|
20
|
+
"#{uuid}/document/"
|
21
|
+
end
|
22
|
+
|
23
|
+
def format_part(format)
|
24
|
+
return if format.nil?
|
25
|
+
|
26
|
+
"/format/#{format}/"
|
27
|
+
end
|
28
|
+
|
29
|
+
def page_part(page)
|
30
|
+
return if page.nil?
|
31
|
+
|
32
|
+
"/page/#{page}/"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Uploadcare
|
4
|
+
module Param
|
5
|
+
module Conversion
|
6
|
+
module Video
|
7
|
+
class ProcessingJobUrlBuilder
|
8
|
+
class << self
|
9
|
+
# rubocop:disable Metrics/ParameterLists
|
10
|
+
def call(uuid:, size: {}, quality: nil, format: nil, cut: {}, thumbs: {})
|
11
|
+
[
|
12
|
+
uuid_part(uuid),
|
13
|
+
size_part(size),
|
14
|
+
quality_part(quality),
|
15
|
+
format_part(format),
|
16
|
+
cut_part(cut),
|
17
|
+
thumbs_part(thumbs)
|
18
|
+
].compact.join('-')
|
19
|
+
end
|
20
|
+
# rubocop:enable Metrics/ParameterLists
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def uuid_part(uuid)
|
25
|
+
"#{uuid}/video/"
|
26
|
+
end
|
27
|
+
|
28
|
+
def size_part(size)
|
29
|
+
return if size.empty?
|
30
|
+
|
31
|
+
dimensions = "#{size[:width]}x#{size[:height]}" if size[:width] || size[:height]
|
32
|
+
resize_mode = (size[:resize_mode]).to_s
|
33
|
+
"/size/#{dimensions}/#{resize_mode}/".squeeze('/')
|
34
|
+
end
|
35
|
+
|
36
|
+
def quality_part(quality)
|
37
|
+
return if quality.nil?
|
38
|
+
|
39
|
+
"/quality/#{quality}/"
|
40
|
+
end
|
41
|
+
|
42
|
+
def format_part(format)
|
43
|
+
return if format.nil?
|
44
|
+
|
45
|
+
"/format/#{format}/"
|
46
|
+
end
|
47
|
+
|
48
|
+
def cut_part(cut)
|
49
|
+
return if cut.empty?
|
50
|
+
|
51
|
+
"/cut/#{cut[:start_time]}/#{cut[:length]}/"
|
52
|
+
end
|
53
|
+
|
54
|
+
def thumbs_part(thumbs)
|
55
|
+
return if thumbs.empty?
|
56
|
+
|
57
|
+
"/thumbs~#{thumbs[:N]}/#{thumbs[:number]}/".squeeze('/')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -12,7 +12,7 @@ module Uploadcare
|
|
12
12
|
# UploadcareRuby/3.0.0-dev/Pubkey_(Ruby/2.6.3;UploadcareRuby)
|
13
13
|
def self.call
|
14
14
|
framework_data = Uploadcare.config.framework_data || ''
|
15
|
-
framework_data_string =
|
15
|
+
framework_data_string = "; #{Uploadcare.config.framework_data}" unless framework_data.empty?
|
16
16
|
public_key = Uploadcare.config.public_key
|
17
17
|
"UploadcareRuby/#{VERSION}/#{public_key} (Ruby/#{RUBY_VERSION}#{framework_data_string})"
|
18
18
|
end
|
data/uploadcare-ruby.gemspec
CHANGED
@@ -38,7 +38,7 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.require_paths = ['lib', 'lib/uploadcare', 'lib/uploadcare/rest']
|
39
39
|
|
40
40
|
spec.add_dependency 'api_struct', '~> 1.0.1'
|
41
|
-
spec.add_dependency 'dry-configurable', '~> 0.9
|
41
|
+
spec.add_dependency 'dry-configurable', '~> 0.9'
|
42
42
|
spec.add_dependency 'parallel'
|
43
43
|
spec.add_dependency 'retries'
|
44
44
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uploadcare-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stepan Redka
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: api_struct
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.9
|
33
|
+
version: '0.9'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.9
|
40
|
+
version: '0.9'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: parallel
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -173,6 +173,9 @@ files:
|
|
173
173
|
- bin/setup
|
174
174
|
- lib/uploadcare.rb
|
175
175
|
- lib/uploadcare/api/api.rb
|
176
|
+
- lib/uploadcare/client/conversion/base_conversion_client.rb
|
177
|
+
- lib/uploadcare/client/conversion/document_conversion_client.rb
|
178
|
+
- lib/uploadcare/client/conversion/video_conversion_client.rb
|
176
179
|
- lib/uploadcare/client/file_client.rb
|
177
180
|
- lib/uploadcare/client/file_list_client.rb
|
178
181
|
- lib/uploadcare/client/group_client.rb
|
@@ -187,6 +190,9 @@ files:
|
|
187
190
|
- lib/uploadcare/concern/error_handler.rb
|
188
191
|
- lib/uploadcare/concern/throttle_handler.rb
|
189
192
|
- lib/uploadcare/concern/upload_error_handler.rb
|
193
|
+
- lib/uploadcare/entity/conversion/base_converter.rb
|
194
|
+
- lib/uploadcare/entity/conversion/document_converter.rb
|
195
|
+
- lib/uploadcare/entity/conversion/video_converter.rb
|
190
196
|
- lib/uploadcare/entity/decorator/paginator.rb
|
191
197
|
- lib/uploadcare/entity/entity.rb
|
192
198
|
- lib/uploadcare/entity/file.rb
|
@@ -196,9 +202,12 @@ files:
|
|
196
202
|
- lib/uploadcare/entity/project.rb
|
197
203
|
- lib/uploadcare/entity/uploader.rb
|
198
204
|
- lib/uploadcare/entity/webhook.rb
|
205
|
+
- lib/uploadcare/exception/conversion_error.rb
|
199
206
|
- lib/uploadcare/exception/request_error.rb
|
200
207
|
- lib/uploadcare/exception/throttle_error.rb
|
201
208
|
- lib/uploadcare/param/authentication_header.rb
|
209
|
+
- lib/uploadcare/param/conversion/document/processing_job_url_builder.rb
|
210
|
+
- lib/uploadcare/param/conversion/video/processing_job_url_builder.rb
|
202
211
|
- lib/uploadcare/param/param.rb
|
203
212
|
- lib/uploadcare/param/secure_auth_header.rb
|
204
213
|
- lib/uploadcare/param/simple_auth_header.rb
|
@@ -232,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
232
241
|
- !ruby/object:Gem::Version
|
233
242
|
version: '0'
|
234
243
|
requirements: []
|
235
|
-
rubygems_version: 3.
|
244
|
+
rubygems_version: 3.2.22
|
236
245
|
signing_key:
|
237
246
|
specification_version: 4
|
238
247
|
summary: Ruby wrapper for uploadcare API
|