Skip to content

Commit

Permalink
Introduce custom_query workflow variable
Browse files Browse the repository at this point in the history
This allows extending the default query used to get files from Google Drive.

For example to exclude folders from the request, set it like this:

    mimeType!='application/vnd.google-apps.folder'

It should also be possible to limit search to a specific folder by requiring that “parents in «folder id»” but this might require updating to version 3 of the Google Drive API.

Please refer to Google’s documentation about the possibilities. The workflow currently uses version 2 of the API.

Closes #38
  • Loading branch information
sorbits committed Sep 14, 2017
1 parent 36c69be commit 048b57b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/google-drive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,14 @@ class GoogleDrive
def self.get_items(token)
uri = URI.parse('https://www.googleapis.com/drive/v2/files')

mime_types = MIME_TYPE_ICONS.keys << 'application/vnd.google-apps.folder'
query = "trashed=false and (#{mime_types.map { |type| "mimeType='#{type}'" }.join(' or ')})"
if custom = ENV['custom_query']
query = "(#{query}) and (#{custom})"
end

parms = {
'q' => "trashed=false and (mimeType='application/vnd.google-apps.folder' or #{MIME_TYPE_ICONS.keys.map { |type| "mimeType='#{type}'" }.join(' or ')})",
'q' => query,
'fields' => 'nextPageToken,items(id,title,alternateLink,mimeType,parents(id,isRoot),modifiedDate,lastModifyingUserName)',
'maxResults' => 1000,
}
Expand Down

0 comments on commit 048b57b

Please sign in to comment.