uploadcare-ruby 4.3.6 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 274b1a99804055c03bbd9642e79b3ae718ad95711a3a0066a95199929c6d42ea
4
- data.tar.gz: 15240af810033c45a69c96dfde93b949654d55fbf370bb3b046122d17a6b0dd1
3
+ metadata.gz: 35dc34779d62684051b582e460d75f4e58acaa5f2c7372869b9fa753eea117e6
4
+ data.tar.gz: ac06dcf3b4921a8199849111bbd38d1ae7cfad4ad1f5d0adb43a06c885102045
5
5
  SHA512:
6
- metadata.gz: '0487759949cdbbf23e9b5d61b6e49bd005a6e895d42a37ddd2c24852537a594ae740c14c073079a22c19674c184fb50f55f5e1b2234e4e3f90b54f5fc5ae46a8'
7
- data.tar.gz: fbd9198af4353d674df9795294c38cd486dab631b1de3824f5b02368d081fc199ba981092b6f074d06752d99f9b1574737005d0087b4c956ddd86af1562f8f87
6
+ metadata.gz: f189a6b962f27441c40f40f56db9fda78aa492e8d1ad1703663b85a6f6eb7df35f23fdab89c475ecbaec5701c0fc838d8d80f68ca7ee780c9037843906ade31c
7
+ data.tar.gz: cf4a88871447ed9733cfc777486ee77d6113a55f523b3a6e6eac0ec9340f0652ec85c01434544352094f7672283879a130d6816df31c2a1ba5d8897176ed7dbb
@@ -16,17 +16,17 @@ jobs:
16
16
  strategy:
17
17
  matrix:
18
18
  ruby-version:
19
- - 2.7
20
19
  - 3.0
21
20
  - 3.1
22
21
  - 3.2
22
+ - 3.3
23
23
 
24
24
  steps:
25
25
  - uses: actions/checkout@v3
26
26
  - name: Set up Ruby
27
27
  uses: ruby/setup-ruby@v1
28
28
  with:
29
- bundler: 2.4
29
+ bundler: latest
30
30
  ruby-version: ${{ matrix.ruby-version }}
31
31
  bundler-cache: true
32
32
  - name: Run tests
@@ -41,8 +41,7 @@ jobs:
41
41
  strategy:
42
42
  matrix:
43
43
  ruby-version:
44
- - 2.7
45
- - 3.2
44
+ - 3.3
46
45
  steps:
47
46
  - uses: actions/checkout@v3
48
47
  - name: Set up Ruby
data/.rubocop.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
- TargetRubyVersion: 2.7
3
+ TargetRubyVersion: 3.0
4
4
 
5
5
  Layout/LineLength:
6
6
  Max: 120
@@ -14,10 +14,6 @@ Style/HashTransformKeys:
14
14
  - 'lib/uploadcare/client/conversion/video_conversion_client.rb'
15
15
  - 'lib/uploadcare/entity/file.rb'
16
16
 
17
- Gemspec/RequiredRubyVersion:
18
- Exclude:
19
- - 'uploadcare-ruby.gemspec'
20
-
21
17
  Metrics/BlockLength:
22
18
  Exclude:
23
19
  - 'bin/'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.4.0 — 2024-03-09
