Class: Assinafy::Resources::TagResource
- Inherits:
-
BaseResource
- Object
- BaseResource
- Assinafy::Resources::TagResource
- Defined in:
- lib/assinafy/resources/tag_resource.rb,
sig/assinafy.rbs
Overview
Workspace-scoped tag management.
Tags are labels that can be attached to documents and templates for filtering and organization.
See https://api.assinafy.com.br/v1/docs#tag for the full documentation of these endpoints.
Constant Summary
Constants inherited from BaseResource
BaseResource::AUTH_HEADERS, BaseResource::PAGINATION_HEADERS, BaseResource::PATH_SEGMENT
Instance Method Summary collapse
-
#create(payload, account_id_override = nil) ⇒ Hash
Create a tag in the workspace.
-
#delete(tag_id, account_id_override = nil, force: false) ⇒ Hash
Delete a tag.
-
#list(params = {}, account_id_override = nil) ⇒ Hash{Symbol=>Array,Hash}
List tags in the workspace, ordered alphabetically by name.
-
#update(tag_id, payload, account_id_override = nil) ⇒ Hash
Update a tag's name and/or color.
Methods inherited from BaseResource
Constructor Details
This class inherits a constructor from Assinafy::Resources::BaseResource
Instance Method Details
#create(payload, account_id_override = nil) ⇒ Hash
Create a tag in the workspace.
Returns 409 Conflict if a tag with the same name (case-insensitive) already exists.
71 72 73 74 75 76 77 78 |
# File 'lib/assinafy/resources/tag_resource.rb', line 71 def create(payload, account_id_override = nil) acc_id = account_id(account_id_override) body = tag_payload(payload, require_name: true) call('Failed to create tag') do http_post("accounts/#{acc_id}/tags", body) end end |
#delete(tag_id, account_id_override = nil, force: false) ⇒ Hash
Delete a tag. By default, deletion fails with 409 Conflict if the tag
is attached to any document or template. Pass force: true to detach
it from everything and delete it; the documents and templates
themselves are not deleted.
142 143 144 145 146 147 148 149 150 151 |
# File 'lib/assinafy/resources/tag_resource.rb', line 142 def delete(tag_id, account_id_override = nil, force: false) acc_id = account_id(account_id_override) tid = require_id(tag_id, 'Tag ID') force = require_boolean(force, 'force') params = force ? { force: true } : {} call('Failed to delete tag') do http_delete("accounts/#{acc_id}/tags/#{tid}", params) end end |
#list(params = {}, account_id_override = nil) ⇒ Hash{Symbol=>Array,Hash}
List tags in the workspace, ordered alphabetically by name.
37 38 39 40 41 42 43 |
# File 'lib/assinafy/resources/tag_resource.rb', line 37 def list(params = {}, account_id_override = nil) acc_id = account_id(account_id_override) call_list('Failed to list tags') do http_get("accounts/#{acc_id}/tags", params) end end |
#update(tag_id, payload, account_id_override = nil) ⇒ Hash
Update a tag's name and/or color. Documents and templates already attached to the tag keep their relationship; only the tag's own attributes change. Returns 409 Conflict if another tag already uses the new name (case-insensitive).
At least one of :name or :color must be supplied: an empty payload
raises, and a blank :name raises.
116 117 118 119 120 121 122 123 124 |
# File 'lib/assinafy/resources/tag_resource.rb', line 116 def update(tag_id, payload, account_id_override = nil) acc_id = account_id(account_id_override) tid = require_id(tag_id, 'Tag ID') body = tag_payload(payload, require_name: false) call('Failed to update tag') do http_put("accounts/#{acc_id}/tags/#{tid}", body) end end |