| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248 |
- <?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 <acronym>SHA-1</acronym> digest if
- <command>login->passwordHashFunction</command> is set to
- '<property>SHA-1</property>'.
- </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 <link
- linkend="zend.gdata.gapps.exceptions">the exceptions chapter</link>.
- </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 <link
- linkend="zend.gdata.introduction.paging">the paging chapter</link>.
- </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 <link
- linkend="zend.gdata.gapps.exceptions">the exceptions chapter</link>.
- </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 <acronym>API</acronym>. 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 <methodname>deleteGroup()</methodname> 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 <methodname>deleteEmailList()</methodname>
- 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 Zend Framework's <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>
|