Skip to content

Instantly share code, notes, and snippets.

@marvinahv
Created November 17, 2012 01:16
Show Gist options
  • Save marvinahv/4092390 to your computer and use it in GitHub Desktop.
Save marvinahv/4092390 to your computer and use it in GitHub Desktop.
Google Drive JSON Table
require 'google_drive'
require 'json'
def get_json_table(key, username, password)
# Create Columns
columns = []
labels = ["id", "Manager", "ToolTip"]
labels.each do |column|
columns << { :id => "", :type => "string", :label => column }
end
# Create Rows
google_session = GoogleDrive.login(username, password)
worksheets = google_session.spreadsheet_by_key(key).worksheets()
data = worksheets[0].list.to_hash_array
rows = []
data.each do |row|
id = {
:v => row["id"],
:f => "<a href=#{row["link"]}>#{row["id"]}</a>"
}
manager = {
:v => row["manager"],
:f => nil
}
tool_tip = {
:v => row["tool_tip"],
:f => nil
}
rows << { :c => [id, manager, tool_tip] }
end
# Create Table
table = {
:cols => columns,
:rows => rows,
:p => nil
}
# Check Table
jj table
return table.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment