| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- Reviewed: no -->
- <sect1 id="zend.gdata.gapps">
- <title>Using Google Apps Provisioning</title>
- <para>
- Google Apps is a service which allows domain administrators to offer
- their users managed access to Google services such as Mail, Calendar,
- and Docs & Spreadsheets. The Provisioning <acronym>API</acronym> offers a programmatic
- interface to configure this service. Specifically, this <acronym>API</acronym> allows
- administrators the ability to create, retrieve, update, and delete
- user accounts, nicknames, groups, and email lists.
- </para>
- <para>
- This library implements version 2.0 of the Provisioning <acronym>API</acronym>. Access to
- your account via the Provisioning <acronym>API</acronym> must be manually enabled for
- each domain using the Google Apps control panel. Only certain
- account types are able to enable this feature.
- </para>
- <para>
- For more information on the Google Apps Provisioning <acronym>API</acronym>, including
- instructions for enabling <acronym>API</acronym> access, refer to the <ulink
- url="http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html">Provisioning
- <acronym>API</acronym> V2.0 Reference</ulink>.
- </para>
- <note>
- <title>Authentication</title>
- <para>
- The Provisioning <acronym>API</acronym> does not support authentication via AuthSub
- and anonymous access is not permitted. All <acronym>HTTP</acronym> connections must
- be authenticated using ClientAuth authentication.
- </para>
- </note>
- <sect2 id="zend.gdata.gapps.domain">
- <title>Setting the current domain</title>
- <para>
- In order to use the Provisioning <acronym>API</acronym>, the domain being
- administered needs to be specified in all request <acronym>URI</acronym>s. In order
- to ease development, this information is stored within both the
- Gapps service and query classes to use when constructing
- requests.
- </para>
- <sect3 id="zend.gdata.gapps.domain.service">
- <title>Setting the domain for the service class</title>
- <para>
- To set the domain for requests made by the service class,
- either call <methodname>setDomain()</methodname> or specify the domain
- when instantiating the service class. For example:
- </para>
- <programlisting language="php"><![CDATA[
- $domain = "example.com";
- $gdata = new Zend_Gdata_Gapps($client, $domain);
- ]]></programlisting>
- </sect3>
- <sect3 id="zend.gdata.gapps.domain.query">
- <title>Setting the domain for query classes</title>
- <para>
- Setting the domain for requests made by query classes is
- similar to setting it for the service class-either call
- <methodname>setDomain()</methodname> or specify the domain when creating
- the query. For example:
- </para>
- <programlisting language="php"><![CDATA[
- $domain = "example.com";
- $query = new Zend_Gdata_Gapps_UserQuery($domain, $arg);
- ]]></programlisting>
- <para>
- When using a service class factory method to create a query,
- the service class will automatically set the query's domain to
- match its own domain. As a result, it is not necessary to
- specify the domain as part of the constructor arguments.
- </para>
- <programlisting language="php"><![CDATA[
- $domain = "example.com";
- $gdata = new Zend_Gdata_Gapps($client, $domain);
- $query = $gdata->newUserQuery($arg);
- ]]></programlisting>
- </sect3>
- </sect2>
- <sect2 id="zend.gdata.gapps.users">
- <title>Interacting with users</title>
- <para>
- Each user account on a Google Apps hosted domain is represented as
- an instance of <classname>Zend_Gdata_Gapps_UserEntry</classname>. This class provides
- access to all account properties including name, username,
- password, access rights, and current quota.
- </para>
- <sect3 id="zend.gdata.gapps.users.creating">
- <title>Creating a user account</title>
- <para>
- User accounts can be created by calling the
- <methodname>createUser()</methodname> convenience method:
- </para>
- <programlisting language="php"><![CDATA[
- $gdata->createUser('foo', 'Random', 'User', '••••••••');
- ]]></programlisting>
- <para>
- Users can also be created by instantiating UserEntry,
- providing a username, given name, family name, and password,
- then calling <methodname>insertUser()</methodname> on a service object to
- upload the entry to the server.
- </para>
- <programlisting language="php"><![CDATA[
- $user = $gdata->newUserEntry();
- $user->login = $gdata->newLogin();
- $user->login->username = 'foo';
- $user->login->password = '••••••••';
- $user->name = $gdata->newName();
- $user->name->givenName = 'Random';
- $user->name->familyName = 'User';
- $user = $gdata->insertUser($user);
- ]]></programlisting>
- <para>
- The user's password should normally be provided as cleartext.
- Optionally, the password can be provided as an SHA-1 digest if
- <command>login->passwordHashFunction</command> is set to 'SHA-1'.
- </para>
- </sect3>
- <sect3 id="zend.gdata.gapps.users.retrieving">
- <title>Retrieving a user account</title>
- <para>
- Individual user accounts can be retrieved by calling the
- <methodname>retrieveUser()</methodname> convenience method. If the user is
- not found, <constant>NULL</constant> will be returned.
- </para>
- <programlisting language="php"><![CDATA[
- $user = $gdata->retrieveUser('foo');
- echo 'Username: ' . $user->login->userName . "\n";
- echo 'Given Name: ' . $user->name->givenName . "\n";
- echo 'Family Name: ' . $user->name->familyName . "\n";
- echo 'Suspended: ' . ($user->login->suspended ? 'Yes' : 'No') . "\n";
- echo 'Admin: ' . ($user->login->admin ? 'Yes' : 'No') . "\n"
- echo 'Must Change Password: ' .
- ($user->login->changePasswordAtNextLogin ? 'Yes' : 'No') . "\n";
- echo 'Has Agreed To Terms: ' .
- ($user->login->agreedToTerms ? 'Yes' : 'No') . "\n";
- ]]></programlisting>
- <para>
- Users can also be retrieved by creating an
- instance of <classname>Zend_Gdata_Gapps_UserQuery</classname>, setting its username
- property to equal the username of the user that is to be
- retrieved, and calling <methodname>getUserEntry()</methodname> on a
- service object with that query.
- </para>
- <programlisting language="php"><![CDATA[
- $query = $gdata->newUserQuery('foo');
- $user = $gdata->getUserEntry($query);
- echo 'Username: ' . $user->login->userName . "\n";
- echo 'Given Name: ' . $user->login->givenName . "\n";
- echo 'Family Name: ' . $user->login->familyName . "\n";
- echo 'Suspended: ' . ($user->login->suspended ? 'Yes' : 'No') . "\n";
- echo 'Admin: ' . ($user->login->admin ? 'Yes' : 'No') . "\n"
- echo 'Must Change Password: ' .
- ($user->login->changePasswordAtNextLogin ? 'Yes' : 'No') . "\n";
- echo 'Has Agreed To Terms: ' .
- ($user->login->agreedToTerms ? 'Yes' : 'No') . "\n";
- ]]></programlisting>
- <para>
- If the specified user cannot be located a ServiceException
- will be thrown with an error code of
- <constant>Zend_Gdata_Gapps_Error::ENTITY_DOES_NOT_EXIST</constant>.
- ServiceExceptions will be covered in <xref
- linkend="zend.gdata.gapps.exceptions" />.
- </para>
- </sect3>
- <sect3 id="zend.gdata.gapps.users.retrievingAll">
- <title>Retrieving all users in a domain</title>
- <para>
- To retrieve all users in a domain, call the
- <methodname>retrieveAllUsers()</methodname> convenience method.
- </para>
- <programlisting language="php"><![CDATA[
- $feed = $gdata->retrieveAllUsers();
- foreach ($feed as $user) {
- echo " * " . $user->login->username . ' (' . $user->name->givenName .
- ' ' . $user->name->familyName . ")\n";
- }
- ]]></programlisting>
- <para>
- This will create a <classname>Zend_Gdata_Gapps_UserFeed</classname> object which
- holds each user on the domain.
- </para>
- <para>
- Alternatively, call <methodname>getUserFeed()</methodname> with no
- options. Keep in mind that on larger
- domains this feed may be paged by the server. For more
- information on paging, see <xref
- linkend="zend.gdata.introduction.paging" />.
- </para>
- <programlisting language="php"><![CDATA[
- $feed = $gdata->getUserFeed();
- foreach ($feed as $user) {
- echo " * " . $user->login->username . ' (' . $user->name->givenName .
- ' ' . $user->name->familyName . ")\n";
- }
- ]]></programlisting>
- </sect3>
- <sect3 id="zend.gdata.gapps.users.updating">
- <title>Updating a user account</title>
- <para>
- The easiest way to update a user account is to retrieve the
- user as described in the previous sections, make any desired
- changes, then call <methodname>save()</methodname> on that user. Any
- changes made will be propagated to the server.
- </para>
- <programlisting language="php"><![CDATA[
- $user = $gdata->retrieveUser('foo');
- $user->name->givenName = 'Foo';
- $user->name->familyName = 'Bar';
- $user = $user->save();
- ]]></programlisting>
- <sect4 id="zend.gdata.gapps.users.updating.resettingPassword">
- <title>Resetting a user's password</title>
- <para>
- A user's password can be reset to a new value by updating
- the <command>login->password</command> property.
- </para>
- <programlisting language="php"><![CDATA[
- $user = $gdata->retrieveUser('foo');
- $user->login->password = '••••••••';
- $user = $user->save();
- ]]></programlisting>
- <para>
- Note that it is not possible to recover a password in this
- manner as stored passwords are not made available via the
- Provisioning <acronym>API</acronym> for security reasons.
- </para>
- </sect4>
- <sect4 id="zend.gdata.gapps.users.updating.forcingPasswordChange">
- <title>Forcing a user to change their password</title>
- <para>
- A user can be forced to change their password at their
- next login by setting the
- <command>login->changePasswordAtNextLogin</command> property to
- <constant>TRUE</constant>.
- </para>
- <programlisting language="php"><![CDATA[
- $user = $gdata->retrieveUser('foo');
- $user->login->changePasswordAtNextLogin = true;
- $user = $user->save();
- ]]></programlisting>
- <para>
- Similarly, this can be undone by setting the
- <command>login->changePasswordAtNextLogin</command> property to
- <constant>FALSE</constant>.
- </para>
- </sect4>
- <sect4 id="zend.gdata.gapps.users.updating.suspendingAccount">
- <title>Suspending a user account</title>
- <para>
- Users can be restricted from logging in without deleting
- their user account by instead
- <emphasis>suspending</emphasis> their user account.
- Accounts can be suspended or restored by using the
- <methodname>suspendUser()</methodname> and
- <methodname>restoreUser()</methodname> convenience methods:
- </para>
- <programlisting language="php"><![CDATA[
- $gdata->suspendUser('foo');
- $gdata->restoreUser('foo');
- ]]></programlisting>
- <para>
- Alternatively, you can set the UserEntry's
- <command>login->suspended</command> property to
- <constant>TRUE</constant>.
- </para>
- <programlisting language="php"><![CDATA[
- $user = $gdata->retrieveUser('foo');
- $user->login->suspended = true;
- $user = $user->save();
- ]]></programlisting>
- <para>
- To restore the user's access, set the
- <command>login->suspended</command> property to
- <constant>FALSE</constant>.
- </para>
- </sect4>
- <sect4 id="zend.gdata.gapps.users.updating.grantingAdminRights">
- <title>Granting administrative rights</title>
- <para>
- Users can be granted the ability to administer your domain
- by setting their <command>login->admin</command> property to
- <constant>TRUE</constant>.
- </para>
- <programlisting language="php"><![CDATA[
- $user = $gdata->retrieveUser('foo');
- $user->login->admin = true;
- $user = $user->save();
- ]]></programlisting>
- <para>
- And as expected, setting a user's <command>login->admin</command>
- property to <constant>FALSE</constant> revokes their
- administrative rights.
- </para>
- </sect4>
- </sect3>
- <sect3 id="zend.gdata.gapps.users.deleting">
- <title>Deleting user accounts</title>
- <para>
- Deleting a user account to which you already hold a UserEntry
- is a simple as calling <methodname>delete()</methodname> on that
- entry.
- </para>
- <programlisting language="php"><![CDATA[
- $user = $gdata->retrieveUser('foo');
- $user->delete();
- ]]></programlisting>
- <para>
- If you do not have access to a UserEntry object for an
- account, use the <methodname>deleteUser()</methodname> convenience method.
- </para>
- <programlisting language="php"><![CDATA[
- $gdata->deleteUser('foo');
- ]]></programlisting>
- </sect3>
- </sect2>
- <sect2 id="zend.gdata.gapps.nicknames">
- <title>Interacting with nicknames</title>
- <para>
- Nicknames serve as email aliases for existing users. Each nickname
- contains precisely two key properties: its name and its owner. Any
- email addressed to a nickname is forwarded to the user who owns
- that nickname.
- </para>
- <para>
- Nicknames are represented as an instances of
- <classname>Zend_Gdata_Gapps_NicknameEntry</classname>.
- </para>
- <sect3 id="zend.gdata.gapps.nicknames.creating">
- <title>Creating a nickname</title>
- <para>
- Nicknames can be created by calling the
- <methodname>createNickname()</methodname> convenience method:
- </para>
- <programlisting language="php"><![CDATA[
- $gdata->createNickname('foo', 'bar');
- ]]></programlisting>
- <para>
- Nicknames can also be created by instantiating NicknameEntry,
- providing the nickname with a name and an owner, then calling
- <methodname>insertNickname()</methodname> on a service object to upload
- the entry to the server.
- </para>
- <programlisting language="php"><![CDATA[
- $nickname = $gdata->newNicknameEntry();
- $nickname->login = $gdata->newLogin('foo');
- $nickname->nickname = $gdata->newNickname('bar');
- $nickname = $gdata->insertNickname($nickname);
- ]]></programlisting>
- </sect3>
- <sect3 id="zend.gdata.gapps.nicknames.retrieving">
- <title>Retrieving a nickname</title>
- <para>
- Nicknames can be retrieved by calling the
- <methodname>retrieveNickname()</methodname> convenience method. This will
- return <constant>NULL</constant> if a user is not found.
- </para>
- <programlisting language="php"><![CDATA[
- $nickname = $gdata->retrieveNickname('bar');
- echo 'Nickname: ' . $nickname->nickname->name . "\n";
- echo 'Owner: ' . $nickname->login->username . "\n";
- ]]></programlisting>
- <para>
- Individual nicknames can also be retrieved by creating an
- instance of <classname>Zend_Gdata_Gapps_NicknameQuery</classname>, setting its
- nickname property to equal the nickname that is to be
- retrieved, and calling <methodname>getNicknameEntry()</methodname> on a
- service object with that query.
- </para>
- <programlisting language="php"><![CDATA[
- $query = $gdata->newNicknameQuery('bar');
- $nickname = $gdata->getNicknameEntry($query);
- echo 'Nickname: ' . $nickname->nickname->name . "\n";
- echo 'Owner: ' . $nickname->login->username . "\n";
- ]]></programlisting>
- <para>
- As with users, if no corresponding nickname is found a
- ServiceException will be thrown with an error code of
- <constant>Zend_Gdata_Gapps_Error::ENTITY_DOES_NOT_EXIST</constant>. Again, these
- will be discussed in <xref linkend="zend.gdata.gapps.exceptions"
- />.
- </para>
- </sect3>
- <sect3 id="zend.gdata.gapps.nicknames.retrievingUser">
- <title>Retrieving all nicknames for a user</title>
- <para>
- To retrieve all nicknames associated with a given user, call
- the convenience method <methodname>retrieveNicknames()</methodname>.
- </para>
- <programlisting language="php"><![CDATA[
- $feed = $gdata->retrieveNicknames('foo');
- foreach ($feed as $nickname) {
- echo ' * ' . $nickname->nickname->name . "\n";
- }
- ]]></programlisting>
- <para>
- This will create a <classname>Zend_Gdata_Gapps_NicknameFeed</classname> object which
- holds each nickname associated with the specified user.
- </para>
- <para>
- Alternatively, create a new <classname>Zend_Gdata_Gapps_NicknameQuery</classname>,
- set its username property to the desired user, and submit the
- query by calling <methodname>getNicknameFeed()</methodname> on a service
- object.
- </para>
- <programlisting language="php"><![CDATA[
- $query = $gdata->newNicknameQuery();
- $query->setUsername('foo');
- $feed = $gdata->getNicknameFeed($query);
- foreach ($feed as $nickname) {
- echo ' * ' . $nickname->nickname->name . "\n";
- }
- ]]></programlisting>
- </sect3>
- <sect3 id="zend.gdata.gapps.nicknames.retrievingAll">
- <title>Retrieving all nicknames in a domain</title>
- <para>
- To retrieve all nicknames in a feed, simply call the
- convenience method <methodname>retrieveAllNicknames()</methodname>
- </para>
- <programlisting language="php"><![CDATA[
- $feed = $gdata->retrieveAllNicknames();
- foreach ($feed as $nickname) {
- echo ' * ' . $nickname->nickname->name . ' => ' .
- $nickname->login->username . "\n";
- }
- ]]></programlisting>
- <para>
- This will create a <classname>Zend_Gdata_Gapps_NicknameFeed</classname> object which
- holds each nickname on the domain.
- </para>
- <para>
- Alternatively, call <methodname>getNicknameFeed()</methodname> on a
- service object with no arguments.
- </para>
- <programlisting language="php"><![CDATA[
- $feed = $gdata->getNicknameFeed();
- foreach ($feed as $nickname) {
- echo ' * ' . $nickname->nickname->name . ' => ' .
- $nickname->login->username . "\n";
- }
- ]]></programlisting>
- </sect3>
- <sect3 id="zend.gdata.gapps.nicknames.deleting">
- <title>Deleting a nickname</title>
- <para>
- Deleting a nickname to which you already hold a NicknameEntry
- for is a simple as calling <methodname>delete()</methodname> on that
- entry.
- </para>
- <programlisting language="php"><![CDATA[
- $nickname = $gdata->retrieveNickname('bar');
- $nickname->delete();
- ]]></programlisting>
- <para>
- For nicknames which you do not hold a NicknameEntry for, use
- the <methodname>deleteNickname()</methodname> convenience method.
- </para>
- <programlisting language="php"><![CDATA[
- $gdata->deleteNickname('bar');
- ]]></programlisting>
- </sect3>
- </sect2>
- <sect2 id="zend.gdata.gapps.groups">
- <title>Interacting with groups</title>
- <para>
- Google Groups allows people to post messages like an email list. Google
- is depreciating the Email List API. Google Groups provides some neat
- features like nested groups and group owners. If you want to start
- a new email lst, it is advisable to use Google Groups instead.
- Google's Email List is not compatible with Google Groups. So if you
- create an email list, it will not show up as a group. The opposite is
- true as well.
- </para>
- <para>
- Each group on a domain is represented as an instance of
- <classname>Zend_Gdata_Gapps_GroupEntry</classname>.
- </para>
- <sect3 id="zend.gdata.gapps.groups.creating">
- <title>Creating a group</title>
- <para>
- Groups can be created by calling the
- <methodname>createGroup()</methodname> convenience method:
- </para>
- <programlisting language="php"><![CDATA[
- $gdata->createGroup('friends', 'The Friends Group');
- ]]></programlisting>
- <para>
- Groups can also be created by instantiating
- GroupEntry, providing a group id and name for the group,
- then calling <methodname>insertGroup()</methodname> on a service
- object to upload the entry to the server.
- </para>
- <programlisting language="php"><![CDATA[
- $group = $gdata->newGroupEntry();
- $properties[0] = $this->newProperty();
- $properties[0]->name = 'groupId';
- $properties[0]->value = 'friends';
- $properties[1] = $this->newProperty();
- $properties[1]->name = 'groupName';
- $properties[1]->value = 'The Friends Group';
- $group->property = $properties;
- $group = $gdata->insertGroup($group);
- ]]></programlisting>
- </sect3>
- <sect3 id="zend.gdata.gapps.groups.retrieveGroup">
- <title>Retrieving an individual group</title>
- <para>
- To retrieve an individual group, call the
- <methodname>retrieveGroup()</methodname> convenience method:
- </para>
- <programlisting language="php"><![CDATA[
- $entry = $gdata->retrieveGroup('friends');
- foreach ($entry->property as $p) {
- echo "Property Name: " . $p->name;
- echo "\nProperty Value: " . $p->value . "\n\n";
- }
- ]]></programlisting>
- <para>
- This will create a <classname>Zend_Gdata_Gapps_GroupEntry</classname>
- object which holds the properties about the group.
- </para>
- <para>
- Alternatively, create a new <classname>Zend_Gdata_Gapps_GroupQuery</classname>,
- set its groupId property to the desired group id, and
- submit the query by calling <methodname>getGroupEntry()</methodname>
- on a service object.
- </para>
- <programlisting language="php"><![CDATA[
- $query = $gdata->newGroupQuery();
- $query->setGroupId('friends');
- $entry = $gdata->getGroupEntry($query);
- foreach ($entry->property as $p) {
- echo "Property Name: " . $p->name;
- echo "\nProperty Value: " . $p->value . "\n\n";
- }
- ]]></programlisting>
- </sect3>
- <sect3 id="zend.gdata.gapps.groups.retrievingAll">
- <title>Retrieving all groups in a domain</title>
- <para>
- To retrieve all groups in a domain, call the convenience
- method <methodname>retrieveAllGroups()</methodname>.
- </para>
- <programlisting language="php"><![CDATA[
- $feed = $gdata->retrieveAllGroups();
- foreach ($feed->entry as $entry) {
- foreach ($entry->property as $p) {
- echo "Property Name: " . $p->name;
- echo "\nProperty Value: " . $p->value . "\n\n";
- }
- echo "\n\n";
- }
- ]]></programlisting>
- <para>
- This will create a <classname>Zend_Gdata_Gapps_GroupFeed</classname>
- object which holds each group on the domain.
- </para>
- <para>
- Alternatively, call <methodname>getGroupFeed()</methodname> on a
- service object with no arguments.
- </para>
- <programlisting language="php"><![CDATA[
- $feed = $gdata->getGroupFeed();
- foreach ($feed->entry as $entry) {
- foreach ($entry->property as $p) {
- echo "Property Name: " . $p->name;
- echo "\nProperty Value: " . $p->value . "\n\n";
- }
- echo "\n\n";
- }
- ]]></programlisting>
- </sect3>
- <sect3 id="zend.gdata.gapps.groups.deleting">
- <title>Deleting a group</title>
- <para>
- To delete a group, call the deleteGroup() convenience method:
- </para>
- <programlisting language="php"><![CDATA[
- $gdata->deleteGroup('friends');
- ]]></programlisting>
- </sect3>
- <sect3 id="zend.gdata.gapps.groups.updating">
- <title>Updating a group</title>
- <para>
- Groups can be updated by calling the
- <methodname>updateGroup()</methodname> convenience method:
- </para>
- <programlisting language="php"><![CDATA[
- $gdata->updateGroup('group-id-here', 'Group Name Here');
- ]]></programlisting>
- <para>
- The first parameter is required. The second, third and fourth parameter,
- representing the group name, group descscription, and email permission,
- respectively are optional. Setting any of these optional parameters
- to null will not update that item.
- </para>
- </sect3>
- <sect3 id="zend.gdata.gapps.groups.retrieve">
- <title>Retrieving all groups to which a person is a member</title>
- <para>
- To retrieve all groups to which a particular person is a
- member, call the <methodname>retrieveGroups()</methodname>
- convenience method:
- </para>
- <programlisting language="php"><![CDATA[
- $feed = $gdata->retrieveGroups('baz@somewhere.com');
- foreach ($feed->entry as $entry) {
- foreach ($entry->property as $p) {
- echo "Property Name: " . $p->name;
- echo "\nProperty Value: " . $p->value . "\n\n";
- }
- echo "\n\n";
- }
- ]]></programlisting>
- <para>
- This will create a <classname>Zend_Gdata_Gapps_GroupFeed</classname>
- object which holds each group associated with the specified member.
- </para>
- <para>
- Alternatively, create a new <classname>Zend_Gdata_Gapps_GroupQuery</classname>,
- set its member property to the desired email address, and
- submit the query by calling <methodname>getGroupFeed()</methodname>
- on a service object.
- </para>
- <programlisting language="php"><![CDATA[
- $query = $gdata->newGroupQuery();
- $query->setMember('baz@somewhere.com');
- $feed = $gdata->getGroupFeed($query);
- foreach ($feed->entry as $entry) {
- foreach ($entry->property as $p) {
- echo "Property Name: " . $p->name;
- echo "\nProperty Value: " . $p->value . "\n\n";
- }
- echo "\n\n";
- }
- ]]></programlisting>
- </sect3>
- </sect2>
- <sect2 id="zend.gdata.gapps.groupMembers">
- <title>Interacting with group members</title>
- <para>
- Each member subscribed to a group is represented by an
- instance of <classname>Zend_Gdata_Gapps_MemberEntry</classname>.
- Through this class, individual recipients can be added and removed
- from groups.
- </para>
- <sect3 id="zend.gdata.gapps.groupMembers.adding">
- <title>Adding a member to a group</title>
- <para>
- To add a member to a group, simply call the
- <methodname>addMemberToGroup()</methodname> convenience method:
- </para>
- <programlisting language="php"><![CDATA[
- $gdata->addMemberToGroup('bar@somewhere.com', 'friends');
- ]]></programlisting>
- </sect3>
- <sect3 id="zend.gdata.gapps.groupMembers.check">
- <title>Check to see if member belongs to group</title>
- <para>
- To check to see if member belongs to group, simply call the
- <methodname>isMember()</methodname> convenience method:
- </para>
- <programlisting language="php"><![CDATA[
- $isMember = $gdata->isMember('bar@somewhere.com', 'friends');
- var_dump($isMember);
- ]]></programlisting>
- <para>
- The method returns a boolean value. If the member belongs to the
- group specified, the method returns true, else it returns false.
- </para>
- </sect3>
- <sect3 id="zend.gdata.gapps.groupMembers.removing">
- <title>Removing a member from a group</title>
- <para>
- To remove a member from a group, call the
- <methodname>removeMemberFromGroup()</methodname> convenience
- method:
- </para>
- <programlisting language="php"><![CDATA[
- $gdata->removeMemberFromGroup('baz', 'friends');
- ]]></programlisting>
- </sect3>
- <sect3 id="zend.gdata.gapps.groupMembers.retrieving">
- <title>Retrieving the list of members to a group</title>
- <para>
- The convenience method <methodname>retrieveAllMembers()</methodname>
- can be used to retrieve the list of members of a group:
- </para>
- <programlisting language="php"><![CDATA[
- $feed = $gdata->retrieveAllMembers('friends');
- foreach ($feed as $member) {
- foreach ($member->property as $p) {
- echo "Property Name: " . $p->name;
- echo "\nProperty Value: " . $p->value . "\n\n";
- }
- }
- ]]></programlisting>
- <para>
- Alternatively, construct a new MemberQuery, set its groupId
- property to match the desired group id, and call
- <methodname>getMemberFeed()</methodname> on a service object.
- </para>
- <programlisting language="php"><![CDATA[
- $query = $gdata->newMemberQuery();
- $query->setGroupId('friends');
- $feed = $gdata->getMemberFeed($query);
- foreach ($feed as $member) {
- foreach ($member->property as $p) {
- echo "Property Name: " . $p->name;
- echo "\nProperty Value: " . $p->value . "\n\n";
- }
- }
- ]]></programlisting>
- <para>
- This will create a <classname>Zend_Gdata_Gapps_MemberFeed</classname>
- object which holds each member for the selected group.
- </para>
- </sect3>
- </sect2>
- <sect2 id="zend.gdata.gapps.groupOwners">
- <title>Interacting with group owners</title>
- <para>
- Each owner associated with a group is represented by an
- instance of <classname>Zend_Gdata_Gapps_OwnerEntry</classname>.
- Through this class, individual owners can be added and removed
- from groups.
- </para>
- <sect3 id="zend.gdata.gapps.groupOwners.adding">
- <title>Adding an owner to a group</title>
- <para>
- To add an owner to a group, simply call the
- <methodname>addOwnerToGroup()</methodname> convenience method:
- </para>
- <programlisting language="php"><![CDATA[
- $gdata->addOwnerToGroup('bar@somewhere.com', 'friends');
- ]]></programlisting>
- </sect3>
- <sect3 id="zend.gdata.gapps.groupOwners.retrieving">
- <title>Retrieving the list of the owner of a group</title>
- <para>
- The convenience method <methodname>retrieveGroupOwners()</methodname>
- can be used to retrieve the list of the owners of a group:
- </para>
- <programlisting language="php"><![CDATA[
- $feed = $gdata->retrieveGroupOwners('friends');
- foreach ($feed as $owner) {
- foreach ($owner->property as $p) {
- echo "Property Name: " . $p->name;
- echo "\nProperty Value: " . $p->value . "\n\n";
- }
- }
- ]]></programlisting>
- <para>
- Alternatively, construct a new OwnerQuery, set its groupId
- property to match the desired group id, and call
- <methodname>getOwnerFeed()</methodname> on a service object.
- </para>
- <programlisting language="php"><![CDATA[
- $query = $gdata->newOwnerQuery();
- $query->setGroupId('friends');
- $feed = $gdata->getOwnerFeed($query);
- foreach ($feed as $owner) {
- foreach ($owner->property as $p) {
- echo "Property Name: " . $p->name;
- echo "\nProperty Value: " . $p->value . "\n\n";
- }
- }
- ]]></programlisting>
- <para>
- This will create a <classname>Zend_Gdata_Gapps_OwnerFeed</classname>
- object which holds each member for the selected group.
- </para>
- </sect3>
- <sect3 id="zend.gdata.gapps.groupOwners.check">
- <title>Check to see if an email is the owner of a group</title>
- <para>
- To check to see if an email is the owner of a group, simply call
- the <methodname>isOwner()</methodname> convenience method:
- </para>
- <programlisting language="php"><![CDATA[
- $isOwner = $gdata->isOwner('bar@somewhere.com', 'friends');
- var_dump($isOwner);
- ]]></programlisting>
- <para>
- The method returns a boolean value. If the email is the owner of
- the group specified, the method returns true, else it returns false.
- </para>
- </sect3>
- <sect3 id="zend.gdata.gapps.groupOwners.removing">
- <title>Removing an owner from a group</title>
- <para>
- To remove an owner from a group, call the
- <methodname>removeOwnerFromGroup()</methodname> convenience
- method:
- </para>
- <programlisting language="php"><![CDATA[
- $gdata->removeOwnerFromGroup('baz@somewhere.com', 'friends');
- ]]></programlisting>
- </sect3>
- </sect2>
- <sect2 id="zend.gdata.gapps.emailLists">
- <title>Interacting with email lists</title>
- <para>
- Email lists allow several users to retrieve email addressed to a
- single email address. Users do not need to be a
- member of this domain in order to subscribe to an email list
- provided their complete email address (including domain) is used.
- </para>
- <para>
- Each email list on a domain is represented as an instance of
- <classname>Zend_Gdata_Gapps_EmailListEntry</classname>.
- </para>
- <sect3 id="zend.gdata.gapps.emailLists.creating">
- <title>Creating an email list</title>
- <para>
- Email lists can be created by calling the
- <methodname>createEmailList()</methodname> convenience method:
- </para>
- <programlisting language="php"><![CDATA[
- $gdata->createEmailList('friends');
- ]]></programlisting>
- <para>
- Email lists can also be created by instantiating
- EmailListEntry, providing a name for the list, then calling
- <methodname>insertEmailList()</methodname> on a service object to upload
- the entry to the server.
- </para>
- <programlisting language="php"><![CDATA[
- $list = $gdata->newEmailListEntry();
- $list->emailList = $gdata->newEmailList('friends');
- $list = $gdata->insertEmailList($list);
- ]]></programlisting>
- </sect3>
- <sect3 id="zend.gdata.gapps.emailList.retrieve">
- <title>Retrieving all email lists to which a recipient is subscribed</title>
- <para>
- To retrieve all email lists to which a particular recipient is
- subscribed, call the <methodname>retrieveEmailLists()</methodname>
- convenience method:
- </para>
- <programlisting language="php"><![CDATA[
- $feed = $gdata->retrieveEmailLists('baz@somewhere.com');
- foreach ($feed as $list) {
- echo ' * ' . $list->emailList->name . "\n";
- }
- ]]></programlisting>
- <para>
- This will create a <classname>Zend_Gdata_Gapps_EmailListFeed</classname> object
- which holds each email list associated with the specified recipient.
- </para>
- <para>
- Alternatively, create a new <classname>Zend_Gdata_Gapps_EmailListQuery</classname>,
- set its recipient property to the desired email address, and
- submit the query by calling <methodname>getEmailListFeed()</methodname> on
- a service object.
- </para>
- <programlisting language="php"><![CDATA[
- $query = $gdata->newEmailListQuery();
- $query->setRecipient('baz@somewhere.com');
- $feed = $gdata->getEmailListFeed($query);
- foreach ($feed as $list) {
- echo ' * ' . $list->emailList->name . "\n";
- }
- ]]></programlisting>
- </sect3>
- <sect3 id="zend.gdata.gapps.emailLists.retrievingAll">
- <title>Retrieving all email lists in a domain</title>
- <para>
- To retrieve all email lists in a domain, call the convenience
- method <methodname>retrieveAllEmailLists()</methodname>.
- </para>
- <programlisting language="php"><![CDATA[
- $feed = $gdata->retrieveAllEmailLists();
- foreach ($feed as $list) {
- echo ' * ' . $list->emailList->name . "\n";
- }
- ]]></programlisting>
- <para>
- This will create a <classname>Zend_Gdata_Gapps_EmailListFeed</classname> object
- which holds each email list on the domain.
- </para>
- <para>
- Alternatively, call <methodname>getEmailListFeed()</methodname> on a
- service object with no arguments.
- </para>
- <programlisting language="php"><![CDATA[
- $feed = $gdata->getEmailListFeed();
- foreach ($feed as $list) {
- echo ' * ' . $list->emailList->name . "\n";
- }
- ]]></programlisting>
- </sect3>
- <sect3 id="zend.gdata.gapps.emailList.deleting">
- <title>Deleting an email list</title>
- <para>
- To delete an email list, call the deleteEmailList()
- convenience method:
- </para>
- <programlisting language="php"><![CDATA[
- $gdata->deleteEmailList('friends');
- ]]></programlisting>
- </sect3>
- </sect2>
- <sect2 id="zend.gdata.gapps.emailListRecipients">
- <title>Interacting with email list recipients</title>
- <para>
- Each recipient subscribed to an email list is represented by an
- instance of <classname>Zend_Gdata_Gapps_EmailListRecipient</classname>. Through this
- class, individual recipients can be added and removed from email
- lists.
- </para>
- <sect3 id="zend.gdata.gapps.emailListRecipients.adding">
- <title>Adding a recipient to an email list</title>
- <para>
- To add a recipient to an email list, simply call the
- <methodname>addRecipientToEmailList()</methodname> convenience method:
- </para>
- <programlisting language="php"><![CDATA[
- $gdata->addRecipientToEmailList('bar@somewhere.com', 'friends');
- ]]></programlisting>
- </sect3>
- <sect3 id="zend.gdata.gapps.emailListRecipients.retrieving">
- <title>Retrieving the list of subscribers to an email list</title>
- <para>
- The convenience method <methodname>retrieveAllRecipients()</methodname>
- can be used to retrieve the list of subscribers to an email list:
- </para>
- <programlisting language="php"><![CDATA[
- $feed = $gdata->retrieveAllRecipients('friends');
- foreach ($feed as $recipient) {
- echo ' * ' . $recipient->who->email . "\n";
- }
- ]]></programlisting>
- <para>
- Alternatively, construct a new EmailListRecipientQuery, set
- its emailListName property to match the desired email list,
- and call <methodname>getEmailListRecipientFeed()</methodname> on a service
- object.
- </para>
- <programlisting language="php"><![CDATA[
- $query = $gdata->newEmailListRecipientQuery();
- $query->setEmailListName('friends');
- $feed = $gdata->getEmailListRecipientFeed($query);
- foreach ($feed as $recipient) {
- echo ' * ' . $recipient->who->email . "\n";
- }
- ]]></programlisting>
- <para>
- This will create a <classname>Zend_Gdata_Gapps_EmailListRecipientFeed</classname>
- object which holds each recipient for the selected email list.
- </para>
- </sect3>
- <sect3 id="zend.gdata.gapps.emailListRecipients.removing">
- <title>Removing a recipient from an email list</title>
- <para>
- To remove a recipient from an email list, call the
- <methodname>removeRecipientFromEmailList()</methodname> convenience
- method:
- </para>
- <programlisting language="php"><![CDATA[
- $gdata->removeRecipientFromEmailList('baz@somewhere.com', 'friends');
- ]]></programlisting>
- </sect3>
- </sect2>
- <sect2 id="zend.gdata.gapps.exceptions">
- <title>Handling errors</title>
- <para>
- In addition to the standard suite of exceptions thrown by
- <classname>Zend_Gdata</classname>, requests using the Provisioning
- <acronym>API</acronym> may also throw a
- <classname>Zend_Gdata_Gapps_ServiceException</classname>. These exceptions
- indicate that a <acronym>API</acronym> specific error occurred which prevents the
- request from completing.
- </para>
- <para>
- Each ServiceException instance may hold one or more Error objects.
- Each of these objects contains an error code, reason, and
- (optionally) the input which triggered the exception. A complete
- list of known error codes is provided in the Zend Framework <acronym>API</acronym>
- documentation under <classname>Zend_Gdata_Gapps_Error</classname>. Additionally, the
- authoritative error list is available online at <ulink
- url="http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html#appendix_d">Google
- Apps Provisioning <acronym>API</acronym> V2.0 Reference: Appendix D</ulink>.
- </para>
- <para>
- While the complete list of errors received is available within
- ServiceException as an array by calling <methodname>getErrors()</methodname>,
- often it is convenient to know if one specific error occurred. For
- these cases the presence of an error can be determined by calling
- <methodname>hasError()</methodname>.
- </para>
- <para>
- The following example demonstrates how to detect if a requested
- resource doesn't exist and handle the fault gracefully:
- </para>
- <programlisting language="php"><![CDATA[
- function retrieveUser ($username) {
- $query = $gdata->newUserQuery($username);
- try {
- $user = $gdata->getUserEntry($query);
- } catch (Zend_Gdata_Gapps_ServiceException $e) {
- // Set the user to null if not found
- if ($e->hasError(Zend_Gdata_Gapps_Error::ENTITY_DOES_NOT_EXIST)) {
- $user = null;
- } else {
- throw $e;
- }
- }
- return $user;
- }
- ]]></programlisting>
- </sect2>
- </sect1>
|