Zend_Gdata_Gapps.xml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.gdata.gapps">
  4. <title>Using Google Apps Provisioning</title>
  5. <para>
  6. Google Apps is a service which allows domain administrators to offer
  7. their users managed access to Google services such as Mail, Calendar,
  8. and Docs &amp; Spreadsheets. The Provisioning <acronym>API</acronym> offers a programmatic
  9. interface to configure this service. Specifically, this <acronym>API</acronym> allows
  10. administrators the ability to create, retrieve, update, and delete
  11. user accounts, nicknames, and email lists.
  12. </para>
  13. <para>
  14. This library implements version 2.0 of the Provisioning <acronym>API</acronym>. Access to
  15. your account via the Provisioning <acronym>API</acronym> must be manually enabled for
  16. each domain using the Google Apps control panel. Only certain
  17. account types are able to enable this feature.
  18. </para>
  19. <para>
  20. For more information on the Google Apps Provisioning <acronym>API</acronym>, including
  21. instructions for enabling <acronym>API</acronym> access, refer to the <ulink
  22. url="http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html">Provisioning
  23. <acronym>API</acronym> V2.0 Reference</ulink>.
  24. </para>
  25. <note>
  26. <title>Authentication</title>
  27. <para>
  28. The Provisioning <acronym>API</acronym> does not support authentication via AuthSub
  29. and anonymous access is not permitted. All <acronym>HTTP</acronym> connections must
  30. be authenticated using ClientAuth authentication.
  31. </para>
  32. </note>
  33. <sect2 id="zend.gdata.gapps.domain">
  34. <title>Setting the current domain</title>
  35. <para>
  36. In order to use the Provisioning <acronym>API</acronym>, the domain being
  37. administered needs to be specified in all request <acronym>URI</acronym>s. In order
  38. to ease development, this information is stored within both the
  39. Gapps service and query classes to use when constructing
  40. requests.
  41. </para>
  42. <sect3 id="zend.gdata.gapps.domain.service">
  43. <title>Setting the domain for the service class</title>
  44. <para>
  45. To set the domain for requests made by the service class,
  46. either call <methodname>setDomain()</methodname> or specify the domain
  47. when instantiating the service class. For example:
  48. </para>
  49. <programlisting language="php"><![CDATA[
  50. $domain = "example.com";
  51. $gdata = new Zend_Gdata_Gapps($client, $domain);
  52. ]]></programlisting>
  53. </sect3>
  54. <sect3 id="zend.gdata.gapps.domain.query">
  55. <title>Setting the domain for query classes</title>
  56. <para>
  57. Setting the domain for requests made by query classes is
  58. similar to setting it for the service class-either call
  59. <methodname>setDomain()</methodname> or specify the domain when creating
  60. the query. For example:
  61. </para>
  62. <programlisting language="php"><![CDATA[
  63. $domain = "example.com";
  64. $query = new Zend_Gdata_Gapps_UserQuery($domain, $arg);
  65. ]]></programlisting>
  66. <para>
  67. When using a service class factory method to create a query,
  68. the service class will automatically set the query's domain to
  69. match its own domain. As a result, it is not necessary to
  70. specify the domain as part of the constructor arguments.
  71. </para>
  72. <programlisting language="php"><![CDATA[
  73. $domain = "example.com";
  74. $gdata = new Zend_Gdata_Gapps($client, $domain);
  75. $query = $gdata->newUserQuery($arg);
  76. ]]></programlisting>
  77. </sect3>
  78. </sect2>
  79. <sect2 id="zend.gdata.gapps.users">
  80. <title>Interacting with users</title>
  81. <para>
  82. Each user account on a Google Apps hosted domain is represented as
  83. an instance of <classname>Zend_Gdata_Gapps_UserEntry</classname>. This class provides
  84. access to all account properties including name, username,
  85. password, access rights, and current quota.
  86. </para>
  87. <sect3 id="zend.gdata.gapps.users.creating">
  88. <title>Creating a user account</title>
  89. <para>
  90. User accounts can be created by calling the
  91. <methodname>createUser()</methodname> convenience method:
  92. </para>
  93. <programlisting language="php"><![CDATA[
  94. $gdata->createUser('foo', 'Random', 'User', '••••••••');
  95. ]]></programlisting>
  96. <para>
  97. Users can also be created by instantiating UserEntry,
  98. providing a username, given name, family name, and password,
  99. then calling <methodname>insertUser()</methodname> on a service object to
  100. upload the entry to the server.
  101. </para>
  102. <programlisting language="php"><![CDATA[
  103. $user = $gdata->newUserEntry();
  104. $user->login = $gdata->newLogin();
  105. $user->login->username = 'foo';
  106. $user->login->password = '••••••••';
  107. $user->name = $gdata->newName();
  108. $user->name->givenName = 'Random';
  109. $user->name->familyName = 'User';
  110. $user = $gdata->insertUser($user);
  111. ]]></programlisting>
  112. <para>
  113. The user's password should normally be provided as cleartext.
  114. Optionally, the password can be provided as an SHA-1 digest if
  115. <code>login->passwordHashFunction</code> is set to 'SHA-1'.
  116. </para>
  117. </sect3>
  118. <sect3 id="zend.gdata.gapps.users.retrieving">
  119. <title>Retrieving a user account</title>
  120. <para>
  121. Individual user accounts can be retrieved by calling the
  122. <methodname>retrieveUser()</methodname> convenience method. If the user is
  123. not found, <constant>NULL</constant> will be returned.
  124. </para>
  125. <programlisting language="php"><![CDATA[
  126. $user = $gdata->retrieveUser('foo');
  127. echo 'Username: ' . $user->login->userName . "\n";
  128. echo 'Given Name: ' . $user->name->givenName . "\n";
  129. echo 'Family Name: ' . $user->name->familyName . "\n";
  130. echo 'Suspended: ' . ($user->login->suspended ? 'Yes' : 'No') . "\n";
  131. echo 'Admin: ' . ($user->login->admin ? 'Yes' : 'No') . "\n"
  132. echo 'Must Change Password: ' .
  133. ($user->login->changePasswordAtNextLogin ? 'Yes' : 'No') . "\n";
  134. echo 'Has Agreed To Terms: ' .
  135. ($user->login->agreedToTerms ? 'Yes' : 'No') . "\n";
  136. ]]></programlisting>
  137. <para>
  138. Users can also be retrieved by creating an
  139. instance of <classname>Zend_Gdata_Gapps_UserQuery</classname>, setting its username
  140. property to equal the username of the user that is to be
  141. retrieved, and calling <methodname>getUserEntry()</methodname> on a
  142. service object with that query.
  143. </para>
  144. <programlisting language="php"><![CDATA[
  145. $query = $gdata->newUserQuery('foo');
  146. $user = $gdata->getUserEntry($query);
  147. echo 'Username: ' . $user->login->userName . "\n";
  148. echo 'Given Name: ' . $user->login->givenName . "\n";
  149. echo 'Family Name: ' . $user->login->familyName . "\n";
  150. echo 'Suspended: ' . ($user->login->suspended ? 'Yes' : 'No') . "\n";
  151. echo 'Admin: ' . ($user->login->admin ? 'Yes' : 'No') . "\n"
  152. echo 'Must Change Password: ' .
  153. ($user->login->changePasswordAtNextLogin ? 'Yes' : 'No') . "\n";
  154. echo 'Has Agreed To Terms: ' .
  155. ($user->login->agreedToTerms ? 'Yes' : 'No') . "\n";
  156. ]]></programlisting>
  157. <para>
  158. If the specified user cannot be located a ServiceException
  159. will be thrown with an error code of
  160. <constant>Zend_Gdata_Gapps_Error::ENTITY_DOES_NOT_EXIST</constant>.
  161. ServiceExceptions will be covered in <xref
  162. linkend="zend.gdata.gapps.exceptions" />.
  163. </para>
  164. </sect3>
  165. <sect3 id="zend.gdata.gapps.users.retrievingAll">
  166. <title>Retrieving all users in a domain</title>
  167. <para>
  168. To retrieve all users in a domain, call the
  169. <methodname>retrieveAllUsers()</methodname> convenience method.
  170. </para>
  171. <programlisting language="php"><![CDATA[
  172. $feed = $gdata->retrieveAllUsers();
  173. foreach ($feed as $user) {
  174. echo " * " . $user->login->username . ' (' . $user->name->givenName .
  175. ' ' . $user->name->familyName . ")\n";
  176. }
  177. ]]></programlisting>
  178. <para>
  179. This will create a <classname>Zend_Gdata_Gapps_UserFeed</classname> object which
  180. holds each user on the domain.
  181. </para>
  182. <para>
  183. Alternatively, call <methodname>getUserFeed()</methodname> with no
  184. options. Keep in mind that on larger
  185. domains this feed may be paged by the server. For more
  186. information on paging, see <xref
  187. linkend="zend.gdata.introduction.paging" />.
  188. </para>
  189. <programlisting language="php"><![CDATA[
  190. $feed = $gdata->getUserFeed();
  191. foreach ($feed as $user) {
  192. echo " * " . $user->login->username . ' (' . $user->name->givenName .
  193. ' ' . $user->name->familyName . ")\n";
  194. }
  195. ]]></programlisting>
  196. </sect3>
  197. <sect3 id="zend.gdata.gapps.users.updating">
  198. <title>Updating a user account</title>
  199. <para>
  200. The easiest way to update a user account is to retrieve the
  201. user as described in the previous sections, make any desired
  202. changes, then call <methodname>save()</methodname> on that user. Any
  203. changes made will be propagated to the server.
  204. </para>
  205. <programlisting language="php"><![CDATA[
  206. $user = $gdata->retrieveUser('foo');
  207. $user->name->givenName = 'Foo';
  208. $user->name->familyName = 'Bar';
  209. $user = $user->save();
  210. ]]></programlisting>
  211. <sect4 id="zend.gdata.gapps.users.updating.resettingPassword">
  212. <title>Resetting a user's password</title>
  213. <para>
  214. A user's password can be reset to a new value by updating
  215. the <code>login->password</code> property.
  216. </para>
  217. <programlisting language="php"><![CDATA[
  218. $user = $gdata->retrieveUser('foo');
  219. $user->login->password = '••••••••';
  220. $user = $user->save();
  221. ]]></programlisting>
  222. <para>
  223. Note that it is not possible to recover a password in this
  224. manner as stored passwords are not made available via the
  225. Provisioning <acronym>API</acronym> for security reasons.
  226. </para>
  227. </sect4>
  228. <sect4 id="zend.gdata.gapps.users.updating.forcingPasswordChange">
  229. <title>Forcing a user to change their password</title>
  230. <para>
  231. A user can be forced to change their password at their
  232. next login by setting the
  233. <code>login->changePasswordAtNextLogin</code> property to
  234. <constant>TRUE</constant>.
  235. </para>
  236. <programlisting language="php"><![CDATA[
  237. $user = $gdata->retrieveUser('foo');
  238. $user->login->changePasswordAtNextLogin = true;
  239. $user = $user->save();
  240. ]]></programlisting>
  241. <para>
  242. Similarly, this can be undone by setting the
  243. <code>login->changePasswordAtNextLogin</code> property to
  244. <constant>FALSE</constant>.
  245. </para>
  246. </sect4>
  247. <sect4 id="zend.gdata.gapps.users.updating.suspendingAccount">
  248. <title>Suspending a user account</title>
  249. <para>
  250. Users can be restricted from logging in without deleting
  251. their user account by instead
  252. <emphasis>suspending</emphasis> their user account.
  253. Accounts can be suspended or restored by using the
  254. <methodname>suspendUser()</methodname> and <methodname>restoreUser()</methodname>
  255. convenience methods:
  256. </para>
  257. <programlisting language="php"><![CDATA[
  258. $gdata->suspendUser('foo');
  259. $gdata->restoreUser('foo');
  260. ]]></programlisting>
  261. <para>
  262. Alternatively, you can set the UserEntry's
  263. <code>login->suspended</code> property to
  264. <constant>TRUE</constant>.
  265. </para>
  266. <programlisting language="php"><![CDATA[
  267. $user = $gdata->retrieveUser('foo');
  268. $user->login->suspended = true;
  269. $user = $user->save();
  270. ]]></programlisting>
  271. <para>
  272. To restore the user's access, set the
  273. <code>login->suspended</code> property to
  274. <constant>FALSE</constant>.
  275. </para>
  276. </sect4>
  277. <sect4 id="zend.gdata.gapps.users.updating.grantingAdminRights">
  278. <title>Granting administrative rights</title>
  279. <para>
  280. Users can be granted the ability to administer your domain
  281. by setting their <code>login->admin</code> property to
  282. <constant>TRUE</constant>.
  283. </para>
  284. <programlisting language="php"><![CDATA[
  285. $user = $gdata->retrieveUser('foo');
  286. $user->login->admin = true;
  287. $user = $user->save();
  288. ]]></programlisting>
  289. <para>
  290. And as expected, setting a user's <code>login->admin</code>
  291. property to <constant>FALSE</constant> revokes their
  292. administrative rights.
  293. </para>
  294. </sect4>
  295. </sect3>
  296. <sect3 id="zend.gdata.gapps.users.deleting">
  297. <title>Deleting user accounts</title>
  298. <para>
  299. Deleting a user account to which you already hold a UserEntry
  300. is a simple as calling <methodname>delete()</methodname> on that
  301. entry.
  302. </para>
  303. <programlisting language="php"><![CDATA[
  304. $user = $gdata->retrieveUser('foo');
  305. $user->delete();
  306. ]]></programlisting>
  307. <para>
  308. If you do not have access to a UserEntry object for an
  309. account, use the <methodname>deleteUser()</methodname> convenience method.
  310. </para>
  311. <programlisting language="php"><![CDATA[
  312. $gdata->deleteUser('foo');
  313. ]]></programlisting>
  314. </sect3>
  315. </sect2>
  316. <sect2 id="zend.gdata.gapps.nicknames">
  317. <title>Interacting with nicknames</title>
  318. <para>
  319. Nicknames serve as email aliases for existing users. Each nickname
  320. contains precisely two key properties: its name and its owner. Any
  321. email addressed to a nickname is forwarded to the user who owns
  322. that nickname.
  323. </para>
  324. <para>
  325. Nicknames are represented as an instances of
  326. <classname>Zend_Gdata_Gapps_NicknameEntry</classname>.
  327. </para>
  328. <sect3 id="zend.gdata.gapps.nicknames.creating">
  329. <title>Creating a nickname</title>
  330. <para>
  331. Nicknames can be created by calling the
  332. <methodname>createNickname()</methodname> convenience method:
  333. </para>
  334. <programlisting language="php"><![CDATA[
  335. $gdata->createNickname('foo', 'bar');
  336. ]]></programlisting>
  337. <para>
  338. Nicknames can also be created by instantiating NicknameEntry,
  339. providing the nickname with a name and an owner, then calling
  340. <methodname>insertNickname()</methodname> on a service object to upload
  341. the entry to the server.
  342. </para>
  343. <programlisting language="php"><![CDATA[
  344. $nickname = $gdata->newNicknameEntry();
  345. $nickname->login = $gdata->newLogin('foo');
  346. $nickname->nickname = $gdata->newNickname('bar');
  347. $nickname = $gdata->insertNickname($nickname);
  348. ]]></programlisting>
  349. </sect3>
  350. <sect3 id="zend.gdata.gapps.nicknames.retrieving">
  351. <title>Retrieving a nickname</title>
  352. <para>
  353. Nicknames can be retrieved by calling the
  354. <methodname>retrieveNickname()</methodname> convenience method. This will
  355. return <constant>NULL</constant> if a user is not found.
  356. </para>
  357. <programlisting language="php"><![CDATA[
  358. $nickname = $gdata->retrieveNickname('bar');
  359. echo 'Nickname: ' . $nickname->nickname->name . "\n";
  360. echo 'Owner: ' . $nickname->login->username . "\n";
  361. ]]></programlisting>
  362. <para>
  363. Individual nicknames can also be retrieved by creating an
  364. instance of <classname>Zend_Gdata_Gapps_NicknameQuery</classname>, setting its
  365. nickname property to equal the nickname that is to be
  366. retrieved, and calling <methodname>getNicknameEntry()</methodname> on a
  367. service object with that query.
  368. </para>
  369. <programlisting language="php"><![CDATA[
  370. $query = $gdata->newNicknameQuery('bar');
  371. $nickname = $gdata->getNicknameEntry($query);
  372. echo 'Nickname: ' . $nickname->nickname->name . "\n";
  373. echo 'Owner: ' . $nickname->login->username . "\n";
  374. ]]></programlisting>
  375. <para>
  376. As with users, if no corresponding nickname is found a
  377. ServiceException will be thrown with an error code of
  378. <constant>Zend_Gdata_Gapps_Error::ENTITY_DOES_NOT_EXIST</constant>. Again, these
  379. will be discussed in <xref linkend="zend.gdata.gapps.exceptions"
  380. />.
  381. </para>
  382. </sect3>
  383. <sect3 id="zend.gdata.gapps.nicknames.retrievingUser">
  384. <title>Retrieving all nicknames for a user</title>
  385. <para>
  386. To retrieve all nicknames associated with a given user, call
  387. the convenience method <methodname>retrieveNicknames()</methodname>.
  388. </para>
  389. <programlisting language="php"><![CDATA[
  390. $feed = $gdata->retrieveNicknames('foo');
  391. foreach ($feed as $nickname) {
  392. echo ' * ' . $nickname->nickname->name . "\n";
  393. }
  394. ]]></programlisting>
  395. <para>
  396. This will create a <classname>Zend_Gdata_Gapps_NicknameFeed</classname> object which
  397. holds each nickname associated with the specified user.
  398. </para>
  399. <para>
  400. Alternatively, create a new <classname>Zend_Gdata_Gapps_NicknameQuery</classname>,
  401. set its username property to the desired user, and submit the
  402. query by calling <methodname>getNicknameFeed()</methodname> on a service
  403. object.
  404. </para>
  405. <programlisting language="php"><![CDATA[
  406. $query = $gdata->newNicknameQuery();
  407. $query->setUsername('foo');
  408. $feed = $gdata->getNicknameFeed($query);
  409. foreach ($feed as $nickname) {
  410. echo ' * ' . $nickname->nickname->name . "\n";
  411. }
  412. ]]></programlisting>
  413. </sect3>
  414. <sect3 id="zend.gdata.gapps.nicknames.retrievingAll">
  415. <title>Retrieving all nicknames in a domain</title>
  416. <para>
  417. To retrieve all nicknames in a feed, simply call the
  418. convenience method <methodname>retrieveAllNicknames()</methodname>
  419. </para>
  420. <programlisting language="php"><![CDATA[
  421. $feed = $gdata->retrieveAllNicknames();
  422. foreach ($feed as $nickname) {
  423. echo ' * ' . $nickname->nickname->name . ' => ' .
  424. $nickname->login->username . "\n";
  425. }
  426. ]]></programlisting>
  427. <para>
  428. This will create a <classname>Zend_Gdata_Gapps_NicknameFeed</classname> object which
  429. holds each nickname on the domain.
  430. </para>
  431. <para>
  432. Alternatively, call <methodname>getNicknameFeed()</methodname> on a
  433. service object with no arguments.
  434. </para>
  435. <programlisting language="php"><![CDATA[
  436. $feed = $gdata->getNicknameFeed();
  437. foreach ($feed as $nickname) {
  438. echo ' * ' . $nickname->nickname->name . ' => ' .
  439. $nickname->login->username . "\n";
  440. }
  441. ]]></programlisting>
  442. </sect3>
  443. <sect3 id="zend.gdata.gapps.nicknames.deleting">
  444. <title>Deleting a nickname</title>
  445. <para>
  446. Deleting a nickname to which you already hold a NicknameEntry
  447. for is a simple as calling <methodname>delete()</methodname> on that
  448. entry.
  449. </para>
  450. <programlisting language="php"><![CDATA[
  451. $nickname = $gdata->retrieveNickname('bar');
  452. $nickname->delete();
  453. ]]></programlisting>
  454. <para>
  455. For nicknames which you do not hold a NicknameEntry for, use
  456. the <methodname>deleteNickname()</methodname> convenience method.
  457. </para>
  458. <programlisting language="php"><![CDATA[
  459. $gdata->deleteNickname('bar');
  460. ]]></programlisting>
  461. </sect3>
  462. </sect2>
  463. <sect2 id="zend.gdata.gapps.emailLists">
  464. <title>Interacting with email lists</title>
  465. <para>
  466. Email lists allow several users to retrieve email addressed to a
  467. single email address. Users do not need to be a
  468. member of this domain in order to subscribe to an email list
  469. provided their complete email address (including domain) is used.
  470. </para>
  471. <para>
  472. Each email list on a domain is represented as an instance of
  473. <classname>Zend_Gdata_Gapps_EmailListEntry</classname>.
  474. </para>
  475. <sect3 id="zend.gdata.gapps.emailLists.creating">
  476. <title>Creating an email list</title>
  477. <para>
  478. Email lists can be created by calling the
  479. <methodname>createEmailList()</methodname> convenience method:
  480. </para>
  481. <programlisting language="php"><![CDATA[
  482. $gdata->createEmailList('friends');
  483. ]]></programlisting>
  484. <para>
  485. Email lists can also be created by instantiating
  486. EmailListEntry, providing a name for the list, then calling
  487. <methodname>insertEmailList()</methodname> on a service object to upload
  488. the entry to the server.
  489. </para>
  490. <programlisting language="php"><![CDATA[
  491. $list = $gdata->newEmailListEntry();
  492. $list->emailList = $gdata->newEmailList('friends');
  493. $list = $gdata->insertEmailList($list);
  494. ]]></programlisting>
  495. </sect3>
  496. <sect3 id="zend.gdata.gapps.emailList.retrieve">
  497. <title>Retrieving all email lists to which a recipient is
  498. subscribed</title>
  499. <para>
  500. To retrieve all email lists to which a particular recipient is
  501. subscribed, call the <methodname>retrieveEmailLists()</methodname>
  502. convenience method:
  503. </para>
  504. <programlisting language="php"><![CDATA[
  505. $feed = $gdata->retrieveEmailLists('baz@somewhere.com');
  506. foreach ($feed as $list) {
  507. echo ' * ' . $list->emailList->name . "\n";
  508. }
  509. ]]></programlisting>
  510. <para>
  511. This will create a <classname>Zend_Gdata_Gapps_EmailListFeed</classname> object which
  512. holds each email list associated with the specified recipient.
  513. </para>
  514. <para>
  515. Alternatively, create a new <classname>Zend_Gdata_Gapps_EmailListQuery</classname>,
  516. set its recipient property to the desired email address, and
  517. submit the query by calling <methodname>getEmailListFeed()</methodname> on
  518. a service object.
  519. </para>
  520. <programlisting language="php"><![CDATA[
  521. $query = $gdata->newEmailListQuery();
  522. $query->setRecipient('baz@somewhere.com');
  523. $feed = $gdata->getEmailListFeed($query);
  524. foreach ($feed as $list) {
  525. echo ' * ' . $list->emailList->name . "\n";
  526. }
  527. ]]></programlisting>
  528. </sect3>
  529. <sect3 id="zend.gdata.gapps.emailLists.retrievingAll">
  530. <title>Retrieving all email lists in a domain</title>
  531. <para>
  532. To retrieve all email lists in a domain, call the convenience
  533. method <methodname>retrieveAllEmailLists()</methodname>.
  534. </para>
  535. <programlisting language="php"><![CDATA[
  536. $feed = $gdata->retrieveAllEmailLists();
  537. foreach ($feed as $list) {
  538. echo ' * ' . $list->emailList->name . "\n";
  539. }
  540. ]]></programlisting>
  541. <para>
  542. This will create a <classname>Zend_Gdata_Gapps_EmailListFeed</classname> object which
  543. holds each email list on the domain.
  544. </para>
  545. <para>
  546. Alternatively, call <methodname>getEmailListFeed()</methodname> on a
  547. service object with no arguments.
  548. </para>
  549. <programlisting language="php"><![CDATA[
  550. $feed = $gdata->getEmailListFeed();
  551. foreach ($feed as $list) {
  552. echo ' * ' . $list->emailList->name . "\n";
  553. }
  554. ]]></programlisting>
  555. </sect3>
  556. <sect3 id="zend.gdata.gapps.emailList.deleting">
  557. <title>Deleting an email list</title>
  558. <para>
  559. To delete an email list, call the deleteEmailList()
  560. convenience method:
  561. </para>
  562. <programlisting language="php"><![CDATA[
  563. $gdata->deleteEmailList('friends');
  564. ]]></programlisting>
  565. </sect3>
  566. </sect2>
  567. <sect2 id="zend.gdata.gapps.emailListRecipients">
  568. <title>Interacting with email list recipients</title>
  569. <para>
  570. Each recipient subscribed to an email list is represented by an
  571. instance of <classname>Zend_Gdata_Gapps_EmailListRecipient</classname>. Through this
  572. class, individual recipients can be added and removed from email
  573. lists.
  574. </para>
  575. <sect3 id="zend.gdata.gapps.emailListRecipients.adding">
  576. <title>Adding a recipient to an email list</title>
  577. <para>
  578. To add a recipient to an email list, simply call the
  579. <methodname>addRecipientToEmailList()</methodname> convenience method:
  580. </para>
  581. <programlisting language="php"><![CDATA[
  582. $gdata->addRecipientToEmailList('bar@somewhere.com', 'friends');
  583. ]]></programlisting>
  584. </sect3>
  585. <sect3 id="zend.gdata.gapps.emailListRecipients.retrieving">
  586. <title>Retrieving the list of subscribers to an email list</title>
  587. <para>
  588. The convenience method <methodname>retrieveAllRecipients()</methodname>
  589. can be used to retrieve the list of subscribers to an email list:
  590. </para>
  591. <programlisting language="php"><![CDATA[
  592. $feed = $gdata->retrieveAllRecipients('friends');
  593. foreach ($feed as $recipient) {
  594. echo ' * ' . $recipient->who->email . "\n";
  595. }
  596. ]]></programlisting>
  597. <para>
  598. Alternatively, construct a new EmailListRecipientQuery, set
  599. its emailListName property to match the desired email list,
  600. and call <methodname>getEmailListRecipientFeed()</methodname> on a service
  601. object.
  602. </para>
  603. <programlisting language="php"><![CDATA[
  604. $query = $gdata->newEmailListRecipientQuery();
  605. $query->setEmailListName('friends');
  606. $feed = $gdata->getEmailListRecipientFeed($query);
  607. foreach ($feed as $recipient) {
  608. echo ' * ' . $recipient->who->email . "\n";
  609. }
  610. ]]></programlisting>
  611. <para>
  612. This will create a <classname>Zend_Gdata_Gapps_EmailListRecipientFeed</classname>
  613. object which holds each recipient for the selected email list.
  614. </para>
  615. </sect3>
  616. <sect3 id="zend.gdata.gapps.emailListRecipients.removing">
  617. <title>Removing a recipient from an email list</title>
  618. <para>
  619. To remove a recipient from an email list, call the
  620. <methodname>removeRecipientFromEmailList()</methodname> convenience
  621. method:
  622. </para>
  623. <programlisting language="php"><![CDATA[
  624. $gdata->removeRecipientFromEmailList('baz@somewhere.com', 'friends');
  625. ]]></programlisting>
  626. </sect3>
  627. </sect2>
  628. <sect2 id="zend.gdata.gapps.exceptions">
  629. <title>Handling errors</title>
  630. <para>
  631. In addition to the standard suite of exceptions thrown by
  632. <classname>Zend_Gdata</classname>, requests using the Provisioning <acronym>API</acronym> may also throw a
  633. <classname>Zend_Gdata_Gapps_ServiceException</classname>. These exceptions
  634. indicate that a <acronym>API</acronym> specific error occurred which prevents the
  635. request from completing.
  636. </para>
  637. <para>
  638. Each ServiceException instance may hold one or more Error objects.
  639. Each of these objects contains an error code, reason, and
  640. (optionally) the input which triggered the exception. A complete
  641. list of known error codes is provided in the Zend Framework <acronym>API</acronym>
  642. documentation under <classname>Zend_Gdata_Gapps_Error</classname>. Additionally, the
  643. authoritative error list is available online at <ulink
  644. url="http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html#appendix_d">Google
  645. Apps Provisioning <acronym>API</acronym> V2.0 Reference: Appendix D</ulink>.
  646. </para>
  647. <para>
  648. While the complete list of errors received is available within
  649. ServiceException as an array by calling <methodname>getErrors()</methodname>,
  650. often it is convenient to know if one specific error occurred. For
  651. these cases the presence of an error can be determined by calling
  652. <methodname>hasError()</methodname>.
  653. </para>
  654. <para>
  655. The following example demonstrates how to detect if a requested
  656. resource doesn't exist and handle the fault gracefully:
  657. </para>
  658. <programlisting language="php"><![CDATA[
  659. function retrieveUser ($username) {
  660. $query = $gdata->newUserQuery($username);
  661. try {
  662. $user = $gdata->getUserEntry($query);
  663. } catch (Zend_Gdata_Gapps_ServiceException $e) {
  664. // Set the user to null if not found
  665. if ($e->hasError(Zend_Gdata_Gapps_Error::ENTITY_DOES_NOT_EXIST)) {
  666. $user = null;
  667. } else {
  668. throw $e;
  669. }
  670. }
  671. return $user;
  672. }
  673. ]]></programlisting>
  674. </sect2>
  675. </sect1>