Zend_Gdata_Gapps.xml 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  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, groups, 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. <command>login->passwordHashFunction</command> 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 <command>login->password</command> 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. <command>login->changePasswordAtNextLogin</command> 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. <command>login->changePasswordAtNextLogin</command> 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
  255. <methodname>restoreUser()</methodname> 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. <command>login->suspended</command> 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. <command>login->suspended</command> 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 <command>login->admin</command> 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 <command>login->admin</command>
  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.groups">
  464. <title>Interacting with groups</title>
  465. <para>
  466. Google Groups allows people to post messages like an email list. Google
  467. is depreciating the Email List API. Google Groups provides some neat
  468. features like nested groups and group owners. If you want to start
  469. a new email lst, it is advisable to use Google Groups instead.
  470. Google's Email List is not compatible with Google Groups. So if you
  471. create an email list, it will not show up as a group. The opposite is
  472. true as well.
  473. </para>
  474. <para>
  475. Each group on a domain is represented as an instance of
  476. <classname>Zend_Gdata_Gapps_GroupEntry</classname>.
  477. </para>
  478. <sect3 id="zend.gdata.gapps.groups.creating">
  479. <title>Creating a group</title>
  480. <para>
  481. Groups can be created by calling the
  482. <methodname>createGroup()</methodname> convenience method:
  483. </para>
  484. <programlisting language="php"><![CDATA[
  485. $gdata->createGroup('friends', 'The Friends Group');
  486. ]]></programlisting>
  487. <para>
  488. Groups can also be created by instantiating
  489. GroupEntry, providing a group id and name for the group,
  490. then calling <methodname>insertGroup()</methodname> on a service
  491. object to upload the entry to the server.
  492. </para>
  493. <programlisting language="php"><![CDATA[
  494. $group = $gdata->newGroupEntry();
  495. $properties[0] = $this->newProperty();
  496. $properties[0]->name = 'groupId';
  497. $properties[0]->value = 'friends';
  498. $properties[1] = $this->newProperty();
  499. $properties[1]->name = 'groupName';
  500. $properties[1]->value = 'The Friends Group';
  501. $group->property = $properties;
  502. $group = $gdata->insertGroup($group);
  503. ]]></programlisting>
  504. </sect3>
  505. <sect3 id="zend.gdata.gapps.groups.retrieveGroup">
  506. <title>Retrieving an individual group</title>
  507. <para>
  508. To retrieve an individual group, call the
  509. <methodname>retrieveGroup()</methodname> convenience method:
  510. </para>
  511. <programlisting language="php"><![CDATA[
  512. $entry = $gdata->retrieveGroup('friends');
  513. foreach ($entry->property as $p) {
  514. echo "Property Name: " . $p->name;
  515. echo "\nProperty Value: " . $p->value . "\n\n";
  516. }
  517. ]]></programlisting>
  518. <para>
  519. This will create a <classname>Zend_Gdata_Gapps_GroupEntry</classname>
  520. object which holds the properties about the group.
  521. </para>
  522. <para>
  523. Alternatively, create a new <classname>Zend_Gdata_Gapps_GroupQuery</classname>,
  524. set its groupId property to the desired group id, and
  525. submit the query by calling <methodname>getGroupEntry()</methodname>
  526. on a service object.
  527. </para>
  528. <programlisting language="php"><![CDATA[
  529. $query = $gdata->newGroupQuery();
  530. $query->setGroupId('friends');
  531. $entry = $gdata->getGroupEntry($query);
  532. foreach ($entry->property as $p) {
  533. echo "Property Name: " . $p->name;
  534. echo "\nProperty Value: " . $p->value . "\n\n";
  535. }
  536. ]]></programlisting>
  537. </sect3>
  538. <sect3 id="zend.gdata.gapps.groups.retrievingAll">
  539. <title>Retrieving all groups in a domain</title>
  540. <para>
  541. To retrieve all groups in a domain, call the convenience
  542. method <methodname>retrieveAllGroups()</methodname>.
  543. </para>
  544. <programlisting language="php"><![CDATA[
  545. $feed = $gdata->retrieveAllGroups();
  546. foreach ($feed->entry as $entry) {
  547. foreach ($entry->property as $p) {
  548. echo "Property Name: " . $p->name;
  549. echo "\nProperty Value: " . $p->value . "\n\n";
  550. }
  551. echo "\n\n";
  552. }
  553. ]]></programlisting>
  554. <para>
  555. This will create a <classname>Zend_Gdata_Gapps_GroupFeed</classname>
  556. object which holds each group on the domain.
  557. </para>
  558. <para>
  559. Alternatively, call <methodname>getGroupFeed()</methodname> on a
  560. service object with no arguments.
  561. </para>
  562. <programlisting language="php"><![CDATA[
  563. $feed = $gdata->getGroupFeed();
  564. foreach ($feed->entry as $entry) {
  565. foreach ($entry->property as $p) {
  566. echo "Property Name: " . $p->name;
  567. echo "\nProperty Value: " . $p->value . "\n\n";
  568. }
  569. echo "\n\n";
  570. }
  571. ]]></programlisting>
  572. </sect3>
  573. <sect3 id="zend.gdata.gapps.groups.deleting">
  574. <title>Deleting a group</title>
  575. <para>
  576. To delete a group, call the deleteGroup() convenience method:
  577. </para>
  578. <programlisting language="php"><![CDATA[
  579. $gdata->deleteGroup('friends');
  580. ]]></programlisting>
  581. </sect3>
  582. <sect3 id="zend.gdata.gapps.groups.updating">
  583. <title>Updating a group</title>
  584. <para>
  585. Groups can be updated by calling the
  586. <methodname>updateGroup()</methodname> convenience method:
  587. </para>
  588. <programlisting language="php"><![CDATA[
  589. $gdata->updateGroup('group-id-here', 'Group Name Here');
  590. ]]></programlisting>
  591. <para>
  592. The first parameter is required. The second, third and fourth parameter,
  593. representing the group name, group descscription, and email permission,
  594. respectively are optional. Setting any of these optional parameters
  595. to null will not update that item.
  596. </para>
  597. </sect3>
  598. <sect3 id="zend.gdata.gapps.groups.retrieve">
  599. <title>Retrieving all groups to which a person is a member</title>
  600. <para>
  601. To retrieve all groups to which a particular person is a
  602. member, call the <methodname>retrieveGroups()</methodname>
  603. convenience method:
  604. </para>
  605. <programlisting language="php"><![CDATA[
  606. $feed = $gdata->retrieveGroups('baz@somewhere.com');
  607. foreach ($feed->entry as $entry) {
  608. foreach ($entry->property as $p) {
  609. echo "Property Name: " . $p->name;
  610. echo "\nProperty Value: " . $p->value . "\n\n";
  611. }
  612. echo "\n\n";
  613. }
  614. ]]></programlisting>
  615. <para>
  616. This will create a <classname>Zend_Gdata_Gapps_GroupFeed</classname>
  617. object which holds each group associated with the specified member.
  618. </para>
  619. <para>
  620. Alternatively, create a new <classname>Zend_Gdata_Gapps_GroupQuery</classname>,
  621. set its member property to the desired email address, and
  622. submit the query by calling <methodname>getGroupFeed()</methodname>
  623. on a service object.
  624. </para>
  625. <programlisting language="php"><![CDATA[
  626. $query = $gdata->newGroupQuery();
  627. $query->setMember('baz@somewhere.com');
  628. $feed = $gdata->getGroupFeed($query);
  629. foreach ($feed->entry as $entry) {
  630. foreach ($entry->property as $p) {
  631. echo "Property Name: " . $p->name;
  632. echo "\nProperty Value: " . $p->value . "\n\n";
  633. }
  634. echo "\n\n";
  635. }
  636. ]]></programlisting>
  637. </sect3>
  638. </sect2>
  639. <sect2 id="zend.gdata.gapps.groupMembers">
  640. <title>Interacting with group members</title>
  641. <para>
  642. Each member subscribed to a group is represented by an
  643. instance of <classname>Zend_Gdata_Gapps_MemberEntry</classname>.
  644. Through this class, individual recipients can be added and removed
  645. from groups.
  646. </para>
  647. <sect3 id="zend.gdata.gapps.groupMembers.adding">
  648. <title>Adding a member to a group</title>
  649. <para>
  650. To add a member to a group, simply call the
  651. <methodname>addMemberToGroup()</methodname> convenience method:
  652. </para>
  653. <programlisting language="php"><![CDATA[
  654. $gdata->addMemberToGroup('bar@somewhere.com', 'friends');
  655. ]]></programlisting>
  656. </sect3>
  657. <sect3 id="zend.gdata.gapps.groupMembers.check">
  658. <title>Check to see if member belongs to group</title>
  659. <para>
  660. To check to see if member belongs to group, simply call the
  661. <methodname>isMember()</methodname> convenience method:
  662. </para>
  663. <programlisting language="php"><![CDATA[
  664. $isMember = $gdata->isMember('bar@somewhere.com', 'friends');
  665. var_dump($isMember);
  666. ]]></programlisting>
  667. <para>
  668. The method returns a boolean value. If the member belongs to the
  669. group specified, the method returns true, else it returns false.
  670. </para>
  671. </sect3>
  672. <sect3 id="zend.gdata.gapps.groupMembers.removing">
  673. <title>Removing a member from a group</title>
  674. <para>
  675. To remove a member from a group, call the
  676. <methodname>removeMemberFromGroup()</methodname> convenience
  677. method:
  678. </para>
  679. <programlisting language="php"><![CDATA[
  680. $gdata->removeMemberFromGroup('baz', 'friends');
  681. ]]></programlisting>
  682. </sect3>
  683. <sect3 id="zend.gdata.gapps.groupMembers.retrieving">
  684. <title>Retrieving the list of members to a group</title>
  685. <para>
  686. The convenience method <methodname>retrieveAllMembers()</methodname>
  687. can be used to retrieve the list of members of a group:
  688. </para>
  689. <programlisting language="php"><![CDATA[
  690. $feed = $gdata->retrieveAllMembers('friends');
  691. foreach ($feed as $member) {
  692. foreach ($member->property as $p) {
  693. echo "Property Name: " . $p->name;
  694. echo "\nProperty Value: " . $p->value . "\n\n";
  695. }
  696. }
  697. ]]></programlisting>
  698. <para>
  699. Alternatively, construct a new MemberQuery, set its groupId
  700. property to match the desired group id, and call
  701. <methodname>getMemberFeed()</methodname> on a service object.
  702. </para>
  703. <programlisting language="php"><![CDATA[
  704. $query = $gdata->newMemberQuery();
  705. $query->setGroupId('friends');
  706. $feed = $gdata->getMemberFeed($query);
  707. foreach ($feed as $member) {
  708. foreach ($member->property as $p) {
  709. echo "Property Name: " . $p->name;
  710. echo "\nProperty Value: " . $p->value . "\n\n";
  711. }
  712. }
  713. ]]></programlisting>
  714. <para>
  715. This will create a <classname>Zend_Gdata_Gapps_MemberFeed</classname>
  716. object which holds each member for the selected group.
  717. </para>
  718. </sect3>
  719. </sect2>
  720. <sect2 id="zend.gdata.gapps.groupOwners">
  721. <title>Interacting with group owners</title>
  722. <para>
  723. Each owner associated with a group is represented by an
  724. instance of <classname>Zend_Gdata_Gapps_OwnerEntry</classname>.
  725. Through this class, individual owners can be added and removed
  726. from groups.
  727. </para>
  728. <sect3 id="zend.gdata.gapps.groupOwners.adding">
  729. <title>Adding an owner to a group</title>
  730. <para>
  731. To add an owner to a group, simply call the
  732. <methodname>addOwnerToGroup()</methodname> convenience method:
  733. </para>
  734. <programlisting language="php"><![CDATA[
  735. $gdata->addOwnerToGroup('bar@somewhere.com', 'friends');
  736. ]]></programlisting>
  737. </sect3>
  738. <sect3 id="zend.gdata.gapps.groupOwners.retrieving">
  739. <title>Retrieving the list of the owner of a group</title>
  740. <para>
  741. The convenience method <methodname>retrieveGroupOwners()</methodname>
  742. can be used to retrieve the list of the owners of a group:
  743. </para>
  744. <programlisting language="php"><![CDATA[
  745. $feed = $gdata->retrieveGroupOwners('friends');
  746. foreach ($feed as $owner) {
  747. foreach ($owner->property as $p) {
  748. echo "Property Name: " . $p->name;
  749. echo "\nProperty Value: " . $p->value . "\n\n";
  750. }
  751. }
  752. ]]></programlisting>
  753. <para>
  754. Alternatively, construct a new OwnerQuery, set its groupId
  755. property to match the desired group id, and call
  756. <methodname>getOwnerFeed()</methodname> on a service object.
  757. </para>
  758. <programlisting language="php"><![CDATA[
  759. $query = $gdata->newOwnerQuery();
  760. $query->setGroupId('friends');
  761. $feed = $gdata->getOwnerFeed($query);
  762. foreach ($feed as $owner) {
  763. foreach ($owner->property as $p) {
  764. echo "Property Name: " . $p->name;
  765. echo "\nProperty Value: " . $p->value . "\n\n";
  766. }
  767. }
  768. ]]></programlisting>
  769. <para>
  770. This will create a <classname>Zend_Gdata_Gapps_OwnerFeed</classname>
  771. object which holds each member for the selected group.
  772. </para>
  773. </sect3>
  774. <sect3 id="zend.gdata.gapps.groupOwners.check">
  775. <title>Check to see if an email is the owner of a group</title>
  776. <para>
  777. To check to see if an email is the owner of a group, simply call
  778. the <methodname>isOwner()</methodname> convenience method:
  779. </para>
  780. <programlisting language="php"><![CDATA[
  781. $isOwner = $gdata->isOwner('bar@somewhere.com', 'friends');
  782. var_dump($isOwner);
  783. ]]></programlisting>
  784. <para>
  785. The method returns a boolean value. If the email is the owner of
  786. the group specified, the method returns true, else it returns false.
  787. </para>
  788. </sect3>
  789. <sect3 id="zend.gdata.gapps.groupOwners.removing">
  790. <title>Removing an owner from a group</title>
  791. <para>
  792. To remove an owner from a group, call the
  793. <methodname>removeOwnerFromGroup()</methodname> convenience
  794. method:
  795. </para>
  796. <programlisting language="php"><![CDATA[
  797. $gdata->removeOwnerFromGroup('baz@somewhere.com', 'friends');
  798. ]]></programlisting>
  799. </sect3>
  800. </sect2>
  801. <sect2 id="zend.gdata.gapps.emailLists">
  802. <title>Interacting with email lists</title>
  803. <para>
  804. Email lists allow several users to retrieve email addressed to a
  805. single email address. Users do not need to be a
  806. member of this domain in order to subscribe to an email list
  807. provided their complete email address (including domain) is used.
  808. </para>
  809. <para>
  810. Each email list on a domain is represented as an instance of
  811. <classname>Zend_Gdata_Gapps_EmailListEntry</classname>.
  812. </para>
  813. <sect3 id="zend.gdata.gapps.emailLists.creating">
  814. <title>Creating an email list</title>
  815. <para>
  816. Email lists can be created by calling the
  817. <methodname>createEmailList()</methodname> convenience method:
  818. </para>
  819. <programlisting language="php"><![CDATA[
  820. $gdata->createEmailList('friends');
  821. ]]></programlisting>
  822. <para>
  823. Email lists can also be created by instantiating
  824. EmailListEntry, providing a name for the list, then calling
  825. <methodname>insertEmailList()</methodname> on a service object to upload
  826. the entry to the server.
  827. </para>
  828. <programlisting language="php"><![CDATA[
  829. $list = $gdata->newEmailListEntry();
  830. $list->emailList = $gdata->newEmailList('friends');
  831. $list = $gdata->insertEmailList($list);
  832. ]]></programlisting>
  833. </sect3>
  834. <sect3 id="zend.gdata.gapps.emailList.retrieve">
  835. <title>Retrieving all email lists to which a recipient is subscribed</title>
  836. <para>
  837. To retrieve all email lists to which a particular recipient is
  838. subscribed, call the <methodname>retrieveEmailLists()</methodname>
  839. convenience method:
  840. </para>
  841. <programlisting language="php"><![CDATA[
  842. $feed = $gdata->retrieveEmailLists('baz@somewhere.com');
  843. foreach ($feed as $list) {
  844. echo ' * ' . $list->emailList->name . "\n";
  845. }
  846. ]]></programlisting>
  847. <para>
  848. This will create a <classname>Zend_Gdata_Gapps_EmailListFeed</classname> object
  849. which holds each email list associated with the specified recipient.
  850. </para>
  851. <para>
  852. Alternatively, create a new <classname>Zend_Gdata_Gapps_EmailListQuery</classname>,
  853. set its recipient property to the desired email address, and
  854. submit the query by calling <methodname>getEmailListFeed()</methodname> on
  855. a service object.
  856. </para>
  857. <programlisting language="php"><![CDATA[
  858. $query = $gdata->newEmailListQuery();
  859. $query->setRecipient('baz@somewhere.com');
  860. $feed = $gdata->getEmailListFeed($query);
  861. foreach ($feed as $list) {
  862. echo ' * ' . $list->emailList->name . "\n";
  863. }
  864. ]]></programlisting>
  865. </sect3>
  866. <sect3 id="zend.gdata.gapps.emailLists.retrievingAll">
  867. <title>Retrieving all email lists in a domain</title>
  868. <para>
  869. To retrieve all email lists in a domain, call the convenience
  870. method <methodname>retrieveAllEmailLists()</methodname>.
  871. </para>
  872. <programlisting language="php"><![CDATA[
  873. $feed = $gdata->retrieveAllEmailLists();
  874. foreach ($feed as $list) {
  875. echo ' * ' . $list->emailList->name . "\n";
  876. }
  877. ]]></programlisting>
  878. <para>
  879. This will create a <classname>Zend_Gdata_Gapps_EmailListFeed</classname> object
  880. which holds each email list on the domain.
  881. </para>
  882. <para>
  883. Alternatively, call <methodname>getEmailListFeed()</methodname> on a
  884. service object with no arguments.
  885. </para>
  886. <programlisting language="php"><![CDATA[
  887. $feed = $gdata->getEmailListFeed();
  888. foreach ($feed as $list) {
  889. echo ' * ' . $list->emailList->name . "\n";
  890. }
  891. ]]></programlisting>
  892. </sect3>
  893. <sect3 id="zend.gdata.gapps.emailList.deleting">
  894. <title>Deleting an email list</title>
  895. <para>
  896. To delete an email list, call the deleteEmailList()
  897. convenience method:
  898. </para>
  899. <programlisting language="php"><![CDATA[
  900. $gdata->deleteEmailList('friends');
  901. ]]></programlisting>
  902. </sect3>
  903. </sect2>
  904. <sect2 id="zend.gdata.gapps.emailListRecipients">
  905. <title>Interacting with email list recipients</title>
  906. <para>
  907. Each recipient subscribed to an email list is represented by an
  908. instance of <classname>Zend_Gdata_Gapps_EmailListRecipient</classname>. Through this
  909. class, individual recipients can be added and removed from email
  910. lists.
  911. </para>
  912. <sect3 id="zend.gdata.gapps.emailListRecipients.adding">
  913. <title>Adding a recipient to an email list</title>
  914. <para>
  915. To add a recipient to an email list, simply call the
  916. <methodname>addRecipientToEmailList()</methodname> convenience method:
  917. </para>
  918. <programlisting language="php"><![CDATA[
  919. $gdata->addRecipientToEmailList('bar@somewhere.com', 'friends');
  920. ]]></programlisting>
  921. </sect3>
  922. <sect3 id="zend.gdata.gapps.emailListRecipients.retrieving">
  923. <title>Retrieving the list of subscribers to an email list</title>
  924. <para>
  925. The convenience method <methodname>retrieveAllRecipients()</methodname>
  926. can be used to retrieve the list of subscribers to an email list:
  927. </para>
  928. <programlisting language="php"><![CDATA[
  929. $feed = $gdata->retrieveAllRecipients('friends');
  930. foreach ($feed as $recipient) {
  931. echo ' * ' . $recipient->who->email . "\n";
  932. }
  933. ]]></programlisting>
  934. <para>
  935. Alternatively, construct a new EmailListRecipientQuery, set
  936. its emailListName property to match the desired email list,
  937. and call <methodname>getEmailListRecipientFeed()</methodname> on a service
  938. object.
  939. </para>
  940. <programlisting language="php"><![CDATA[
  941. $query = $gdata->newEmailListRecipientQuery();
  942. $query->setEmailListName('friends');
  943. $feed = $gdata->getEmailListRecipientFeed($query);
  944. foreach ($feed as $recipient) {
  945. echo ' * ' . $recipient->who->email . "\n";
  946. }
  947. ]]></programlisting>
  948. <para>
  949. This will create a <classname>Zend_Gdata_Gapps_EmailListRecipientFeed</classname>
  950. object which holds each recipient for the selected email list.
  951. </para>
  952. </sect3>
  953. <sect3 id="zend.gdata.gapps.emailListRecipients.removing">
  954. <title>Removing a recipient from an email list</title>
  955. <para>
  956. To remove a recipient from an email list, call the
  957. <methodname>removeRecipientFromEmailList()</methodname> convenience
  958. method:
  959. </para>
  960. <programlisting language="php"><![CDATA[
  961. $gdata->removeRecipientFromEmailList('baz@somewhere.com', 'friends');
  962. ]]></programlisting>
  963. </sect3>
  964. </sect2>
  965. <sect2 id="zend.gdata.gapps.exceptions">
  966. <title>Handling errors</title>
  967. <para>
  968. In addition to the standard suite of exceptions thrown by
  969. <classname>Zend_Gdata</classname>, requests using the Provisioning
  970. <acronym>API</acronym> may also throw a
  971. <classname>Zend_Gdata_Gapps_ServiceException</classname>. These exceptions
  972. indicate that a <acronym>API</acronym> specific error occurred which prevents the
  973. request from completing.
  974. </para>
  975. <para>
  976. Each ServiceException instance may hold one or more Error objects.
  977. Each of these objects contains an error code, reason, and
  978. (optionally) the input which triggered the exception. A complete
  979. list of known error codes is provided in the Zend Framework <acronym>API</acronym>
  980. documentation under <classname>Zend_Gdata_Gapps_Error</classname>. Additionally, the
  981. authoritative error list is available online at <ulink
  982. url="http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html#appendix_d">Google
  983. Apps Provisioning <acronym>API</acronym> V2.0 Reference: Appendix D</ulink>.
  984. </para>
  985. <para>
  986. While the complete list of errors received is available within
  987. ServiceException as an array by calling <methodname>getErrors()</methodname>,
  988. often it is convenient to know if one specific error occurred. For
  989. these cases the presence of an error can be determined by calling
  990. <methodname>hasError()</methodname>.
  991. </para>
  992. <para>
  993. The following example demonstrates how to detect if a requested
  994. resource doesn't exist and handle the fault gracefully:
  995. </para>
  996. <programlisting language="php"><![CDATA[
  997. function retrieveUser ($username) {
  998. $query = $gdata->newUserQuery($username);
  999. try {
  1000. $user = $gdata->getUserEntry($query);
  1001. } catch (Zend_Gdata_Gapps_ServiceException $e) {
  1002. // Set the user to null if not found
  1003. if ($e->hasError(Zend_Gdata_Gapps_Error::ENTITY_DOES_NOT_EXIST)) {
  1004. $user = null;
  1005. } else {
  1006. throw $e;
  1007. }
  1008. }
  1009. return $user;
  1010. }
  1011. ]]></programlisting>
  1012. </sect2>
  1013. </sect1>