Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 4.4.0 release to main #156

Merged
merged 6 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## 4.4.0 — 2024-03-09

### Breaking

* Drop support of unmaintainable Ruby versions < 3.x
vipulnsward marked this conversation as resolved.
Show resolved Hide resolved

### Fixed

* Update locations where Dry::Monads structure has changed.
* Sign URL uploads if configured (#139)
vipulnsward marked this conversation as resolved.
Show resolved Hide resolved
* Start returning proper error message when raising RequestError in poll_upload_response, to hint to users what is going on. Fixes #141
vipulnsward marked this conversation as resolved.
Show resolved Hide resolved
* When polling, raise if an error is returned (#142)
vipulnsward marked this conversation as resolved.
Show resolved Hide resolved
* Fix documentation about original file url on simple file upload.

### Changed
* 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
vipulnsward marked this conversation as resolved.
Show resolved Hide resolved


## 4.3.6 — 2023-11-18

### Fixed
Expand Down
1 change: 1 addition & 0 deletions lib/uploadcare.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Exceptions
require 'exception/throttle_error'
require 'exception/request_error'
require 'exception/retry_error'

# Entities
require 'entity/entity'
Expand Down
34 changes: 21 additions & 13 deletions lib/uploadcare/client/uploader_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_relative 'upload_client'
require 'retries'
require 'param/upload/upload_params_generator'
require 'param/upload/signature_generator'

module Uploadcare
module Client
Expand Down Expand Up @@ -75,15 +76,22 @@ def post(args = {})
def poll_upload_response(token)
with_retries(max_tries: Uploadcare.config.max_request_tries,
base_sleep_seconds: Uploadcare.config.base_request_sleep,
max_sleep_seconds: Uploadcare.config.max_request_sleep) do
max_sleep_seconds: Uploadcare.config.max_request_sleep,
rescue: RetryError) do
response = get_upload_from_url_status(token)
handle_polling_response(response)
end
end

if %w[progress waiting unknown].include?(response.success[:status])
raise RequestError, '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
end

response
def handle_polling_response(response)
case response.success[:status]
when 'error'
raise RequestError, response.success[:error]
when 'progress', 'waiting', 'unknown'
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
end

response
end

# Prepares body for upload_many method
Expand All @@ -99,13 +107,13 @@ def upload_many_body(arr, options = {})

# Prepare upload_from_url initial request body
def upload_from_url_body(url, options = {})
HTTP::FormData::Multipart.new(
options.merge(
'pub_key' => Uploadcare.config.public_key,
'source_url' => url,
'store' => store_value(options[:store])
)
)
opts = {
'pub_key' => Uploadcare.config.public_key,
'source_url' => url,
'store' => store_value(options[:store])
}
opts.merge!(Param::Upload::SignatureGenerator.call) if Uploadcare.config.sign_uploads
HTTP::FormData::Multipart.new(options.merge(opts))
end

def store_value(store)
Expand Down
3 changes: 1 addition & 2 deletions lib/uploadcare/exception/request_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
module Uploadcare
module Exception
# Standard error for invalid API responses
class RequestError < StandardError
end
class RequestError < StandardError; end
end
end
8 changes: 8 additions & 0 deletions lib/uploadcare/exception/retry_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

module Uploadcare
module Exception
# Standard error to raise when needing to retry a request
class RetryError < StandardError; end
end
end
2 changes: 1 addition & 1 deletion lib/uploadcare/ruby/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Uploadcare
VERSION = '4.3.6'
VERSION = '4.4.0'
end
116 changes: 116 additions & 0 deletions spec/fixtures/vcr_cassettes/upload_upload_from_url_with_signature.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions spec/uploadcare/client/uploader_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
module Uploadcare
module Client
RSpec.describe UploaderClient do
subject { UploaderClient.new }
let!(:file) { ::File.open('spec/fixtures/kitten.jpeg') }
let!(:another_file) { ::File.open('spec/fixtures/another_kitten.jpeg') }
subject { described_class.new }

describe 'upload' do
let(:file) { ::File.open('spec/fixtures/kitten.jpeg') }
let(:another_file) { ::File.open('spec/fixtures/another_kitten.jpeg') }

it 'uploads a file' do
VCR.use_cassette('upload_upload') do
response = subject.upload(file, metadata: { subsystem: 'test' })
Expand Down
Loading
Loading