google-drive-ruby
google-drive-ruby copied to clipboard
Pass the field parameter to the underlying Drive API
HI there
thank you for your gem.
http://www.rubydoc.info/gems/google_drive/GoogleDrive/Session#collection_by_title-instance_method
I"m using the collection_by_title method. It returns a full payload, but all I really want is one or two specific fields.
If I am understanding correctly, to change the method would require one to add a block. (or one could the files method of the session object and pass in a mimetype paramter for folders).
am i understanding this correctly. Should i have a go making a pull request for adding a block to the collection_by_title method? if yes, any advice re: testing much appreciated.
rgds
Ben
Thanks for the feedback.
If I am understanding correctly, to change the method would require one to add a block.
I prefer to add it as an optional parameter like this, not a block:
session.collection_by_title("foo", fields: ["title", "etag"])
The field parameter is specified here: https://github.com/gimite/google-drive-ruby/blob/master/lib/google_drive/session.rb#L189 Currently hard-coded to "*". Session#collection_by_title also calls Session#files in the end. So you can add the parameter all the way down to Session#files.
Would be great if you send a pull request for it.
That would certainly make for an interesting study.
I confess I am not quite there yet with my ruby background to grok this just yet. I want to give a genuine attempt at it though. will try over the weekend. can't guarantee success.
another question i could not quite work out. Consider the code below:
# Gets list of remote files.
session.files.each do |file|
p file.title
end
Each file has a .title attribute.
But when I look on the Google reference: there is no reference to file having a "title" attribute. where is the "title" coming from?
rgds
Ben
The title
property is defined here:
http://www.rubydoc.info/gems/google_drive/GoogleDrive/File#title-instance_method
which is alias of name
.
But I found that my previous example code was wrong. I must use name
instead of title
for fields
:
session.collection_by_title("foo", fields: ["name", "etag"])