Skip to content

Commit

Permalink
Version 4.3.3 (#124)
Browse files Browse the repository at this point in the history
* Don't pull info after upload

* Fix the spec and add changelog

* Run info if the secret key is present

* Update CHANGELOG.md

Co-authored-by: Roman Sedykh <[email protected]>

* Add file info method

* Update changelog

* Fix the casette

* Revert "Fix the casette"

This reverts commit 180ee6c.

* Avoid breaking changes

* Update documentation

---------

Co-authored-by: Roman Sedykh <[email protected]>
  • Loading branch information
kraft001 and rsedykh authored Apr 14, 2023
1 parent 834951a commit d3c96ed
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 3 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 4.3.3 — 2023-04-14

### Changed

* Use `file_info` request after a file upload if the secret key is not provided.

### Added

* Add a new `file_info` method to retreive file information without the secret key.

## 4.3.2 — 2023-03-28

### Changed
Expand Down
12 changes: 12 additions & 0 deletions lib/uploadcare/client/uploader_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ def get_upload_from_url_status(token)
get(path: 'from_url/status/', params: query_params)
end

# Get information about an uploaded file
# Secret key not needed
#
# https://uploadcare.com/api-refs/upload-api/#tag/Upload/operation/fileUploadInfo
def file_info(uuid)
query_params = {
file_id: uuid,
pub_key: Uploadcare.config.public_key
}
get(path: 'info/', params: query_params)
end

private

alias api_struct_post post
Expand Down
14 changes: 13 additions & 1 deletion lib/uploadcare/entity/uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ def self.upload(object, options = {})
# upload single file
def self.upload_file(file, options = {})
response = UploaderClient.new.upload_many([file], options)
Uploadcare::Entity::File.info(response.success.to_a.flatten[-1])
uuid = response.success.values.first
if Uploadcare.config.secret_key.nil?
Uploadcare::Entity::File.new(file_info(uuid).success)
else
# we can get more info about the uploaded file
Uploadcare::Entity::File.info(uuid)
end
end

# upload multiple files
Expand Down Expand Up @@ -63,6 +69,12 @@ def self.get_upload_from_url_status(token)
UploaderClient.new.get_upload_from_url_status(token)
end

# Get information about an uploaded file (without the secret key)
# @param uuid [String]
def self.file_info(uuid)
UploaderClient.new.file_info(uuid)
end

class << self
private

Expand Down
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.2'
VERSION = '4.3.3'
end
56 changes: 56 additions & 0 deletions spec/fixtures/vcr_cassettes/upload_file_info.yml

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

107 changes: 107 additions & 0 deletions spec/fixtures/vcr_cassettes/upload_upload_one_without_secret_key.yml

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

29 changes: 28 additions & 1 deletion spec/uploadcare/entity/uploader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,21 @@ module Entity
VCR.use_cassette('upload_upload_one') do
upload = subject.upload(file)
expect(upload).to be_kind_of(Uploadcare::Entity::File)
expect(upload.size).to eq(file.size)
expect(file.path).to end_with(upload.original_filename.to_s)
expect(file.size).to eq(upload.size)
end
end

context 'when the secret key is missing' do
it 'returns a file without details', :aggregate_failures do
Uploadcare.config.secret_key = nil

VCR.use_cassette('upload_upload_one_without_secret_key') do
upload = subject.upload(file)
expect(upload).to be_kind_of(Uploadcare::Entity::File)
expect(file.path).to end_with(upload.original_filename.to_s)
expect(file.size).to eq(upload.size)
end
end
end
end
Expand Down Expand Up @@ -66,6 +80,19 @@ module Entity
end
end
end

describe 'file_info' do
it 'returns file info without the secret key', :aggregate_failures do
uuid = 'a7f9751a-432b-4b05-936c-2f62d51d255d'

VCR.use_cassette('upload_file_info') do
file_info = subject.file_info(uuid).success
expect(file_info[:original_filename]).not_to be_empty
expect(file_info[:size]).to be >= 0
expect(file_info[:uuid]).to eq uuid
end
end
end
end
end
end

0 comments on commit d3c96ed

Please sign in to comment.