-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from Jesus/search-v2
Search v2
- Loading branch information
Showing
25 changed files
with
402 additions
and
96 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropboxApi::Metadata | ||
class FileCategoriesList < Array | ||
def initialize(list) | ||
super(list.map { |c| DropboxApi::Metadata::FileCategory.new c }) | ||
end | ||
end | ||
end |
This file contains 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,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropboxApi::Metadata | ||
class FileCategory < DropboxApi::Metadata::Tag | ||
VALID_VALUES = %i[ | ||
image | ||
document | ||
spreadsheet | ||
presentation | ||
audio | ||
video | ||
folder | ||
paper | ||
others | ||
].freeze | ||
|
||
def self.valid_values | ||
VALID_VALUES | ||
end | ||
end | ||
end |
This file contains 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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropboxApi::Metadata | ||
class FileExtensionsList < Array | ||
def initialize(data) | ||
if !data.is_a?(Array) || data.any? { |v| !v.is_a? String } | ||
raise ArgumentError, "Invalid extension list: #{data.inspect}." | ||
end | ||
|
||
super(data) | ||
end | ||
end | ||
end |
This file contains 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,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropboxApi::Metadata | ||
class FileStatus < DropboxApi::Metadata::Tag | ||
VALID_VALUES = %i[ | ||
active | ||
deleted | ||
].freeze | ||
|
||
def self.valid_values | ||
VALID_VALUES | ||
end | ||
end | ||
end |
This file contains 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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropboxApi::Metadata | ||
class MetadataV2 < Base | ||
field :metadata, DropboxApi::Metadata::Resource | ||
end | ||
end |
This file contains 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,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropboxApi::Metadata | ||
class SearchMatchFieldOptions < Base | ||
# Whether to include highlight span from file title. The default for | ||
# this field is False. | ||
field :include_highlights, :boolean, :optional | ||
end | ||
end |
This file contains 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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropboxApi::Metadata | ||
class SearchMatchTypeV2 < DropboxApi::Metadata::Tag | ||
VALID_VALUES = %i[ | ||
filename | ||
file_content | ||
filename_and_content | ||
image_content | ||
].freeze | ||
|
||
def self.valid_values | ||
VALID_VALUES | ||
end | ||
end | ||
end |
This file contains 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,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropboxApi::Metadata | ||
class SearchMatchV2 < Base | ||
# The metadata for the matched file or folder. | ||
field :metadata, DropboxApi::Metadata::MetadataV2 | ||
|
||
# The type of the match. This field is optional. | ||
field :match_type, SearchMatchTypeV2 | ||
|
||
def resource | ||
# for some strange reason, v2 of this search endpoint doesn't have | ||
# the `resource` field anymore and file metadata is wrapped in a | ||
# metadata/metadata field... | ||
metadata.metadata | ||
end | ||
end | ||
end |
This file contains 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 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropboxApi::Metadata | ||
class SearchOptions < Base | ||
# Scopes the search to a path in the user's Dropbox. Searches the entire | ||
# Dropbox if not specified. This field is optional. | ||
field :path, String, :optional | ||
|
||
# The maximum number of search results to return. The default for this | ||
# field is 100. | ||
field :max_results, Integer, :optional | ||
|
||
# Specified property of the order of search results. By default, results | ||
# are sorted by relevance. This field is optional. | ||
field :order_by, DropboxApi::Metadata::SearchOrderBy, :optional | ||
|
||
# Restricts search to the given file status. The default for this union | ||
# is active. | ||
field :file_status, DropboxApi::Metadata::FileStatus, :optional | ||
|
||
# Restricts search to only match on filenames. The default for this field | ||
# is false. | ||
field :filename_only, :boolean, :optional | ||
|
||
# Restricts search to only the extensions specified. Only supported for | ||
# active file search. This field is optional. | ||
field :file_extensions, DropboxApi::Metadata::FileExtensionsList, :optional | ||
|
||
# Restricts search to only the file categories specified. Only supported | ||
# for active file search. This field is optional. | ||
field :file_categories, DropboxApi::Metadata::FileCategoriesList, :optional | ||
end | ||
end |
This file contains 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,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropboxApi::Metadata | ||
class SearchOrderBy < DropboxApi::Metadata::Tag | ||
VALID_VALUES = %i[ | ||
relevance | ||
last_modified_time | ||
].freeze | ||
|
||
def self.valid_values | ||
VALID_VALUES | ||
end | ||
end | ||
end |
17 changes: 9 additions & 8 deletions
17
lib/dropbox_api/results/search_result.rb → lib/dropbox_api/results/search_v2_result.rb
This file contains 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 |
---|---|---|
@@ -1,23 +1,24 @@ | ||
# frozen_string_literal: true | ||
module DropboxApi::Results | ||
class SearchResult < DropboxApi::Results::Base | ||
class SearchV2Result < DropboxApi::Results::Base | ||
# A list (possibly empty) of matches for the query. | ||
def matches | ||
@matches ||= @data['matches'].map do |match| | ||
DropboxApi::Results::Search::Match.new match | ||
DropboxApi::Metadata::SearchMatchV2.new match | ||
end | ||
end | ||
|
||
# Used for paging. Value to set the start argument to when calling search | ||
# to fetch the next page of results. | ||
def start | ||
@data['start'].to_i | ||
end | ||
|
||
# Used for paging. If true, indicates there is another page of results | ||
# available that can be fetched by calling search again. | ||
def has_more? | ||
@data['more'].to_s == 'true' | ||
end | ||
|
||
# Pass the cursor into #search_continue to fetch the next page of results | ||
# (not yet implemented). | ||
# This field is optional. | ||
def cursor | ||
@data['cursor'] | ||
end | ||
end | ||
end |
This file contains 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.