SYNOPSIS

 use VUser::Google::ProvisioningAPI;
 my $google = new VUser::Google::ProvisioningAPI($domain, $admin, $passwd, '2.0');

 $google->CreateUser($userName, $givenName, $familyName, $password, $quotaMB);
 my $user = $google->RetrieveUser($userName);

REQUIREMENTS

VUser::Google::ProvisioningAPI requires the following modules to be installed:

  • \*(C`LWP::UserAgent\*(C'

  • \*(C`HTTP::Request\*(C'

  • \*(C`Encode\*(C'

  • \*(C`XML::Simple\*(C'

DESCRIPTION

VUser::Google::ProvisioningAPI provides a simple interface to the Google Apps for Your Domain Provisioning \s-1API\s0. It uses the \*(C`LWP::UserAgent\*(C' module for the \s-1HTTP\s0 transport, and the \*(C`HTTP::Request\*(C' module for the \s-1HTTP\s0 request and response.

Examples

Adding a user:

use VUser::Google::ProvisioningAPI; my $google = VUser::Google::ProvisioningAPI->new('yourdomain.com', 'admin', 'your password', '2.0');

my $entry = $google->CreateUser('joeb', 'Joe', 'Blow', 'joespassword'); if (defined $entry) { print $entry->User, " created\n"; } else { die "Add failed: ".$google->{result}{reason}; }

Updating a user:

my $new_entry = VUser::Google::ProvisioningAPI::V2_0::UserEntry->new(); $new_entry->Password('heresmynewpassword'); $new_entry->GivenName('Joseph'); my $entry = $google->UpdateUser('joeb', $new_entry);

Delete a user:

my $rc = $google->DeleteUser('joeb'); if (not $rc) { die "Can't delete user: ".$google->{result}{reason}; }

CONSTRUCTOR

new ($domain, $admin, $adminpasswd)

This is the constructor for a new VUser::Google::ProvisioningAPI object. $domain is the domain name registered with Google Apps For Your Domain, $admin is an account in the above domain that has the right to manage that domain, and $adminpassword is the password for that account.

Note that the constructor will \s-1NOT\s0 attempt to perform the 'ClientLogin' call to the Google Provisioning \s-1API\s0 (see below). Authentication happens automatically when the first \s-1API\s0 call is performed. The token will be remembered for the duration of the object, and will be automatically refreshed as needed. If you want to verify that you can get a valid token before performing any operations, follow the constructor with a call to IsAuthenticated() as such:

print "Authentication OK\n" unless not $google->IsAuthenticated();

METHODS

Below are all the methods available on the object. For the Google \s-1API\s0 specific methods, see the Google \s-1API\s0 documentation for more details.

When a request is properly handed by Google's \s-1API\s0 engine, the results of the action are returned as the content of the request.

If the request fails (as determined by the \*(C`HTTP::Request\*(C' method is_success()), it could mean a couple of things. If it's a failure within the Google \s-1API\s0, the content will contain an \s-1XML\s0 encoded error message. All other \s-1HTTP\s0 errors are still possible.

Checking Authentication

IsAuthenticated()

will check if the object has been able to authenticate with Google's api engine, and get an authentication ticket. Returns 1 if successful, 0 on failure. To see why it may fail, see the $@ variable, and the $google->{results}->{reason} hash, and parse the returned page (see the 'content' and 'header' variables.)

Relogin()

Performs a login if required. Relogin() will be called but the \s-1API\s0 methods and IsAuthenticated(). You should not need to call this directly.

User Methods

These are the acutual \s-1API\s0 calls. These calls match up with the client library methods described for the .Net and Java libraries.

CreateUser($userName, $givenName, $familyName, $password, $quota, $forceChange, $hashName)

Creates a user in your Google Apps domain. The first four arguments are required. The $quota argument is optional and may not do anything unless your agreement with Google allows you to change quotas. If $forceChange is true, the user will be required to change their password after log in. $hashName, if set, must be sha-1 or md5. CreateUser() returns a \*(C`VUser::Google::ProvisioningAPI::V2_0::UserEntry\*(C' object if the request was successful and \*(C`undef\*(C' otherwise.

RetrieveUser($userName)

Get the passed user from Google. Returns a \*(C`VUser::Google::ProvisioningAPI::V2_0::UserEntry\*(C' object.

RetrieveAllUsers()

Returns a list of all users in your domain. The entries are \*(C`VUser::Google::ProvisioningAPI::V2_0::UserEntry\*(C' objects.

RetrievePageOfUsers($startUser)

Google Provisioning \s-1API\s0 2.0 supports returning lists of users 100 at a time. $startUser is optional. When used, it will be the list will start at that user. Otherwise, it will return the first 100 users. RetrievePageOfUsers() returns a list of \*(C`VUser::Google::ProvisioningAPI::V2_0::UserEntry\*(C' objects.

UpdateUser($userName, $newUserEntry)

$userName is the mandatory name of the user account. $newUserEntry is a \*(C`VUser::Google::ProvisioningAPI::V2_0::UserEntry\*(C' object with the changes to the account. You only need to set the elements of $newUserEntry that are being changed. Note: According to the Google \s-1API\s0 docs, you should not set the password unless you are actually changing the password.

SuspendUser($userName)

$userName is the name of the user that you want to suspend. Returns a \*(C`VUser::Google::ProvisioningAPI::V2_0::UserEntry\*(C' object if successful.

RestoreUser($userName)

Unsuspend the user's account. $userName is required. Returns a \*(C`VUser::Google::ProvisioningAPI::V2_0::UserEntry\*(C' object if successful.

DeleteUser($userName)

$userName is the required user name to delete. Returns '1' on success.

Nickname methods

CreateNickname($userName, $nickName)

Creates a nickname (or alias) for a user. $userName is the existing user and $nickName is the user's new nickname. Returns a \*(C`VUser::Google::ProvisioningAPI::V2_0::NicknameEntry\*(C' object on success.

RetrieveNickname($nickName)

Returns a \*(C`VUser::Google::ProvisioningAPI::V2_0::NicknameEntry\*(C' if the $nickName exists.

RetrieveNicknames($userName)

Get all nicknames for $userName. Returns a list of \*(C`VUser::Google::ProvisioningAPI::V2_0::NicknameEntry\*(C' objects.

RetrieveAllNicknames()

Get all of the nick names for your domain. Returns a list of \*(C`VUser::Google::ProvisioningAPI::V2_0::NicknameEntry\*(C' objects.

RetrievePageOfNicknames($startNick)

Get 100 of the nick names for your domain. If $startNick is defined, the list will start with that nick name, otherwise, the first 100 nicks will be returned. Returns a list of \*(C`VUser::Google::ProvisioningAPI::V2_0::NicknameEntry\*(C' objects.

DeleteNickname($nickName)

Delete $nickName from your domain. Returns 1 if the request succeeds.

Email list methods

CreateEmailList($listName)

Create an email list named $listName. Returns a \*(C`VUser::Google::ProvisioningAPI::V2_0::EmailListEntry\*(C' on success.

RetrieveEmailLists($recipient)

Get a list of all local email lists that $recipient is subscribed to. $recipient is limited to users at your domain. Returns a list of \*(C`VUser::Google::ProvisioningAPI::V2_0::EmailListEntry\*(C' objects.

RetrieveAllEmailLists()

Get a list of all email lists for your domain. Returns a list of \*(C`VUser::Google::ProvisioningAPI::V2_0::EmailListEntry\*(C' objects.

RetrievePageOfEmailLists($startList)

Get a single page (100 lists) of email lists.

DeleteEmailList($emailList)

Delete $emailList from your domain. Returns 1 on success.

AddRecipientToEmailList($recipient, $emailList)

Adds a recipient to a mail list. $recipient is the address you want to add and $emailList is the list to add to. Returns a \*(C`VUser::Google::ProvisioningAPI::V2_0::EmailListRecipientEntry\*(C' object on success.

RetrieveAllRecipients($emailList)

Get a list of the recipients of the specified email list. Returns a list of \*(C`VUser::Google::ProvisioningAPI::V2_0::EmailListRecipientEntry\*(C' objects.

RetrievePageOfRecipients($emailList, $startRecpt)

Get a page of recipients for that given list (\*(C`$emailList)\*(C' starting with $startRecpt or the beginning if $startRecpt is not defined. Returns a list of \*(C`VUser::Google::ProvisioningAPI::V2_0::EmailListRecipientEntry\*(C' objects.

RemoveRecipientFromEmailList($recipient, $emailList)

Remove $recipient from the given email list ($emailList). Returns 1 in success.

ACCESSING RESULTING DATA

Most \s-1API\s0 calls return an object so that you don't have to screw around with the \s-1XML\s0 data. The parsed \s-1XML\s0 (by XML::Simple) is available in \*(C`$google-\*(C'{result}>.

EXPORT

None by default.

RELATED TO VUser::Google::ProvisioningAPI::V2_0…

The perldocs for VUser::Google::ProvisioningAPI::V2_0::UserEntry; VUser::Google::ProvisioningAPI::V2_0::NicknameEntry; VUser::Google::ProvisioningAPI::V2_0::EmailListEntry; and VUser::Google::ProvisioningAPI::V2_0::EmailListRecipientEntry.

The official Google documentation can be found at http://code.google.com/apis/apps-for-your-domain/google_apps_provisioning_api_v2.0_reference.html

http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html

For support, see the Google Group at http://groups.google.com/group/apps-for-your-domain-apis

For additional support specific to this modules, email me at johan at reinalda dot net.

AUTHOR

Johan Reinalda, johan at reinalda dot net Randy Smith, perlstalker at vuser dot org

COPYRIGHT AND LICENSE

Copyright (C) 2006 by Johan Reinalda, johan at reinalda dot net Copyright (C) 2007 by Randy Smith, perlstalker at vuser dot org

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available.

If you make useful modification, kindly consider emailing then to me for inclusion in a future version of this module.