Class: Uploadcare::Entity::File
- Inherits:
-
Uploadcare::Entity
- Object
- Uploadcare::Entity
- Uploadcare::Entity::File
- Defined in:
- lib/uploadcare/entity/file.rb
Overview
This serializer returns a single file
Constant Summary collapse
- RESPONSE_PARAMS =
%i[ datetime_removed datetime_stored datetime_uploaded is_image is_ready mime_type original_file_url original_filename size url uuid variations content_info metadata appdata source ].freeze
Class Method Summary collapse
-
.local_copy(source, args = {}) ⇒ Object
Copies file to current project.
-
.remote_copy(source, target, args = {}) ⇒ Object
copy file to different project.
Instance Method Summary collapse
-
#convert_document(params = {}, options = {}, converter = Conversion::DocumentConverter) ⇒ Object
The method to convert a document file to another file gets (conversion) params [Hash], options (store: Boolean) [Hash], converter [Class].
-
#convert_video(params = {}, options = {}, converter = Conversion::VideoConverter) ⇒ Object
The method to convert a video file to another file gets (conversion) params [Hash], options (store: Boolean) [Hash], converter [Class].
- #datetime_stored ⇒ Object
- #delete ⇒ Object
-
#load ⇒ Object
loads file metadata, if it's initialized with url or uuid.
-
#local_copy(args = {}) ⇒ Object
Instance version of internal_copy.
-
#remote_copy(target, args = {}) ⇒ Object
Instance version of external_copy.
-
#store ⇒ Object
Store a single file, preventing it from being deleted in 2 weeks.
-
#uuid ⇒ Object
gets file's uuid - even if it's only initialized with url.
Class Method Details
.local_copy(source, args = {}) ⇒ Object
Copies file to current project
source can be UID or full CDN link
56 57 58 59 |
# File 'lib/uploadcare/entity/file.rb', line 56 def self.local_copy(source, args = {}) response = FileClient.new.local_copy(source: source, **args).success[:result] File.new(response) end |
.remote_copy(source, target, args = {}) ⇒ Object
copy file to different project
source can be UID or full CDN link
66 67 68 |
# File 'lib/uploadcare/entity/file.rb', line 66 def self.remote_copy(source, target, args = {}) FileClient.new.remote_copy(source: source, target: target, **args).success[:result] end |
Instance Method Details
#convert_document(params = {}, options = {}, converter = Conversion::DocumentConverter) ⇒ Object
The method to convert a document file to another file gets (conversion) params [Hash], options (store: Boolean) [Hash], converter [Class]
40 41 42 |
# File 'lib/uploadcare/entity/file.rb', line 40 def convert_document(params = {}, = {}, converter = Conversion::DocumentConverter) convert_file(params, converter, ) end |
#convert_video(params = {}, options = {}, converter = Conversion::VideoConverter) ⇒ Object
The method to convert a video file to another file gets (conversion) params [Hash], options (store: Boolean) [Hash], converter [Class]
47 48 49 |
# File 'lib/uploadcare/entity/file.rb', line 47 def convert_video(params = {}, = {}, converter = Conversion::VideoConverter) convert_file(params, converter, ) end |
#datetime_stored ⇒ Object
18 19 20 21 |
# File 'lib/uploadcare/entity/file.rb', line 18 def datetime_stored Uploadcare.config.logger&.warn 'datetime_stored property has been deprecated, and will be removed without a replacement in future.' # rubocop:disable Layout/LineLength @entity.datetime_stored end |
#delete ⇒ Object
87 88 89 |
# File 'lib/uploadcare/entity/file.rb', line 87 def delete File.delete(uuid) end |
#load ⇒ Object
loads file metadata, if it's initialized with url or uuid
33 34 35 |
# File 'lib/uploadcare/entity/file.rb', line 33 def load initialize(File.info(uuid).entity) end |
#local_copy(args = {}) ⇒ Object
Instance version of internal_copy
71 72 73 |
# File 'lib/uploadcare/entity/file.rb', line 71 def local_copy(args = {}) File.local_copy(uuid, **args) end |
#remote_copy(target, args = {}) ⇒ Object
Instance version of external_copy
76 77 78 |
# File 'lib/uploadcare/entity/file.rb', line 76 def remote_copy(target, args = {}) File.remote_copy(uuid, target, **args) end |
#store ⇒ Object
Store a single file, preventing it from being deleted in 2 weeks
82 83 84 |
# File 'lib/uploadcare/entity/file.rb', line 82 def store File.store(uuid) end |
#uuid ⇒ Object
gets file's uuid - even if it's only initialized with url
25 26 27 28 29 30 |
# File 'lib/uploadcare/entity/file.rb', line 25 def uuid return @entity.uuid if @entity.uuid uuid = @entity.url.gsub('https://ucarecdn.com/', '') uuid.gsub(%r{/.*}, '') end |