Class: Uploadcare::Resources::FileTags
- Inherits:
-
BaseResource
- Object
- BaseResource
- Uploadcare::Resources::FileTags
- Defined in:
- lib/uploadcare/resources/file_tags.rb
Overview
Resource for reading and changing the ordered tag list associated with a file.
Instance Attribute Summary collapse
-
#added ⇒ Object
Returns the value of attribute added.
-
#deleted ⇒ Object
Returns the value of attribute deleted.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Class Method Summary collapse
-
.list(uuid:, client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Array<String>
(also: index)
Get the current tag list for a file.
-
.replace(uuid:, tags:, client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Uploadcare::Resources::FileTags
Replace the complete tag list for a file.
-
.update(uuid:, add: [], delete: [], client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Uploadcare::Resources::FileTags
Atomically add and delete tags for a file.
Instance Method Summary collapse
-
#index ⇒ self
Fetch the current tags.
-
#initialize(attributes = {}, client_or_config = nil) ⇒ FileTags
constructor
A new instance of FileTags.
-
#list(request_options: {}) ⇒ self
Fetch the current tags.
-
#replace(tags:, request_options: {}) ⇒ self
Replace the complete tag list.
-
#update(add: [], delete: [], request_options: {}) ⇒ self
Atomically add and delete tags.
Constructor Details
#initialize(attributes = {}, client_or_config = nil) ⇒ FileTags
Returns a new instance of FileTags.
9 10 11 12 13 14 |
# File 'lib/uploadcare/resources/file_tags.rb', line 9 def initialize(attributes = {}, client_or_config = nil) @tags = [] @added = [] @deleted = [] super end |
Instance Attribute Details
#added ⇒ Object
Returns the value of attribute added.
7 8 9 |
# File 'lib/uploadcare/resources/file_tags.rb', line 7 def added @added end |
#deleted ⇒ Object
Returns the value of attribute deleted.
7 8 9 |
# File 'lib/uploadcare/resources/file_tags.rb', line 7 def deleted @deleted end |
#tags ⇒ Object
Returns the value of attribute tags.
7 8 9 |
# File 'lib/uploadcare/resources/file_tags.rb', line 7 def @tags end |
#uuid ⇒ Object
Returns the value of attribute uuid.
7 8 9 |
# File 'lib/uploadcare/resources/file_tags.rb', line 7 def uuid @uuid end |
Class Method Details
.list(uuid:, client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Array<String> Also known as: index
Get the current tag list for a file.
66 67 68 69 |
# File 'lib/uploadcare/resources/file_tags.rb', line 66 def self.list(uuid:, client: nil, config: Uploadcare.configuration, request_options: {}) resolved_client = resolve_client(client: client, config: config) new({ uuid: uuid }, resolved_client).list(request_options: )..dup end |
.replace(uuid:, tags:, client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Uploadcare::Resources::FileTags
Replace the complete tag list for a file.
78 79 80 81 |
# File 'lib/uploadcare/resources/file_tags.rb', line 78 def self.replace(uuid:, tags:, client: nil, config: Uploadcare.configuration, request_options: {}) resolved_client = resolve_client(client: client, config: config) new({ uuid: uuid }, resolved_client).replace(tags: , request_options: ) end |
.update(uuid:, add: [], delete: [], client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Uploadcare::Resources::FileTags
Atomically add and delete tags for a file.
86 87 88 89 90 91 |
# File 'lib/uploadcare/resources/file_tags.rb', line 86 def self.update(uuid:, add: [], delete: [], client: nil, config: Uploadcare.configuration, request_options: {}) resolved_client = resolve_client(client: client, config: config) new({ uuid: uuid }, resolved_client).update( add: add, delete: delete, request_options: ) end |
Instance Method Details
#index ⇒ self
Fetch the current tags.
29 30 31 32 33 34 35 36 37 |
# File 'lib/uploadcare/resources/file_tags.rb', line 29 def list(request_options: {}) response = Uploadcare::Result.unwrap( client.api.rest..list(uuid: uuid, request_options: ) ) self. = response.fetch('tags', []) self.added = [] self.deleted = [] self end |
#list(request_options: {}) ⇒ self
Fetch the current tags.
20 21 22 23 24 25 26 27 28 |
# File 'lib/uploadcare/resources/file_tags.rb', line 20 def list(request_options: {}) response = Uploadcare::Result.unwrap( client.api.rest..list(uuid: uuid, request_options: ) ) self. = response.fetch('tags', []) self.added = [] self.deleted = [] self end |
#replace(tags:, request_options: {}) ⇒ self
Replace the complete tag list. An empty array clears all tags.
36 37 38 39 40 41 42 43 |
# File 'lib/uploadcare/resources/file_tags.rb', line 36 def replace(tags:, request_options: {}) normalized = Uploadcare::Internal::FileTagNormalizer.call() response = Uploadcare::Result.unwrap( client.api.rest..replace(uuid: uuid, tags: normalized, request_options: ) ) assign_attributes(response) self end |
#update(add: [], delete: [], request_options: {}) ⇒ self
Atomically add and delete tags. Deletions are applied first.
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/uploadcare/resources/file_tags.rb', line 51 def update(add: [], delete: [], request_options: {}) normalized_add = Uploadcare::Internal::FileTagNormalizer.call(add) normalized_delete = Uploadcare::Internal::FileTagNormalizer.call(delete, max_count: nil) response = Uploadcare::Result.unwrap( client.api.rest..update( uuid: uuid, add: normalized_add, delete: normalized_delete, request_options: ) ) assign_attributes(response) self end |