Class: Spodunk::Connection::GDrive

Inherits:
Base
  • Object
show all
Defined in:
lib/spodunk/connections/gdrive.rb

Instance Attribute Summary

Attributes inherited from Base

#session, #spreadsheet

Instance Method Summary collapse

Methods inherited from Base

#load_table, #real_tables, #save_row, #save_table, #table, #tables

Constructor Details

#initialize(creds, sheet_opts = {}) ⇒ GDrive

the interface between Hash objects and Google Spreadsheets



7
8
9
10
11
12
13
14
15
# File 'lib/spodunk/connections/gdrive.rb', line 7

def initialize(creds, sheet_opts={})
  # old style auth
  if creds[:email] && creds[:password]
    @session = GoogleDrive. creds[:email], creds[:password]
  end
  @spreadsheet = load_spreadsheet(sheet_opts)

  super
end

Instance Method Details

#load_spreadsheet(opts) ⇒ Object



23
24
25
26
27
28
29
# 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) ⇒ Object



33
34
35
36
37
38
# 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