A simple but powerful ruby API wrapper for Google's services.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install google-api
Before Using this Gem
Google API depends on you to authenticate each user with Google via OAuth2. We don't really care how you get authenticated, but you must request access to a User's Google account and save the Refresh Token, Access Token, and Access Token Expiration Date.
As a starting point, we recommend using Omniauth for most authentication with Ruby. It is a great gem, and integrates seemlessly with most SSO sites, including Google. Check out the Wiki for more information.
This gem couldn't be easier to set up. Once you have a Client ID and Secret from Google (check out the Wiki for instructions on how to get these), you just need to add an initializer to your application that looks like this:
GoogleAPI.configure do |config| config.client_id = '[CLIENT ID]' config.client_secret = '[CLIENT SECRET]' config.encryption_key = '[ENCRYPTION KEY]' end
We make it easy to set up an object as 'Google API Ready', giving you a couple of conveniences. For starters, if you have a User model, add the OAuth2 fields to your database migration:
create_table :users do |t| t.string :email_address, :first_name, :last_name t.oauthable t.timestamps end
...and methods to the Model:
class User < ActiveRecord::Base oauthable end
Once you have set that up, making a request to the Google API is as simple as:
user = User.find(1) user.google.drive.files.list
This will fetch all files and folders in the user's Google Drive and return them in an array of hashes.
What Google APIs has this gem been tested against?
Help! I need to use an API that is not yet tested
Open an issue, and we will do our best to fully test the API you need. Or, you can submit a pull request with any necessary updates!
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Added some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request