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].
- #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
51 52 53 54 |
# File 'lib/uploadcare/entity/file.rb', line 51 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
61 62 63 64 |
# File 'lib/uploadcare/entity/file.rb', line 61 def self.remote_copy(source, target, args = {}) response = FileClient.new.remote_copy(source: source, target: target, **args).success[:result] File.new(response) 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]
35 36 37 |
# File 'lib/uploadcare/entity/file.rb', line 35 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]
42 43 44 |
# File 'lib/uploadcare/entity/file.rb', line 42 def convert_video(params = {}, = {}, converter = Conversion::VideoConverter) convert_file(params, converter, ) end |
#delete ⇒ Object
83 84 85 |
# File 'lib/uploadcare/entity/file.rb', line 83 def delete File.delete(uuid) end |
#load ⇒ Object
loads file metadata, if it's initialized with url or uuid
28 29 30 |
# File 'lib/uploadcare/entity/file.rb', line 28 def load initialize(File.info(uuid).entity) end |
#local_copy(args = {}) ⇒ Object
Instance version of internal_copy
67 68 69 |
# File 'lib/uploadcare/entity/file.rb', line 67 def local_copy(args = {}) File.local_copy(uuid, **args) end |
#remote_copy(target, args = {}) ⇒ Object
Instance version of external_copy
72 73 74 |
# File 'lib/uploadcare/entity/file.rb', line 72 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
78 79 80 |
# File 'lib/uploadcare/entity/file.rb', line 78 def store File.store(uuid) end |
#uuid ⇒ Object
gets file's uuid - even if it's only initialized with url
20 21 22 23 24 25 |
# File 'lib/uploadcare/entity/file.rb', line 20 def uuid return @entity.uuid if @entity.uuid uuid = @entity.url.gsub('https://ucarecdn.com/', '') uuid.gsub(%r{/.*}, '') end |