0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Simple Google Drive file uploader with autocreating required folders
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Build Status

SimpleGdrive

from this example

Simple Google Drive file uploader

Creates a required folder and all its parents like mkdir_p. For example:

MyMoney/<year>/<month>/<type>/money.csv

Installation

Add this line to your application's Gemfile:

gem 'simple_gdrive'

And then execute:

$ bundle

Or install it yourself as:

$ gem install simple_gdrive

Usage with Rails

  1. Create client_secrets.json using this wizard

  2. Add the following initializer to config/initializers

SimpleGdrive.configure do |config|  
  config.client_secrets_file = Rails.root.join('config', 'client_secrets.json') # required
  config.base_folder_id = '14lJD-WCxgCd9JxkBnsJktXhw0XrwrsLD' # required
  
  config.app_name = 'My app' # optional, default "GDrive Simple Uploader"
  config.credential_file = Rails.root.join('config', 'credentials.yaml') # optional, default ~/.credentials/gdrive-uploader.yaml  
end
  1. Call Authorizer.call in console and follow instructions to create credentials.yaml.

File upload

SimpleGdrive.upload '2018/01/MyMoney/money.csv', 'money.csv'

folder id:
folder_id

import local csv to google drive table:

CSV.open(tempfile_path, 'w', col_sep: "\t") do |output|
  output << ...
  ...
end

SimpleGdrive.upload 'my/reports/folder/report', 
                    tempfile_path, 
                    content_type: 'text/csv',
                    mime_type: 'application/vnd.google-apps.spreadsheet' 

Folder clear

removes all files and folders in base folder

SimpleGdrive.clear

option move_to_trash, default: false

Trash clear

clears the user's trash bin

SimpleGdrive.clear_trash

Known issues

  • incorrect behaviour with cyrillic symbols in filenames:
SimpleGdrive.upload 'Расходы/01/money.csv', 'money.csv'

License

The gem is available as open source under the terms of the MIT License.