alexfarrill / GoogleApps

Ruby library for simple GoogleApps API tasks like creating a calendar, spreadsheet, or document

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GoogleApps

This is really just a sketch of a library at the moment, but it will let you do some basic things with the GoogleApps API. I’ve built this with the idea of using it in a Rails project because that’s what I’m using it for, but it doesn’t have to be so…

If you’re interested in building this out more, send me an email or just fork the project.

Requirements

  • HTTParty v0.4.2 & Crack

  • A GoogleApps account (N.B. it’s nice to have separate ones for dev and prod)

Quick setup

  • gem install dependencies (see requirements above)

  • Copy google_apps.rb to your Rails project lib directory

  • Make a file: config/google_apps.yml with settings for your environments,

    e.g.:

    development:
      email: soandso@gmail.com
      password: pass

(Alternatively, or if you’re not using Rails, just edit the google_apps.rb file so that @@config is a hash with this info.)

Examples

Calendars API

List calendars on your account

g = GoogleApps::CalendarsConnection.new
calendars = g.calendars

List events in a calendar

calendar = g.calendars.first
calendar.events

Add an event to my default calendar

calendar_event = g.create_event! :title => "My Event", :description => "Behind the scenes", :starts_at => Time.zone.now, :ends_at => 1.day.from_now

Add a recurring event

calendar_event = g.create_event! :title => "My Event", :description => "Behind the scenes", :starts_at => Time.zone.now, :ends_at => 1.hour.from_now, :recurrence => { :freq => :daily, :until => 1.week.from_now }

Add an event to a specific calendar

calendar = g.calendars.detect{|cal| cal.title == "My Public Calendar"}
calendar.create_event! :title => "My Event", :description => "Open to the public", :starts_at => Time.zone.now, :ends_at => 1.day.from_now

Update an event

calendar_event.update! :title => "Cool Event", :description => "Now with more fizz... BAM!", :starts_at => Time.zone.now, :ends_at => 1.day.from_now

Destroy an event

calendar_event.destroy

Spreadsheets API

Create a spreadsheet

g = GoogleApps::SpreadsheetsConnection.new
gs = g.create! :title => "My Cool Spreadsheet"

Add collaborators to a spreadsheet

g.add_user gs, ["ghostfacekillah@example.com", "raekwonthechef@example.com"], :writer

Get a link to the spreadsheet

gs.link

Improvements needed

  • A better test framework for testing expected behavior against XML responses from Google

  • Make connections less wasteful by using ETags and pooling

  • Break out google_apps.rb into utility-specific files, e.g. google_apps_connect.rb

Gems that depend on GoogleApps

  • acts_as_google_calendar

About

Ruby library for simple GoogleApps API tasks like creating a calendar, spreadsheet, or document


Languages

Language:Ruby 99.6%Language:JavaScript 0.4%