uploadcare-ruby 3.0.5 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +13 -0
  3. data/CHANGELOG.md +25 -9
  4. data/README.md +401 -39
  5. data/lib/uploadcare/client/conversion/base_conversion_client.rb +59 -0
  6. data/lib/uploadcare/client/conversion/document_conversion_client.rb +41 -0
  7. data/lib/uploadcare/client/conversion/video_conversion_client.rb +46 -0
  8. data/lib/uploadcare/client/file_list_client.rb +4 -4
  9. data/lib/uploadcare/client/group_client.rb +1 -1
  10. data/lib/uploadcare/client/multipart_upload/chunks_client.rb +16 -5
  11. data/lib/uploadcare/client/multipart_upload_client.rb +14 -12
  12. data/lib/uploadcare/client/project_client.rb +3 -1
  13. data/lib/uploadcare/client/rest_client.rb +6 -5
  14. data/lib/uploadcare/client/rest_group_client.rb +2 -2
  15. data/lib/uploadcare/client/upload_client.rb +8 -0
  16. data/lib/uploadcare/client/uploader_client.rb +25 -17
  17. data/lib/uploadcare/client/webhook_client.rb +11 -5
  18. data/lib/uploadcare/concern/error_handler.rb +2 -2
  19. data/lib/uploadcare/entity/conversion/base_converter.rb +36 -0
  20. data/lib/uploadcare/entity/conversion/document_converter.rb +15 -0
  21. data/lib/uploadcare/entity/conversion/video_converter.rb +15 -0
  22. data/lib/uploadcare/entity/decorator/paginator.rb +5 -7
  23. data/lib/uploadcare/entity/file.rb +40 -4
  24. data/lib/uploadcare/entity/file_list.rb +1 -0
  25. data/lib/uploadcare/entity/group.rb +1 -2
  26. data/lib/uploadcare/entity/uploader.rb +11 -3
  27. data/lib/uploadcare/exception/conversion_error.rb +8 -0
  28. data/lib/uploadcare/exception/throttle_error.rb +2 -0
  29. data/lib/uploadcare/param/conversion/document/processing_job_url_builder.rb +39 -0
  30. data/lib/uploadcare/param/conversion/video/processing_job_url_builder.rb +64 -0
  31. data/lib/uploadcare/param/user_agent.rb +1 -1
  32. data/lib/uploadcare/param/webhook_signature_verifier.rb +23 -0
  33. data/lib/uploadcare/ruby/version.rb +1 -1
  34. data/lib/uploadcare.rb +3 -0
  35. data/uploadcare-ruby.gemspec +1 -1
  36. metadata +14 -4
@@ -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
- upload_big_file(object, **options)
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.upload_big_file(file, **_options)
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
 
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Uploadcare
4
+ module Exception
5
+ # Standard error for invalid API conversion responses
6
+ class ConversionError < StandardError; end
7
+ end
8
+ end
@@ -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 = '; ' + Uploadcare.config.framework_data unless framework_data.empty?
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
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest/md5'
4
+
5
+ module Uploadcare
6
+ module Param
7
+ # This object verifies a signature received along with webhook headers
8
+ class WebhookSignatureVerifier
9
+ # @see https://uploadcare.com/docs/security/secure-webhooks/
10
+ def self.valid?(options = {})
11
+ webhook_body_json = options[:webhook_body]
12
+ signing_secret = options[:signing_secret] || ENV['UC_SIGNING_SECRET']
13
+ x_uc_signature_header = options[:x_uc_signature_header]
14
+
15
+ digest = OpenSSL::Digest.new('sha256')
16
+
17
+ calculated_signature = "v1=#{OpenSSL::HMAC.hexdigest(digest, signing_secret, webhook_body_json)}"
18
+
19
+ calculated_signature == x_uc_signature_header
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uploadcare
4
- VERSION = '3.0.5'
4
+ VERSION = '3.2.0'
5
5
  end
data/lib/uploadcare.rb CHANGED
@@ -17,6 +17,9 @@ require 'entity/project'
17
17
  require 'entity/uploader'
18
18
  require 'entity/webhook'
19
19
 
20
+ # Param
21
+ require 'param/webhook_signature_verifier'
22
+
20
23
  # General api
21
24
  require 'api/api'
22
25
 
@@ -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.0'
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.0.5
4
+ version: 3.2.0
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-04-15 00:00:00.000000000 Z
11
+ date: 2021-11-25 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.0
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.0
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,15 +202,19 @@ 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
205
214
  - lib/uploadcare/param/upload/signature_generator.rb
206
215
  - lib/uploadcare/param/upload/upload_params_generator.rb
207
216
  - lib/uploadcare/param/user_agent.rb
217
+ - lib/uploadcare/param/webhook_signature_verifier.rb
208
218
  - lib/uploadcare/ruby/version.rb
209
219
  - uploadcare-ruby.gemspec
210
220
  homepage: https://github.com/uploadcare/uploadcare-ruby