Sha256: 5fe382bda0cfbff14f5401c00a94c8c8ea7407f9c0b1db18cb9e0a15212eadce

Contents?: true

Size: 882 Bytes

Versions: 2

Compression:

Stored size: 882 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

    def clean
      return unless time_to_keep

      session.files(q: ['createdTime < ?', time_to_keep.ago]).each do |file|
        file.delete(true)
      end
    end

    private

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
riserva-0.1.7 lib/riserva/storage/google_drive.rb
riserva-0.1.6 lib/riserva/storage/google_drive.rb