Google apps provisioning API ruby library

This is a copy of the Google Apps provisioning API taken from http://code.google.com/p/gdatav2rubyclientlib/ v 1.2 (latest)

BEFORE USE Enable the API on Google Admin Panel

Domain Settings -> User Settings -> Enable Provisionin API

https://www.google.com/a/cpanel/[YOUR_DOMAIN.com]/DomainSettingsUserSettings

Example

 #!/usr/bin/ruby
 require 'gappsprovisioning/provisioningapi'
 include GAppsProvisioning
 adminuser = "[email protected]"
 password  = "PaSsWo4d!"
 myapps = ProvisioningApi.new(adminuser,password)

 new_user = myapps.create_user("jsmith", "john", "smith", "12345678", nil, "2048")
 puts new_user.family_name
 puts new_user.given_name

Want to update a user ?

 user = myapps.retrieve_user('jsmith')
 user_updated = myapps.update_user(user.username, user.given_name, user.family_name, nil, nil, "true")

Want to add an alias or nickname ?

 new_nickname = myapps.create_nickname("jsmith", "john.smith")

Want to add an email forwarding (thanks to Scott Jungling) ?

 new_forwarding = myapps.create_email_forwarding("jsmith", "[email protected]", "KEEP")

Want to manage groups ? (i.e. mailing lists)

 new_group = myapps.create_group("sales-dep", ['Sales Departement'])
 new_member = myapps.add_member_to_group("jsmith", "sales-dep")
 new_owner = myapps.add_owner_to_group("jsmith", "sales-dep")
 #     (ATTENTION: a owner is added only if it's already member of the group!)

Want to handle errors ?

 begin
         user = myapps.retrieve_user('noone')
         puts "givenName : "+user.given_name, "familyName : "+user.family_name, "username : "+user.username
         puts "admin ? : "+user.admin
 rescue GDataError => e
         puts "errorcode = "+e.code, "input : "+e.input, "reason : "+e.reason
 end

Character Usage

  • Usernames may contain letters (a-z), numbers (0-9), dashes (-), underscores (_), and periods (.), and may not contain an equal sign (=) or brackets (<,>). They can't contain more than one period in a row.

  • Passwords may contain any combination of characters, but a minimum of 8 characters is required.

  • First and last names support unicode/UTF-8 characters, and may contain spaces, letters (a-z), numbers (0-9), dashes (-), forward slashes (/), and periods (.), with a maximum of 40 characters.

-Characters that cannot be part of a name include: !, #, $, %, &, (, ), *, +, /, ?, \, ^, |, ~

Testing

Google API testing is hard. There are multiple server side rules that make testing hard, such as deleting a user and creating it back requires you to wait for 5 days.

Instead we simply use VCR to verify that code interprets correctly and that the codes are being made. If you want to "really" test the API you need a username and password for a domain to run your tests.