Sha256: a4042c4aaa16cffec4b0127e41d046ea7fb73746757d07a3511ae49098b92baa

Contents?: true

Size: 712 Bytes

Versions: 5

Compression:

Stored size: 712 Bytes

Contents

# frozen_string_literal: true

require 'google_drive'

module Riserva::Storage
  class GoogleDrive < ApplicationStorage
    def upload(local_file, remote_file)
      session.upload_from_file(local_file.to_s, remote_file, convert: false)
    end

    def download(remote_file, local_file)
      file = session.file_by_title(remote_file.to_s)
      file.download_to_file(local_file)
    end

    def verify(remote_file, local_file)
      file = session.file_by_title(remote_file.to_s)
      checksum = Digest::MD5.hexdigest(IO.read(local_file))

      file.md5_checksum == checksum
    end

    private

    def session
      @session ||= ::GoogleDrive::Session.from_service_account_key(secrets)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
riserva-0.1.4 lib/riserva/storage/google_drive.rb
riserva-0.1.3 lib/riserva/storage/google_drive.rb
riserva-0.1.2 lib/riserva/storage/google_drive.rb
riserva-0.1.1 lib/riserva/storage/google_drive.rb
riserva-0.1.0 lib/riserva/storage/google_drive.rb