ip2k / google-api-ruby-client

Automatically exported from code.google.com/p/google-api-ruby-client
Apache License 2.0
0 stars 0 forks source link

Uploading media with hash parameters raises TypeError exception #54

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create an instance of Google::APIClient::UploadIO
2. Execute instance using a hash for the parameters argument

sample code:
tempfile=File.new('test.pdf','w')
client = Google::APIClient.new
client.authorization.client_id = #your id
client.authorization.client_secret = #your secret
client.authorization.access_token = #your token
drive = client.discovered_api('drive', 'v2')
media = Google::APIClient::UploadIO.new(tempfile, "application/pdf")
file = drive.files.insert.request_schema.new({
      'title'       => "some file.pdf",
      'description' => "description",
      'mimeType'    => "application/pdf"
    })
media = Google::APIClient::UploadIO.new(tempfile, "application/pdf")
result = client.execute(
      :api_method => drive.files.insert,
      :body_object => file,
      :media => media,
      :parameters => {
        'uploadType' => 'multipart',
        'alt' => 'json'})
2.
3.

What is the expected output? What do you see instead?
Expected output should be a success response. Instead, I get an error, 
"TypeError: can't convert String into Integer"

What version of the product are you using? On what operating system?
0.4.5 on Mac OSX 10.7.4

Please provide any additional information below.
The change to Google::APIClient::Reference 
(http://code.google.com/p/google-api-ruby-client/source/diff?spec=svne77169a7f4b
b0097a8e1900b931e78abb4c82070&r=992a698b0a9def23ffd2067cc18545ad1e1b8391&format=
side&path=/lib/google/api_client/reference.rb&old_path=/lib/google/api_client/re
ference.rb&old=3bc7d52764c7dc6d7561e26974bdd515b9d7da98) converts all 
parameters to an array, but the parameters are still being treated as a hash to 
check for 'uploadType'.

I have a patch to change the line to pull the upload type from an array instead 
of a hash.

Original issue reported on code.google.com by alexche...@gmail.com on 24 Aug 2012 at 9:40

Attachments:

GoogleCodeExporter commented 9 years ago
Actually, this also errors for Array parameters.

Original comment by alexche...@gmail.com on 24 Aug 2012 at 9:52

GoogleCodeExporter commented 9 years ago
Could you provide the full stack trace?

Original comment by bobaman@google.com on 30 Aug 2012 at 8:40

GoogleCodeExporter commented 9 years ago
Here's my stack trace from console

TypeError: can't convert String into Integer
    from /Users/alexchee/.rvm/gems/ruby-1.9.3-p194/gems/google-api-client-0.4.5/lib/google/api_client/reference.rb:66:in `[]'
    from /Users/alexchee/.rvm/gems/ruby-1.9.3-p194/gems/google-api-client-0.4.5/lib/google/api_client/reference.rb:66:in `initialize'
    from /Users/alexchee/.rvm/gems/ruby-1.9.3-p194/gems/google-api-client-0.4.5/lib/google/api_client.rb:764:in `new'
    from /Users/alexchee/.rvm/gems/ruby-1.9.3-p194/gems/google-api-client-0.4.5/lib/google/api_client.rb:764:in `execute'
    from (irb):11
    from /Users/alexchee/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
    from /Users/alexchee/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
    from /Users/alexchee/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Original comment by alexche...@gmail.com on 30 Aug 2012 at 9:47

GoogleCodeExporter commented 9 years ago
Ahh, yes, OK. This has already been fixed by 0e5070c and 6795eee.

Original comment by bobaman@google.com on 30 Aug 2012 at 9:59