-
Notifications
You must be signed in to change notification settings - Fork 28
File tags #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
File tags #191
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #!/usr/bin/env ruby | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative '../support/run_rest_example' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #!/usr/bin/env ruby | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative '../support/run_rest_example' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #!/usr/bin/env ruby | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative '../support/run_rest_example' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'uri' | ||
|
|
||
| # REST API endpoint for per-file tag operations. | ||
| # | ||
| # @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/File-tags | ||
| class Uploadcare::Api::Rest::FileTags | ||
| # @return [Uploadcare::Api::Rest] Parent REST client | ||
| attr_reader :rest | ||
|
|
||
| # @param rest [Uploadcare::Api::Rest] Parent REST client | ||
| def initialize(rest:) | ||
| @rest = rest | ||
| end | ||
|
|
||
| # Get the ordered list of tags for a file. | ||
| # | ||
| # @param uuid [String] File UUID | ||
| # @param request_options [Hash] Request options | ||
| # @return [Uploadcare::Result] Response containing the `tags` array | ||
| def list(uuid:, request_options: {}) | ||
| rest.get(path: tags_path(uuid), params: {}, headers: {}, request_options: request_options) | ||
| end | ||
| alias index list | ||
|
|
||
| # Replace all tags for a file. | ||
| # | ||
| # @param uuid [String] File UUID | ||
| # @param tags [Array<String>] Complete replacement tag list | ||
| # @param request_options [Hash] Request options | ||
| # @return [Uploadcare::Result] Response containing tags, added, and deleted | ||
| def replace(uuid:, tags:, request_options: {}) | ||
| rest.put( | ||
| path: tags_path(uuid), params: { tags: tags }, headers: {}, request_options: request_options | ||
| ) | ||
| end | ||
|
|
||
| # Atomically add and delete tags for a file. | ||
| # | ||
| # Deletions are applied before additions by the API. | ||
| # | ||
| # @param uuid [String] File UUID | ||
| # @param add [Array<String>, nil] Tags to add | ||
| # @param delete [Array<String>, nil] Tags to delete | ||
| # @param request_options [Hash] Request options | ||
| # @return [Uploadcare::Result] Response containing tags, added, and deleted | ||
| def update(uuid:, add: nil, delete: nil, request_options: {}) | ||
| params = {} | ||
| params[:add] = add unless add.nil? || add.empty? | ||
| params[:delete] = delete unless delete.nil? || delete.empty? | ||
| body = params.empty? ? {}.to_json : params | ||
| rest.patch(path: tags_path(uuid), params: body, headers: {}, request_options: request_options) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def tags_path(uuid) | ||
| encoded_uuid = URI.encode_www_form_component(uuid.to_s) | ||
| "/files/#{encoded_uuid}/tags/" | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Per-file tag operations scoped to a client instance. | ||
| class Uploadcare::Client::FileTagsAccessor | ||
| attr_reader :client | ||
|
|
||
| # @param client [Uploadcare::Client] | ||
| def initialize(client:) | ||
| @client = client | ||
| end | ||
|
|
||
| # @param uuid [String] | ||
| # @param request_options [Hash] | ||
| # @return [Array<String>] | ||
| def list(uuid:, request_options: {}) | ||
| Uploadcare::Resources::FileTags.list(uuid: uuid, client: client, request_options: request_options) | ||
| end | ||
| alias index list | ||
|
|
||
| # @param uuid [String] | ||
| # @param tags [Array<String>] | ||
| # @param request_options [Hash] | ||
| # @return [Uploadcare::Resources::FileTags] | ||
| def replace(uuid:, tags:, request_options: {}) | ||
| Uploadcare::Resources::FileTags.replace( | ||
| uuid: uuid, tags: tags, client: client, request_options: request_options | ||
| ) | ||
| end | ||
|
|
||
| # @param uuid [String] | ||
| # @param add [Array<String>] | ||
| # @param delete [Array<String>] | ||
| # @param request_options [Hash] | ||
| # @return [Uploadcare::Resources::FileTags] | ||
| def update(uuid:, add: [], delete: [], request_options: {}) | ||
| Uploadcare::Resources::FileTags.update( | ||
| uuid: uuid, add: add, delete: delete, client: client, request_options: request_options | ||
| ) | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.