lib/pg_drive/uploader.rb in pg_drive-0.1.2 vs lib/pg_drive/uploader.rb in pg_drive-0.2.0

- old
+ new

@@ -3,27 +3,27 @@ Drive = Google::Apis::DriveV2 AUTH_SCOPE = "https://www.googleapis.com/auth/drive".freeze RETRY_COUNT = 3 class << self - def call(content) + def call(pipe) drive = Drive::DriveService.new drive.authorization = credentials app_name = Rails.application.class.parent_name drive.insert_file( - Drive::File.new(title: "backup-#{app_name}-#{Time.now.to_i}"), - upload_source: gzip(content), - content_type: GZIP_MIME_TYPE, + Drive::File.new(title: "#{app_name}-#{Time.now.utc.iso8601}.dmp"), + upload_source: pipe, + content_type: BINARY_MIME_TYPE, options: { retries: RETRY_COUNT } ) end - def gzip(string) - gzipped_io = StringIO.new - writer = Zlib::GzipWriter.new(gzipped_io) - writer.write(string) - writer.close - StringIO.new(gzipped_io.string) + def authorizer + Google::Auth::UserAuthorizer.new( + Uploader.client_id, + Uploader::AUTH_SCOPE, + nil + ) end def client_id Google::Auth::ClientId.new(google_key, google_secret) end