andymeneely / squib

A Ruby DSL for prototyping card games.
http://squib.rocks
MIT License
920 stars 68 forks source link

Do we want Google Sheets integration? #49

Open andymeneely opened 9 years ago

andymeneely commented 9 years ago

Much like xlsx and csv, maybe a method to get data from Google Sheets?

Pros:

Cons:

Thoughts? Post your votes here!

evolve2k commented 9 years ago

I would love this! Im building our game with a team and we're using google sheets, I've been having to periodically download the sheets into csv and copy them to the project. This would be a great addition.

andymeneely commented 9 years ago

Thanks for the vote!

I should also point out that we had someone write up a workaround for now: http://andymeneely.github.io/squib/doc/file.README.html#Using_Google_Sheets

Let me know if it doesn't work, though. Google keeps changing its apis.

bcompter commented 9 years ago

Love the idea. I use sheets for all of my development now.

andymeneely commented 9 years ago

It's not looking good for Ruby+Google these days. Google has changed their API and usage rules a lot lately, and I haven't seen any Ruby gems make a concerted effort to keep up.

Google also now requires things like API keys and OAuth, which complicates the process much more than most Squibbers have the stomach for.

But if someone else wants to take that on, it doesn't have to integrate with Squib at all - it could just be a general exporter. I would love to be proven wrong.

yipcma commented 7 years ago

perhaps a good time to revisit this issue? https://developers.google.com/sheets/api/quickstart/ruby

yipcma commented 7 years ago

there's also this gem http://www.rubydoc.info/gems/google_drive/GoogleDrive/Spreadsheet

But basically all one needs is a in ruby way of downloading a .csv from google sheet

andymeneely commented 7 years ago

Yeah that google_drive gem is the one I was using a while back. I'm glad to see it's back to being regularly updated now.

Honestly, while I know folks would love to have this built into Squib, I'm not quite ready to support it. The OAuth steps, while simple for some folks, can be a little daunting for some and I'm not ready to put the support effort into that.

If someone wants to make this happen, it's easy enough to define your own method that works a lot like the Excel parser. You can always post that as a Gist or on this issue. Or, better yet, you can maintain your own gem called squib_google or something.

If that code gets used a lot and maintaining is easy, then I'd be willing to put it into Squib.

bbugh commented 7 years ago

You can use Publish to the web... functionality in Google Sheets to make an url that returns CSV.

In Google Sheets:

  1. File -> Publish to the web...
  2. Pick the sheet you want to publish
  3. Pick the format you want to publish (CSV in this case)
  4. Click Publish
  5. Copy the link that it generates

That link is now something you can curl or directly import from Ruby. Note that it doesn't re-publish immediately, it can take up to a minute or two, so it's not great for rapid iteration. It's usually pretty fast though.

Here's how you'd do it in Squib:

require 'net/http'
uri = URI("https://docs.google.com/spreadsheets/d/e/YOUR_GOOGLE_LINK/pub?gid=0&single=true&output=csv")
data = Squib.csv data: Net::HTTP.get(uri)

It's what I'm using and it works great.

Just say NO to Google APIs!