4
+
5
+ ### Breaking
6
+
7
+ * Drop support of unmaintainable Ruby versions < 3.x.
8
+
9
+ ### Fixed
10
+
11
+ * Update locations where Dry::Monads structure has changed.
12
+ * Sign URL uploads if configured (#139).
13
+ * Start returning proper error message when raising RequestError in poll_upload_response, to hint to users what is going on. Fixes #141.
14
+ * When polling, raise if an error is returned (#142).
15
+ * Fix documentation about original file url on simple file upload.
16
+
17
+ ### Changed
18
+ * Support params in Rest client and in file info method, to allow passing custom params like "include=appdata" in `Uploadcare::File.file` calls. Closes #132.
19
+
20
+
3
21
  ## 4.3.6 — 2023-11-18
4
22
 
5
23
  ### Fixed
data/Gemfile CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- gem 'byebug', '~> 11.1'
6
- gem 'rake', '~> 13.0'
7
- gem 'rspec', '~> 3.0'
8
- gem 'rubocop', '~> 1.48'
9
- gem 'vcr', '~> 6.1'
10
- gem 'webmock', '~> 3.18'
5
+ gem 'byebug'
6
+ gem 'rake'
7
+ gem 'rspec'
8
+ gem 'rubocop'
9
+ gem 'vcr'
10
+ gem 'webmock'
11
11
 
12
12
  # Specify your gem's dependencies in uploadcare-ruby.gemspec
13
13
  gemspec
data/README.md CHANGED
@@ -34,7 +34,7 @@ wrapping Upload and REST APIs.
34
34
  * [Useful links](#useful-links)
35
35
 
36
36
  ## Requirements
37
- * ruby 2.7+
37
+ * ruby 3.0+
38
38
 
39
39
  ## Compatibility
40
40
 
@@ -101,8 +101,8 @@ Using Uploadcare is simple, and here are the basics of handling files.
101
101
  # => "dc99200d-9bd6-4b43-bfa9-aa7bfaefca40"
102
102
 
103
103
  # URL for the file, can be used with your website or app right away
104
- @uc_file.url
105
- # => "https://ucarecdn.com/dc99200d-9bd6-4b43-bfa9-aa7bfaefca40/"
104
+ @uc_file.original_file_url
105
+ # => "https://ucarecdn.com/dc99200d-9bd6-4b43-bfa9-aa7bfaefca40/your-file.png"
106
106
  ```
107
107
 
108
108
  Your might then want to store or delete the uploaded file. Storing files could
@@ -134,7 +134,7 @@ Uploadcare::Uploader.upload("https://placekitten.com/96/139")
134
134
  There are explicit ways to select upload type:
135
135
 
136
136
  ```ruby
137
- files = [File.open("1.jpg"), File.open("1.jpg"]
137
+ files = [File.open("1.jpg"), File.open("1.jpg")]
138
138
  Uploadcare::Uploader.upload_files(files)
139
139
 
140
140
  Uploadcare::Uploader.upload_from_url("https://placekitten.com/96/139")
@@ -208,10 +208,10 @@ Entities are representations of objects in Uploadcare cloud.
208
208
 
209
209
  #### File
210
210
 
211
- File entity contains its metadata.
211
+ File entity contains its metadata. It also supports `include` param to include additional fields to the file object, such as: "appdata".
212
212
 
213
213
  ```ruby
214
- @file = Uploadcare::File.file("FILE_ID_IN_YOUR_PROJECT")
214
+ @file = Uploadcare::File.file("FILE_ID_IN_YOUR_PROJECT", include: "appdata")
215
215
  {
216
216
  "datetime_removed"=>nil,
217
217
  "datetime_stored"=>"2018-11-26T12:49:10.477888Z",
@@ -37,9 +37,9 @@ module Uploadcare
37
37
 
38
38
  parsed_body = JSON.parse(response_body, symbolize_names: true)
39
39
  errors = parsed_body[:error] || parsed_body[:problems]
40
- return Dry::Monads::Failure(errors) unless errors.nil? || errors.empty?
40
+ return Dry::Monads::Result::Failure.call(errors) unless errors.nil? || errors.empty?
41
41
 
42
- Dry::Monads::Success(parsed_body)
42
+ Dry::Monads::Result::Success.call(parsed_body)
43
43
  end
44
44
 
45
45
  # Prepares body for convert_many method
@@ -16,8 +16,8 @@ module Uploadcare
16
16
 
17
17
  # Acquire file info
18
18
  # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#operation/fileInfo
19
- def info(uuid)
20
- get(uri: "/files/#{uuid}/")
19
+ def info(uuid, params = {})
20
+ get(uri: "/files/#{uuid}/", params: params)
21
21
  end
22
22
  alias file info
23
23
 
@@ -27,8 +27,11 @@ module Uploadcare
27
27
  request_headers = Param::AuthenticationHeader.call(method: method.upcase, uri: uri,
28
28
  content_type: headers[:'Content-Type'], **options)
29
29
  handle_throttling do
30
- send("api_struct_#{method.downcase}", path: remove_trailing_slash(uri),
31
- headers: request_headers, body: options[:content])
30
+ send("api_struct_#{method.downcase}",
31
+ path: remove_trailing_slash(uri),
32
+ headers: request_headers,
33
+ body: options[:content],
34
+ params: options[:params])
32
35
  end
33
36
  end
34
37
 
@@ -17,7 +17,7 @@ module Uploadcare
17
17
  end
18
18
  end
19
19
 
20
- Dry::Monads::Success(nil)
20
+ Dry::Monads::Result::Success.call(nil)
21
21
  end
22
22
 
23
23
  # Get a file group by its ID.
@@ -3,6 +3,7 @@
3
3
  require_relative 'upload_client'
4
4
  require 'retries'
5
5
  require 'param/upload/upload_params_generator'
6
+ require 'param/upload/signature_generator'
6
7
 
7
8
  module Uploadcare
8
9
  module Client
@@ -42,7 +43,7 @@ module Uploadcare
42
43
  uploaded_response = poll_upload_response(token_response.success[:token])
43
44
  return uploaded_response if uploaded_response.success[:status] == 'error'
44
45
 
45
- Dry::Monads::Success(files: [uploaded_response.success])
46
+ Dry::Monads::Result::Success.call(files: [uploaded_response.success])
46
47
  end
47
48
 
48
49
  # Check upload status
@@ -75,12 +76,22 @@ module Uploadcare
75
76
  def poll_upload_response(token)
76
77
  with_retries(max_tries: Uploadcare.config.max_request_tries,
77
78
  base_sleep_seconds: Uploadcare.config.base_request_sleep,
78
- max_sleep_seconds: Uploadcare.config.max_request_sleep) do
79
+ max_sleep_seconds: Uploadcare.config.max_request_sleep,
80
+ rescue: RetryError) do
79
81
  response = get_upload_from_url_status(token)
80
- raise RequestError if %w[progress waiting unknown].include?(response.success[:status])
82
+ handle_polling_response(response)
83
+ end
84
+ end
81
85
 
82
- response
86
+ def handle_polling_response(response)
87
+ case response.success[:status]
88
+ when 'error'
89
+ raise RequestError, response.success[:error]
90
+ when 'progress', 'waiting', 'unknown'
91
+ raise RetryError, response.success[:error] || 'Upload is taking longer than expected. Try increasing the max_request_tries config if you know your file uploads will take more time.' # rubocop:disable Layout/LineLength
83
92
  end
93
+
94
+ response
84
95
  end
85
96
 
86
97
  # Prepares body for upload_many method
@@ -96,13 +107,13 @@ module Uploadcare
96
107
 
97
108
  # Prepare upload_from_url initial request body
98
109
  def upload_from_url_body(url, options = {})
99
- HTTP::FormData::Multipart.new(
100
- options.merge(
101
- 'pub_key' => Uploadcare.config.public_key,
102
- 'source_url' => url,
103
- 'store' => store_value(options[:store])
104
- )
105
- )
110
+ opts = {
111
+ 'pub_key' => Uploadcare.config.public_key,
112
+ 'source_url' => url,
113
+ 'store' => store_value(options[:store])
114
+ }
115
+ opts.merge!(Param::Upload::SignatureGenerator.call) if Uploadcare.config.sign_uploads
116
+ HTTP::FormData::Multipart.new(options.merge(opts))
106
117
  end
107
118
 
108
119
  def store_value(store)
@@ -3,7 +3,6 @@
3
3
  module Uploadcare
4
4
  module Exception
5
5
  # Standard error for invalid API responses
6
- class RequestError < StandardError
7
- end
6
+ class RequestError < StandardError; end
8
7
  end
9
8
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Uploadcare
4
+ module Exception
5
+ # Standard error to raise when needing to retry a request
6
+ class RetryError < StandardError; end
7
+ end
8
+ end
@@ -1,26 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'digest/md5'
4
+ require 'addressable/uri'
4
5
 
5
6
  module Uploadcare
6
7
  module Param
7
8
  # This object returns headers needed for authentication
8
9
  # This authentication method is more secure, but more tedious
9
10
  class SecureAuthHeader
10
- # @see https://uploadcare.com/docs/api_reference/rest/requests_auth/#auth-uploadcare
11
- def self.call(options = {})
12
- @method = options[:method]
13
- @body = options[:content] || ''
14
- @content_type = options[:content_type]
15
- @uri = options[:uri]
16
- @date_for_header = timestamp
17
- {
18
- Date: @date_for_header,
19
- Authorization: "Uploadcare #{Uploadcare.config.public_key}:#{signature}"
20
- }
21
- end
22
-
23
11
  class << self
12
+ # @see https://uploadcare.com/docs/api_reference/rest/requests_auth/#auth-uploadcare
13
+ def call(options = {})
14
+ @method = options[:method]
15
+ @body = options[:content] || ''
16
+ @content_type = options[:content_type]
17
+ @uri = make_uri(options)
18
+
19
+ @date_for_header = timestamp
20
+ {
21
+ Date: @date_for_header,
22
+ Authorization: "Uploadcare #{Uploadcare.config.public_key}:#{signature}"
23
+ }
24
+ end
25
+
24
26
  def signature
25
27
  content_md5 = Digest::MD5.hexdigest(@body)
26
28
  sign_string = [@method, content_md5, @content_type, @date_for_header, @uri].join("\n")
@@ -31,6 +33,18 @@ module Uploadcare
31
33
  def timestamp
32
34
  Time.now.gmtime.strftime('%a, %d %b %Y %H:%M:%S GMT')
33
35
  end
36
+
37
+ private
38
+
39
+ def make_uri(options)
40
+ if options[:params] && !options[:params].empty?
41
+ uri = Addressable::URI.parse options[:uri]
42
+ uri.query_values = uri.query_values(Array).to_a.concat(options[:params].to_a)
43
+ uri.to_s
44
+ else
45
+ options[:uri]
46
+ end
47
+ end
34
48
  end
35
49
  end
36
50
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uploadcare
4
- VERSION = '4.3.6'
4
+ VERSION = '4.4.0'
5
5
  end
data/lib/uploadcare.rb CHANGED
@@ -6,6 +6,7 @@ require 'ruby/version'
6
6
  # Exceptions
7
7
  require 'exception/throttle_error'
8
8
  require 'exception/request_error'
9
+ require 'exception/retry_error'
9
10
 
10
11
  # Entities
11
12
  require 'entity/entity'
@@ -33,18 +34,6 @@ require 'signed_url_generators/base_generator'
33
34
  module Uploadcare
34
35
  extend Dry::Configurable
35
36
 
36
- # NOTE: The dry-configurable gem has introduced the `default` keyword argument
37
- # and deprecated the positional default argument in v0.13.0, which requires
38
- # Ruby >= 2.6.0. In order to provide backwards compatibility and not disable
39
- # deprecation warnings, we override the dry-configurable's `setting` DSL method.
40
- def self.setting(name, default:, **options, &block)
41
- if RUBY_VERSION < '2.6'
42
- super name, default, &block
43
- else
44
- super
45
- end
46
- end
47
-
48
37
  setting :public_key, default: ENV.fetch('UPLOADCARE_PUBLIC_KEY', '')
49
38
  setting :secret_key, default: ENV.fetch('UPLOADCARE_SECRET_KEY', '')
50
39
  setting :auth_type, default: 'Uploadcare'
@@ -43,6 +43,8 @@ Gem::Specification.new do |spec|
43
43
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
44
44
  spec.require_paths = ['lib', 'lib/uploadcare', 'lib/uploadcare/rest']
45
45
 
46
+ spec.required_ruby_version = '>= 3.0'
47
+
46
48
  spec.add_dependency 'mimemagic', '~> 0.4'
47
49
  spec.add_dependency 'parallel', '~> 1.22'
48
50
  spec.add_dependency 'retries', '~> 0.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uploadcare-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.6
4
+ version: 4.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "@dmitrijivanchenko (Dmitrij Ivanchenko), @T0mbery (Andrey Aksenov)"
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-11-18 00:00:00.000000000 Z
12
+ date: 2024-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mimemagic
@@ -132,6 +132,7 @@ files:
132
132
  - lib/uploadcare/entity/webhook.rb
133
133
  - lib/uploadcare/exception/conversion_error.rb
134
134
  - lib/uploadcare/exception/request_error.rb
135
+ - lib/uploadcare/exception/retry_error.rb
135
136
  - lib/uploadcare/exception/throttle_error.rb
136
137
  - lib/uploadcare/param/authentication_header.rb
137
138
  - lib/uploadcare/param/conversion/document/processing_job_url_builder.rb
@@ -168,14 +169,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
169
  requirements:
169
170
  - - ">="
170
171
  - !ruby/object:Gem::Version
171
- version: '0'
172
+ version: '3.0'
172
173
  required_rubygems_version: !ruby/object:Gem::Requirement
173
174
  requirements:
174
175
  - - ">="
175
176
  - !ruby/object:Gem::Version
176
177
  version: '0'
177
178
  requirements: []
178
- rubygems_version: 3.4.10
179
+ rubygems_version: 3.5.3
179
180
  signing_key:
180
181
  specification_version: 4
181
182
  summary: Ruby wrapper for uploadcare API