From f6aa6b06155009be609a2e6ec171f4653dd9ed15 Mon Sep 17 00:00:00 2001 From: Steve Bazyl Date: Thu, 21 Jan 2016 17:55:48 -0800 Subject: [PATCH] Add note about hash->keyword expansion --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d32a64ed..a9b5af95f 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,7 @@ to replace. For example: ```ruby file = {id: '123', title: 'My document', labels: { starred: true }} -file = drive.insert_file(file) # Returns a Drive::File instance +file = drive.create_file(file, {}) # Returns a Drive::File instance ``` is equivalent to: @@ -150,6 +150,15 @@ file.labels = Drive::File::Labels.new(starred: true) file = drive.update_file(file) # Returns a Drive::File instance ``` +IMPORTANT: Be careful when supplying hashes for request objects. If it is the last argument to a method, ruby will interpret the hash as keyword arguments. To prevent this, appending an empty hash as an extra parameter will avoid misinterpretation. + +```ruby +file = {id: '123', title: 'My document', labels: { starred: true }} +file = drive.create_file(file) # Raises ArgumentError: unknown keywords: id, title, labels +file = drive.create_file(file, {}) # Returns a Drive::File instance +``` + + ## Authorization [OAuth 2](https://developers.google.com/accounts/docs/OAuth2) is used to authorize applications. This library uses