Class: Uploadcare::Resources::FileMetadata
- Inherits:
-
BaseResource
- Object
- BaseResource
- Uploadcare::Resources::FileMetadata
- Defined in:
- lib/uploadcare/resources/file_metadata.rb
Overview
File metadata resource for managing key-value metadata on files.
Instance Attribute Summary collapse
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Class Method Summary collapse
-
.delete(uuid:, key:, client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Object
Delete a metadata key.
-
.index(uuid:, client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Object
Get all metadata for a file.
-
.show(uuid:, key:, client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Object
Get a single metadata key's value.
-
.update(uuid:, key:, value:, client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Object
Update a metadata key's value.
Instance Method Summary collapse
-
#[](key) ⇒ String?
Access a metadata value by key.
-
#[]=(key, value) ⇒ Object
Set a metadata value by key (local only, call #update to persist).
-
#delete(key:, uuid: nil, request_options: {}) ⇒ nil
Delete a metadata key.
-
#index(uuid: nil, request_options: {}) ⇒ self
Retrieve all metadata for the file.
-
#initialize(attributes = {}, client_or_config = nil) ⇒ FileMetadata
constructor
A new instance of FileMetadata.
-
#show(key:, uuid: nil, request_options: {}) ⇒ String
Retrieve a single metadata key's value.
-
#to_h ⇒ Hash
Return all metadata as a hash.
-
#update(key:, value:, uuid: nil, request_options: {}) ⇒ String
Update a metadata key's value on the server.
Constructor Details
#initialize(attributes = {}, client_or_config = nil) ⇒ FileMetadata
Returns a new instance of FileMetadata.
9 10 11 12 |
# File 'lib/uploadcare/resources/file_metadata.rb', line 9 def initialize(attributes = {}, client_or_config = nil) super @metadata = {} end |
Instance Attribute Details
#uuid ⇒ Object
Returns the value of attribute uuid.
7 8 9 |
# File 'lib/uploadcare/resources/file_metadata.rb', line 7 def uuid @uuid end |
Class Method Details
.delete(uuid:, key:, client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Object
Delete a metadata key.
129 130 131 132 133 134 |
# File 'lib/uploadcare/resources/file_metadata.rb', line 129 def self.delete(uuid:, key:, client: nil, config: Uploadcare.configuration, request_options: {}) resolved_client = resolve_client(client: client, config: config) Uploadcare::Result.unwrap( resolved_client.api.rest..delete(uuid: uuid, key: key, request_options: ) ) end |
.index(uuid:, client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Object
Get all metadata for a file.
103 104 105 106 107 108 |
# File 'lib/uploadcare/resources/file_metadata.rb', line 103 def self.index(uuid:, client: nil, config: Uploadcare.configuration, request_options: {}) resolved_client = resolve_client(client: client, config: config) Uploadcare::Result.unwrap( resolved_client.api.rest..index(uuid: uuid, request_options: ) ) end |
.show(uuid:, key:, client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Object
Get a single metadata key's value.
111 112 113 114 115 116 |
# File 'lib/uploadcare/resources/file_metadata.rb', line 111 def self.show(uuid:, key:, client: nil, config: Uploadcare.configuration, request_options: {}) resolved_client = resolve_client(client: client, config: config) Uploadcare::Result.unwrap( resolved_client.api.rest..show(uuid: uuid, key: key, request_options: ) ) end |
.update(uuid:, key:, value:, client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Object
Update a metadata key's value.
119 120 121 122 123 124 125 126 |
# File 'lib/uploadcare/resources/file_metadata.rb', line 119 def self.update(uuid:, key:, value:, client: nil, config: Uploadcare.configuration, request_options: {}) resolved_client = resolve_client(client: client, config: config) Uploadcare::Result.unwrap( resolved_client.api.rest..update( uuid: uuid, key: key, value: value, request_options: ) ) end |
Instance Method Details
#[](key) ⇒ String?
Access a metadata value by key.
33 34 35 |
# File 'lib/uploadcare/resources/file_metadata.rb', line 33 def [](key) @metadata[key.to_s] end |
#[]=(key, value) ⇒ Object
Set a metadata value by key (local only, call #update to persist).
41 42 43 |
# File 'lib/uploadcare/resources/file_metadata.rb', line 41 def []=(key, value) @metadata[key.to_s] = value end |
#delete(key:, uuid: nil, request_options: {}) ⇒ nil
Delete a metadata key.
91 92 93 94 95 96 97 98 |
# File 'lib/uploadcare/resources/file_metadata.rb', line 91 def delete(key:, uuid: nil, request_options: {}) target_uuid = uuid || @uuid result = Uploadcare::Result.unwrap( client.api.rest..delete(uuid: target_uuid, key: key, request_options: ) ) @metadata.delete(key.to_s) if target_uuid == @uuid result end |
#index(uuid: nil, request_options: {}) ⇒ self
Retrieve all metadata for the file.
21 22 23 24 25 26 27 |
# File 'lib/uploadcare/resources/file_metadata.rb', line 21 def index(uuid: nil, request_options: {}) response = Uploadcare::Result.unwrap( client.api.rest..index(uuid: uuid || @uuid, request_options: ) ) @metadata = response.is_a?(Hash) ? response.transform_keys(&:to_s) : {} self end |
#show(key:, uuid: nil, request_options: {}) ⇒ String
Retrieve a single metadata key's value.
76 77 78 79 80 81 82 83 |
# File 'lib/uploadcare/resources/file_metadata.rb', line 76 def show(key:, uuid: nil, request_options: {}) target_uuid = uuid || @uuid result = Uploadcare::Result.unwrap( client.api.rest..show(uuid: target_uuid, key: key, request_options: ) ) @metadata[key.to_s] = result if target_uuid == @uuid result end |
#to_h ⇒ Hash
Return all metadata as a hash.
48 49 50 |
# File 'lib/uploadcare/resources/file_metadata.rb', line 48 def to_h @metadata.dup end |
#update(key:, value:, uuid: nil, request_options: {}) ⇒ String
Update a metadata key's value on the server.
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/uploadcare/resources/file_metadata.rb', line 59 def update(key:, value:, uuid: nil, request_options: {}) target_uuid = uuid || @uuid result = Uploadcare::Result.unwrap( client.api.rest..update( uuid: target_uuid, key: key, value: value, request_options: ) ) @metadata[key.to_s] = result if target_uuid == @uuid result end |