googleapis/google-api-ruby-client

uninitialized constant Google::Apis::Core::DownloadCommand::Pathname

Closed this issue · 2 comments

Environment details

  • OS: macOS 13.5.2
  • Ruby version: 3.3.0
  • Gem name and version: google-apis-drive_v3 0.49.0

Steps to reproduce

  1. Create a minimal script file (example.rb) that does not require 'pathname'.
  2. run ruby example.rb

Code example

require 'google/apis/drive_v3'

scope = Google::Apis::DriveV3::AUTH_DRIVE_READONLY
drive = Google::Apis::DriveV3::DriveService.new
drive.authorization = Google::Auth::ServiceAccountCredentials.make_creds(json_key_io: File.open('./google_auth.json'), scope: scope)
response = drive.get_file('some_id', download_dest: './test.txt')

The script will fail with google-apis-core-0.14.0/lib/google/apis/core/download.rb:38:in `prepare!': uninitialized constant Google::Apis::Core::DownloadCommand::Pathname (NameError).

This bug was introduced in #17120, there should be probably
require 'pathname' in lib/google/apis/core/download.rb.

It can be easily fixed on the client side by adding require 'pathname', but it should not be necessary

Hi @SimonSebechlebsky,
I looked into this issue and I was able to download the files without issues.

require 'google/apis/drive_v3'

drive_service = Google::Apis::DriveV3::DriveService.new
drive_service.authorization = Google::Auth.get_application_default(
  'https://www.googleapis.com/auth/drive')

drive_service.list_files.files.each do |f|
  drive_service.get_file(f.id, download_dest: "/tmp/#{f.id}")
end

Gemfile

<     google-apis-drive_v3 (0.49.0)
<       google-apis-core (>= 0.14.0, < 2.a)

Can you try this and see if it works for you? Or did you find any solution for it?

@SimonSebechlebsky - This should be fixed in 0.14.1. Please test with that.