Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation, examples, or similar #4

Open
Midnighter opened this issue Jul 5, 2016 · 3 comments
Open

Documentation, examples, or similar #4

Midnighter opened this issue Jul 5, 2016 · 3 comments

Comments

@Midnighter
Copy link

Midnighter commented Jul 5, 2016

The documentation on this gem is very slim. How can I actually use this? I can successfully access my Google spreadsheet using google_drive but how do I get it to work with roo-google?

The following code creates below error.

require 'roo-google'

spread = Roo::Spreadsheet.open('uuid', extension: :google)

spread.sheets
set access token
/var/lib/gems/2.3.0/gems/roo-google-1.0.0/lib/roo/google.rb:26:in `worksheets': undefined method `spreadsheet_by_key' for nil:NilClass (NoMethodError)
        from /var/lib/gems/2.3.0/gems/roo-google-1.0.0/lib/roo/google.rb:30:in `sheets'
        from events.seeds.rb:5:in `<main>'

Do I need to create a session first using google_drive? Please advise.

I should probably add versions:

ruby 2.3.1p112 (2016-04-26)
roo-google-1.0.0
roo-2.4.0
google_drive-1.0.6
@ontl
Copy link

ontl commented Jul 9, 2016

Pretty please? Just an example or two of how to authenticate and read the contents of a sheet would be awesome. Thanks!

@allenwyma
Copy link

yeah, i believe there's a problem with this gem. Not sure what, though. My google OAuth token doesn't seem to be taking in correctly through google_drive.

@Kaakati
Copy link

Kaakati commented Jan 4, 2021

I found this online:

require 'roo'
require 'date'


def fetch_spreadsheet_data()
 google_user = "you@gmail.com"
 google_password = "YOUR-PASSWORD"

  workbook = Roo::Google.new("XXXXXXX YOUR DOCUMENT ID XXXX_XXXXXXXXXXX",user: google_user, password: google_password)
  workbook.default_sheet = workbook.sheets[0]
 
   # Create a hash of the headers so we can access columns by name (assuming row
   # 1 contains the column headings). This will also grab any data in hidden
   # columns.
  headers = Hash.new
  workbook.row(1).each_with_index {|header,i|
 headers[header] = i
 }

   graph_data = []
 # Iterate over the rows using the `first_row` and `last_row` methods. Skip
  # the header row in the range.
  ((workbook.first_row + 1)..workbook.last_row).each do |row|
     value = workbook.row(row)[headers['Value']]
   date = workbook.row(row)[headers['Date']]     
    timestamp = DateTime.parse(date).to_time.to_i
   graph_data << { x: timestamp, y: value }
  end
  send_event('YOUR GRAPH WIDGET NAME', points: graph_data.last(50))
end

SCHEDULER.every '5m' do
    fetch_spreadsheet_data()
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants