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

Google Sheets support #164

Closed
jamie opened this issue Jul 20, 2016 · 2 comments
Closed

Google Sheets support #164

jamie opened this issue Jul 20, 2016 · 2 comments

Comments

@jamie
Copy link

jamie commented Jul 20, 2016

Just looking for some quick and dirty google sheets support.

If you have a doc that has Link Sharing on, you can get a CSV download link from a fairly trivial URL transform:

# Browser URL
https://docs.google.com/spreadsheets/d/{doc_id}/edit#gid={sheet_id}
# CSV URL
https://docs.google.com/spreadsheets/d/{doc_id}/export?format=csv&id={doc_id}&gid={sheet_id}

I'm using the following hack right now to load this data, but it'd be nice if I could just say data = Squib.google_sheet(url: "...")

require 'open-uri'
sheet_uri = "https://docs.google.com/spreadsheets/d/.../edit#gid=..."
csv_uri = sheet_uri.gsub(%r{/d/(.*)/edit#}, '/d/\1/export?format=csv&id=\1&')
csv = open(csv_uri).read

data = Squib.csv(data: csv)
@andymeneely
Copy link
Owner

See #49. I'm not planning on supporting Google Sheets anytime soon.

Google made my (work) life a pain when they kept changing their APIs and behaviors without warning. I used to use Ruby to connect to Google Spreadsheets, but they made it way more difficult to do it right without the security hole of turning on link sharing. Technically, the feature you're using is undocumented and unsupported by Google, which means Squib could break at any time if I ship with it. Instead, we can just keep code snippets like this around with the understanding that Google does what Google does.

If you don't like having code like that in your main Squib source code, you can always just declare a Ruby method and put it in another file. I like to have a squib_helpers.rb in my code, like this:

https://github.com/andymeneely/project-timber-wolf/blob/master/src/characters.rb#L2
and
https://github.com/andymeneely/project-timber-wolf/blob/master/src/helpers.rb

@jamie
Copy link
Author

jamie commented Jul 20, 2016

That's fair. Thanks for the response.

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

2 participants