class Spodunk::Connection::GDrive

Public Class Methods

new(creds, sheet_opts={}) click to toggle source

the interface between Hash objects and Google Spreadsheets

Calls superclass method Spodunk::Connection::Base::new
# File lib/spodunk/connections/gdrive.rb, line 7
def initialize(creds, sheet_opts={})
  # old style auth
  if creds[:email] && creds[:password]
    @session = GoogleDrive.login creds[:email], creds[:password]
  end
  @spreadsheet = load_spreadsheet(sheet_opts)

  super
end

Public Instance Methods

load_spreadsheet(opts) click to toggle source

url is something like:

docs.google.com/spreadsheet/ccc?key=xXcdHmAt3Q3D3lDx&usp=drive_web#gid=0

# File lib/spodunk/connections/gdrive.rb, line 23
def load_spreadsheet(opts)
  if opts[:url]
    @session.spreadsheet_by_key parse_gdoc_url_for_key(opts[:url])
  elsif opts[:key]
    @session.spreadsheet_by_key(opts[:key])
  end
end
save_cell(table_id, real_row_idx, real_col_idx, val) click to toggle source

via: github.com/gimite/google-drive-ruby#how-to-use

# File lib/spodunk/connections/gdrive.rb, line 33
def save_cell(table_id, real_row_idx, real_col_idx, val)
  r_table = real_tables(table_id) # i.e. a Google Worksheet
  r_table[real_row_idx, real_col_idx] = val

  r_table.save
end

Protected Instance Methods

fetch_real_table_object(title) click to toggle source
# File lib/spodunk/connections/gdrive.rb, line 57
def fetch_real_table_object(title)
  @spreadsheet.worksheet_by_title(title)
end
init_podunk_table(gsheet, opts={}) click to toggle source

sets up the table structure

# File lib/spodunk/connections/gdrive.rb, line 51
def init_podunk_table(gsheet, opts={})
  opts[:connection] = self
  Table.new(gsheet.rows, opts)
end
parse_gdoc_url_for_key(url) click to toggle source

returns a string for key

# File lib/spodunk/connections/gdrive.rb, line 43
def parse_gdoc_url_for_key(url)
  u = URI.parse(url)
   
  key = CGI.parse(u.query)['key'][0]
end