class Riserva::Storage::GoogleDrive

Public Instance Methods

clean() click to toggle source
# File lib/riserva/storage/google_drive.rb, line 23
def clean
  return unless time_to_keep

  session.files(q: ['createdTime < ?', time_to_keep.ago]).each do |file|
    file.delete(true)
  end
end
download(remote_file, local_file) click to toggle source
# File lib/riserva/storage/google_drive.rb, line 11
def download(remote_file, local_file)
  file = session.file_by_title(remote_file.to_s)
  file.download_to_file(local_file)
end
upload(local_file, remote_file) click to toggle source
# File lib/riserva/storage/google_drive.rb, line 7
def upload(local_file, remote_file)
  session.upload_from_file(local_file.to_s, remote_file, convert: false)
end
verify(remote_file, local_file) click to toggle source
# File lib/riserva/storage/google_drive.rb, line 16
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 Instance Methods

session() click to toggle source
# File lib/riserva/storage/google_drive.rb, line 33
def session
  @session ||= ::GoogleDrive::Session.from_service_account_key(secrets)
end