• Stars
    star
    1,744
  • Rank 25,625 (Top 0.6 %)
  • Language
    Ruby
  • License
    Other
  • Created about 12 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Ruby library to read/write files/spreadsheets in Google Drive/Docs.

google-drive-ruby Build Status

This is a Ruby library to read/write files/spreadsheets in Google Drive/Docs.

NOTE: This is NOT a library to create Google Drive App.

There are some incompatible API changes. See MIGRATING.md.

Add this line to your application's Gemfile:

gem 'google_drive'

And then execute:

$ bundle

Or install it yourself as:

$ gem install google_drive

If you need system wide installation, execute below:

$ sudo gem install google_drive

Authorization

Follow one of the options in Authorization to construct a session object. The example code below assumes "On behalf of you" option.

Example to read/write files in Google Drive

require "google_drive"

# Creates a session. This will prompt the credential via command line for the
# first time and save it to config.json file for later usages.
# See this document to learn how to create config.json:
# https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md
session = GoogleDrive::Session.from_config("config.json")

# Gets list of remote files.
session.files.each do |file|
  p file.title
end

# Uploads a local file.
session.upload_from_file("/path/to/hello.txt", "hello.txt", convert: false)

# Downloads to a local file.
file = session.file_by_title("hello.txt")
file.download_to_file("/path/to/hello.txt")

# Updates content of the remote file.
file.update_from_file("/path/to/hello.txt")

Example to read/write spreadsheets

require "google_drive"

# Creates a session. This will prompt the credential via command line for the
# first time and save it to config.json file for later usages.
# See this document to learn how to create config.json:
# https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md
session = GoogleDrive::Session.from_config("config.json")

# First worksheet of
# https://docs.google.com/spreadsheet/ccc?key=pz7XtlQC-PYx-jrVMJErTcg
# Or https://docs.google.com/a/someone.com/spreadsheets/d/pz7XtlQC-PYx-jrVMJErTcg/edit?usp=drive_web
ws = session.spreadsheet_by_key("pz7XtlQC-PYx-jrVMJErTcg").worksheets[0]

# Gets content of A2 cell.
p ws[2, 1]  #==> "hoge"

# Changes content of cells.
# Changes are not sent to the server until you call ws.save().
ws[2, 1] = "foo"
ws[2, 2] = "bar"
ws.save

# Dumps all cells.
(1..ws.num_rows).each do |row|
  (1..ws.num_cols).each do |col|
    p ws[row, col]
  end
end

# Yet another way to do so.
p ws.rows  #==> [["fuga", ""], ["foo", "bar]]

# Reloads the worksheet to get changes by other clients.
ws.reload

New BSD Licence.

Ruby 2.0.0 or later. Checked with Ruby 2.4.1.

Hiroshi Ichikawa

More Repositories

1

web-socket-js

HTML5 Web Socket implementation powered by Flash
JavaScript
2,735
star
2

web-socket-ruby

HTML5 Web Socket server/client implementation in Ruby
Ruby
376
star
3

google-spreadsheet-ruby

Ruby library to read/write Google Spreadsheet
Ruby
302
star
4

moji

Ruby library for character type classification/conversion for Japanese
Ruby
86
star
5

android-native-exe-demo

Demo app to run native executable on Android app
Java
56
star
6

tweet-search-stream

Real time Twitter search using Twitter Streaming API, hosted at http://tweet-search-stream.gimite.net/
JavaScript
49
star
7

mjai

Game server for Japanese Mahjong AI.
Ruby
47
star
8

mjai-manue

Japanese Mahjong AI.
CoffeeScript
34
star
9

hrwt

Ruby VM on JavaScript (based on HotRuby) + RPC.
Ruby
30
star
10

web-irc-util

Web-based IRC client (based on QuickIRC2) + IRC log viewer used in irc.gimite.net.
Ruby
11
star
11

tx-ruby

Ruby 1.8/1.9 binding of Tx, a library for a compact trie data structure.
Ruby
10
star
12

android-jatts

Japanese TTS for Android, using Galatea Talk in server side
Java
8
star
13

kanjy-wave

Google Wave Robot to perform Japanese IME using Social IME API.
Python
6
star
14

mail-speaks

Android app to notify new emails with voice
Java
5
star
15

em-fiber-utils

Provides concurrent version of each() which works in EventMachine + Fiber environment.
Ruby
3
star
16

touchauth_demo

JavaScript
2
star
17

gimite-tools

Unix commands for my personal use.
Ruby
2
star
18

gae-rest-uploader

An uploader which runs on Google AppEngine with a simple REST API.
Python
2
star
19

MjaiClients

Mahjong AI clients for Mjai
Java
2
star
20

gimite.github.io

CSS
1
star
21

gimite-test

Gimite's testing repository.
HTML
1
star
22

kantan-kensaku

Automatically exported from code.google.com/p/kantan-kensaku
Java
1
star