Google Forms Ruby Gem
When you need to post something to a Google Form from your ruby script.
How it works
I got tired of copypasting field names from Google Forms to my code and created a gem that gets the whole Google Form page using curb
and grabs input names from it using Nokogiri.
Installation
Add to your Gemfile
:
gem 'google_forms'
and run bundle
, or just:
gem install google_forms
Usage
Assuming you have a form to fill with your script:
Make sure your fields don't have any validations
Add the gem to your project:
require 'google_forms'
Pass a Google Form id or an url (yes, short url will work too):
form = GoogleForm.new('https://forms.gle/QvQbSm5Gxg7GNwBq9')
=> #<GoogleForm:12134640 @id=\"1FAIpQLScgwPtuN0aMJ6NLztq2kTZ4pdebxcrE_99Ax6I0fQtBwaT7fA\">
Get the list of input fields:
form.inputs
=> [#<GoogleFormInput:... @input_type="text", @label="id", @name="entry.462465405">, ...]
form.inputs.map(&:label)
=> ["id", "username", "first_name", "last_name"]
Fill in the inputs (using labels):
form.id = 12345
form.username = 'installero'
form.first_name = 'Vadim'
form.last_name = 'V'
And post the response:
form.post
Or do it all in one line:
form.post(id: 12345, username: 'installero', first_name: 'Vadim', last_name: 'V')
Yes, you can combine:
form.id = 12345
form.post(username: 'installero', first_name: 'Vadim', last_name: 'V')