-
Notifications
You must be signed in to change notification settings - Fork 28
File search #192
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
Merged
Merged
File search #192
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1e0cfe6
File tags
alxgsv 68bc001
Fix flaky multipart upload specs by forcing sequential path
alxgsv d64b6a1
File search
alxgsv 3347801
Fix blank file tag normalization
vipulnsward c7f578a
Fix documentation and RuboCop compatibility
vipulnsward a0ccdf1
Merge branch 'feature/tags' into feature/search
vipulnsward c9a516b
Simplify file search operation
vipulnsward 3ab7bb2
Document file tags and upload examples
vipulnsward 3e54ea1
Document file search workflow
vipulnsward 7de64a1
Merge branch 'feature/tags' into feature/search
vipulnsward 5a6a6d8
Complete file tag documentation guidance
vipulnsward 335e206
Make file tag example executable
vipulnsward ceef639
Complete file search documentation guidance
vipulnsward fd46bbb
Merge branch 'feature/tags' into feature/search
vipulnsward 84993df
Clean up file tag example uploads
vipulnsward 0cbf8c5
Merge branch 'feature/tags' into feature/search
vipulnsward 7bef5bc
Merge remote-tracking branch 'origin/main' into feature/search
vipulnsward f0008ee
Fix file search pagination review feedback
vipulnsward 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
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,33 @@ | ||
| #!/usr/bin/env ruby | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative '../lib/uploadcare' | ||
| require 'dotenv/load' | ||
|
|
||
| query = ARGV.join(' ') | ||
|
|
||
| if query.length < 4 | ||
| puts 'Usage: ruby file_search.rb <query of at least four characters>' | ||
| puts 'Example: ruby file_search.rb invoice' | ||
| exit 1 | ||
| end | ||
|
|
||
| begin | ||
| client = Uploadcare::Client.new( | ||
| public_key: ENV.fetch('UPLOADCARE_PUBLIC_KEY'), | ||
| secret_key: ENV.fetch('UPLOADCARE_SECRET_KEY') | ||
| ) | ||
|
|
||
| results = client.files.search(query: query, sort: ['-datetime_uploaded'], limit: 20) | ||
|
|
||
| puts "Found #{results.total} files" | ||
| results.each do |file| | ||
| puts [file.uuid, file.original_filename, file.highlight].compact.join(' | ') | ||
| end | ||
|
|
||
| next_page = results.next_page | ||
| puts "Next page contains #{next_page.count} files" if next_page | ||
| rescue StandardError => e | ||
| warn "File search example failed: #{e.message}" | ||
| exit 1 | ||
| 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
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,45 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Paginated results returned by the file search endpoint. | ||
| # | ||
| # Search pagination uses POST requests, so every subsequent page must resend the | ||
| # original JSON search criteria while following the query parameters supplied by | ||
| # the API's next or previous URL. | ||
| class Uploadcare::Collections::FileSearchResult < Uploadcare::Collections::Paginated | ||
| # @return [Hash] JSON search criteria resent for subsequent pages | ||
| attr_reader :search_params, :search_query | ||
|
|
||
| def initialize(params = {}) | ||
| @search_params = immutable_copy(params[:search_params] || {}) | ||
| @search_query = immutable_copy(params[:search_query] || {}) | ||
| super | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def immutable_copy(value) | ||
| case value | ||
| when Hash | ||
| value.each_with_object({}) do |(key, nested_value), copy| | ||
| copy[immutable_copy(key)] = immutable_copy(nested_value) | ||
| end.freeze | ||
| when Array | ||
| value.map { |nested_value| immutable_copy(nested_value) }.freeze | ||
| when String | ||
| value.dup.freeze | ||
| else | ||
| value | ||
| end | ||
| end | ||
|
|
||
| def fetch_response(params) | ||
| query = search_query.transform_keys(&:to_s).merge(params) | ||
| Uploadcare::Result.unwrap( | ||
| api_client.search(params: search_params, query: query, request_options: request_options) | ||
| ) | ||
| end | ||
|
|
||
| def continuation_options | ||
| { search_params: search_params, search_query: search_query } | ||
| 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
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.