Zend_Gdata_Gapps.xml 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  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 <acronym>SHA-1</acronym> digest if
  115. <command>login->passwordHashFunction</command> is set to
  116. '<property>SHA-1</property>'.
  117. </para>
  118. </sect3>
  119. <sect3 id="zend.gdata.gapps.users.retrieving">
  120. <title>Retrieving a user account</title>
  121. <para>
  122. Individual user accounts can be retrieved by calling the
  123. <methodname>retrieveUser()</methodname> convenience method. If the user is
  124. not found, <constant>NULL</constant> will be returned.
  125. </para>
  126. <programlisting language="php"><![CDATA[
  127. $user = $gdata->retrieveUser('foo');
  128. echo 'Username: ' . $user->login->userName . "\n";
  129. echo 'Given Name: ' . $user->name->givenName . "\n";
  130. echo 'Family Name: ' . $user->name->familyName . "\n";
  131. echo 'Suspended: ' . ($user->login->suspended ? 'Yes' : 'No') . "\n";
  132. echo 'Admin: ' . ($user->login->admin ? 'Yes' : 'No') . "\n"
  133. echo 'Must Change Password: ' .
  134. ($user->login->changePasswordAtNextLogin ? 'Yes' : 'No') . "\n";
  135. echo 'Has Agreed To Terms: ' .
  136. ($user->login->agreedToTerms ? 'Yes' : 'No') . "\n";
  137. ]]></programlisting>
  138. <para>
  139. Users can also be retrieved by creating an
  140. instance of <classname>Zend_Gdata_Gapps_UserQuery</classname>, setting its username
  141. property to equal the username of the user that is to be
  142. retrieved, and calling <methodname>getUserEntry()</methodname> on a
  143. service object with that query.
  144. </para>
  145. <programlisting language="php"><![CDATA[
  146. $query = $gdata->newUserQuery('foo');
  147. $user = $gdata->getUserEntry($query);
  148. echo 'Username: ' . $user->login->userName . "\n";
  149. echo 'Given Name: ' . $user->login->givenName . "\n";
  150. echo 'Family Name: ' . $user->login->familyName . "\n";
  151. echo 'Suspended: ' . ($user->login->suspended ? 'Yes' : 'No') . "\n";
  152. echo 'Admin: ' . ($user->login->admin ? 'Yes' : 'No') . "\n"
  153. echo 'Must Change Password: ' .
  154. ($user->login->changePasswordAtNextLogin ? 'Yes' : 'No') . "\n";
  155. echo 'Has Agreed To Terms: ' .
  156. ($user->login->agreedToTerms ? 'Yes' : 'No') . "\n";
  157. ]]></programlisting>
  158. <para>
  159. If the specified user cannot be located a ServiceException
  160. will be thrown with an error code of
  161. <constant>Zend_Gdata_Gapps_Error::ENTITY_DOES_NOT_EXIST</constant>.
  162. ServiceExceptions will be covered in <link
  163. linkend="zend.gdata.gapps.exceptions">the exceptions chapter</link>.
  164. </para>
  165. </sect3>
  166. <sect3 id="zend.gdata.gapps.users.retrievingAll">
  167. <title>Retrieving all users in a domain</title>
  168. <para>
  169. To retrieve all users in a domain, call the
  170. <methodname>retrieveAllUsers()</methodname> convenience method.
  171. </para>
  172. <programlisting language="php"><![CDATA[
  173. $feed = $gdata->retrieveAllUsers();
  174. foreach ($feed as $user) {
  175. echo " * " . $user->login->username . ' (' . $user->name->givenName .
  176. ' ' . $user->name->familyName . ")\n";
  177. }
  178. ]]></programlisting>
  179. <para>
  180. This will create a <classname>Zend_Gdata_Gapps_UserFeed</classname> object which
  181. holds each user on the domain.
  182. </para>
  183. <para>
  184. Alternatively, call <methodname>getUserFeed()</methodname> with no
  185. options. Keep in mind that on larger
  186. domains this feed may be paged by the server. For more
  187. information on paging, see <link
  188. linkend="zend.gdata.introduction.paging">the paging chapter</link>.
  189. </para>
  190. <programlisting language="php"><![CDATA[
  191. $feed = $gdata->getUserFeed();
  192. foreach ($feed as $user) {
  193. echo " * " . $user->login->username . ' (' . $user->name->givenName .
  194. ' ' . $user->name->familyName . ")\n";
  195. }
  196. ]]></programlisting>
  197. </sect3>
  198. <sect3 id="zend.gdata.gapps.users.updating">
  199. <title>Updating a user account</title>
  200. <para>
  201. The easiest way to update a user account is to retrieve the
  202. user as described in the previous sections, make any desired
  203. changes, then call <methodname>save()</methodname> on that user. Any
  204. changes made will be propagated to the server.
  205. </para>
  206. <programlisting language="php"><![CDATA[
  207. $user = $gdata->retrieveUser('foo');
  208. $user->name->givenName = 'Foo';
  209. $user->name->familyName = 'Bar';
  210. $user = $user->save();
  211. ]]></programlisting>
  212. <sect4 id="zend.gdata.gapps.users.updating.resettingPassword">
  213. <title>Resetting a user's password</title>
  214. <para>
  215. A user's password can be reset to a new value by updating
  216. the <command>login->password</command> property.
  217. </para>
  218. <programlisting language="php"><![CDATA[
  219. $user = $gdata->retrieveUser('foo');
  220. $user->login->password = '••••••••';
  221. $user = $user->save();
  222. ]]></programlisting>
  223. <para>
  224. Note that it is not possible to recover a password in this
  225. manner as stored passwords are not made available via the
  226. Provisioning <acronym>API</acronym> for security reasons.
  227. </para>
  228. </sect4>
  229. <sect4 id="zend.gdata.gapps.users.updating.forcingPasswordChange">
  230. <title>Forcing a user to change their password</title>
  231. <para>
  232. A user can be forced to change their password at their
  233. next login by setting the
  234. <command>login->changePasswordAtNextLogin</command> property to
  235. <constant>TRUE</constant>.
  236. </para>
  237. <programlisting language="php"><![CDATA[
  238. $user = $gdata->retrieveUser('foo');
  239. $user->login->changePasswordAtNextLogin = true;
  240. $user = $user->save();
  241. ]]></programlisting>
  242. <para>
  243. Similarly, this can be undone by setting the
  244. <command>login->changePasswordAtNextLogin</command> property to
  245. <constant>FALSE</constant>.
  246. </para>
  247. </sect4>
  248. <sect4 id="zend.gdata.gapps.users.updating.suspendingAccount">
  249. <title>Suspending a user account</title>
  250. <para>
  251. Users can be restricted from logging in without deleting
  252. their user account by instead
  253. <emphasis>suspending</emphasis> their user account.
  254. Accounts can be suspended or restored by using the
  255. <methodname>suspendUser()</methodname> and
  256. <methodname>restoreUser()</methodname> convenience methods:
  257. </para>
  258. <programlisting language="php"><![CDATA[
  259. $gdata->suspendUser('foo');
  260. $gdata->restoreUser('foo');
  261. ]]></programlisting>
  262. <para>
  263. Alternatively, you can set the UserEntry's
  264. <command>login->suspended</command> property to
  265. <constant>TRUE</constant>.
  266. </para>
  267. <programlisting language="php"><![CDATA[
  268. $user = $gdata->retrieveUser('foo');
  269. $user->login->suspended = true;
  270. $user = $user->save();
  271. ]]></programlisting>
  272. <para>
  273. To restore the user's access, set the
  274. <command>login->suspended</command> property to
  275. <constant>FALSE</constant>.
  276. </para>
  277. </sect4>
  278. <sect4 id="zend.gdata.gapps.users.updating.grantingAdminRights">
  279. <title>Granting administrative rights</title>
  280. <para>
  281. Users can be granted the ability to administer your domain
  282. by setting their <command>login->admin</command> property to
  283. <constant>TRUE</constant>.
  284. </para>
  285. <programlisting language="php"><![CDATA[
  286. $user = $gdata->retrieveUser('foo');
  287. $user->login->admin = true;
  288. $user = $user->save();
  289. ]]></programlisting>
  290. <para>
  291. And as expected, setting a user's <command>login->admin</command>
  292. property to <constant>FALSE</constant> revokes their
  293. administrative rights.
  294. </para>
  295. </sect4>
  296. </sect3>
  297. <sect3 id="zend.gdata.gapps.users.deleting">
  298. <title>Deleting user accounts</title>
  299. <para>
  300. Deleting a user account to which you already hold a UserEntry
  301. is a simple as calling <methodname>delete()</methodname> on that
  302. entry.
  303. </para>
  304. <programlisting language="php"><![CDATA[
  305. $user = $gdata->retrieveUser('foo');
  306. $user->delete();
  307. ]]></programlisting>
  308. <para>
  309. If you do not have access to a UserEntry object for an
  310. account, use the <methodname>deleteUser()</methodname> convenience method.
  311. </para>
  312. <programlisting language="php"><![CDATA[
  313. $gdata->deleteUser('foo');
  314. ]]></programlisting>
  315. </sect3>
  316. </sect2>
  317. <sect2 id="zend.gdata.gapps.nicknames">
  318. <title>Interacting with nicknames</title>
  319. <para>
  320. Nicknames serve as email aliases for existing users. Each nickname
  321. contains precisely two key properties: its name and its owner. Any
  322. email addressed to a nickname is forwarded to the user who owns
  323. that nickname.
  324. </para>
  325. <para>
  326. Nicknames are represented as an instances of
  327. <classname>Zend_Gdata_Gapps_NicknameEntry</classname>.
  328. </para>
  329. <sect3 id="zend.gdata.gapps.nicknames.creating">
  330. <title>Creating a nickname</title>
  331. <para>
  332. Nicknames can be created by calling the
  333. <methodname>createNickname()</methodname> convenience method:
  334. </para>
  335. <programlisting language="php"><![CDATA[
  336. $gdata->createNickname('foo', 'bar');
  337. ]]></programlisting>
  338. <para>
  339. Nicknames can also be created by instantiating NicknameEntry,
  340. providing the nickname with a name and an owner, then calling
  341. <methodname>insertNickname()</methodname> on a service object to upload
  342. the entry to the server.
  343. </para>
  344. <programlisting language="php"><![CDATA[
  345. $nickname = $gdata->newNicknameEntry();
  346. $nickname->login = $gdata->newLogin('foo');
  347. $nickname->nickname = $gdata->newNickname('bar');
  348. $nickname = $gdata->insertNickname($nickname);
  349. ]]></programlisting>
  350. </sect3>
  351. <sect3 id="zend.gdata.gapps.nicknames.retrieving">
  352. <title>Retrieving a nickname</title>
  353. <para>
  354. Nicknames can be retrieved by calling the
  355. <methodname>retrieveNickname()</methodname> convenience method. This will
  356. return <constant>NULL</constant> if a user is not found.
  357. </para>
  358. <programlisting language="php"><![CDATA[
  359. $nickname = $gdata->retrieveNickname('bar');
  360. echo 'Nickname: ' . $nickname->nickname->name . "\n";
  361. echo 'Owner: ' . $nickname->login->username . "\n";
  362. ]]></programlisting>
  363. <para>
  364. Individual nicknames can also be retrieved by creating an
  365. instance of <classname>Zend_Gdata_Gapps_NicknameQuery</classname>, setting its
  366. nickname property to equal the nickname that is to be
  367. retrieved, and calling <methodname>getNicknameEntry()</methodname> on a
  368. service object with that query.
  369. </para>
  370. <programlisting language="php"><![CDATA[
  371. $query = $gdata->newNicknameQuery('bar');
  372. $nickname = $gdata->getNicknameEntry($query);
  373. echo 'Nickname: ' . $nickname->nickname->name . "\n";
  374. echo 'Owner: ' . $nickname->login->username . "\n";
  375. ]]></programlisting>
  376. <para>
  377. As with users, if no corresponding nickname is found a
  378. ServiceException will be thrown with an error code of
  379. <constant>Zend_Gdata_Gapps_Error::ENTITY_DOES_NOT_EXIST</constant>. Again, these
  380. will be discussed in <link
  381. linkend="zend.gdata.gapps.exceptions">the exceptions chapter</link>.
  382. </para>
  383. </sect3>
  384. <sect3 id="zend.gdata.gapps.nicknames.retrievingUser">
  385. <title>Retrieving all nicknames for a user</title>
  386. <para>
  387. To retrieve all nicknames associated with a given user, call
  388. the convenience method <methodname>retrieveNicknames()</methodname>.
  389. </para>
  390. <programlisting language="php"><![CDATA[
  391. $feed = $gdata->retrieveNicknames('foo');
  392. foreach ($feed as $nickname) {
  393. echo ' * ' . $nickname->nickname->name . "\n";
  394. }
  395. ]]></programlisting>
  396. <para>
  397. This will create a <classname>Zend_Gdata_Gapps_NicknameFeed</classname> object which
  398. holds each nickname associated with the specified user.
  399. </para>
  400. <para>
  401. Alternatively, create a new <classname>Zend_Gdata_Gapps_NicknameQuery</classname>,
  402. set its username property to the desired user, and submit the
  403. query by calling <methodname>getNicknameFeed()</methodname> on a service
  404. object.
  405. </para>
  406. <programlisting language="php"><![CDATA[
  407. $query = $gdata->newNicknameQuery();
  408. $query->setUsername('foo');
  409. $feed = $gdata->getNicknameFeed($query);
  410. foreach ($feed as $nickname) {
  411. echo ' * ' . $nickname->nickname->name . "\n";
  412. }
  413. ]]></programlisting>
  414. </sect3>
  415. <sect3 id="zend.gdata.gapps.nicknames.retrievingAll">
  416. <title>Retrieving all nicknames in a domain</title>
  417. <para>
  418. To retrieve all nicknames in a feed, simply call the
  419. convenience method <methodname>retrieveAllNicknames()</methodname>
  420. </para>
  421. <programlisting language="php"><![CDATA[
  422. $feed = $gdata->retrieveAllNicknames();
  423. foreach ($feed as $nickname) {
  424. echo ' * ' . $nickname->nickname->name . ' => ' .
  425. $nickname->login->username . "\n";
  426. }
  427. ]]></programlisting>
  428. <para>
  429. This will create a <classname>Zend_Gdata_Gapps_NicknameFeed</classname> object which
  430. holds each nickname on the domain.
  431. </para>
  432. <para>
  433. Alternatively, call <methodname>getNicknameFeed()</methodname> on a
  434. service object with no arguments.
  435. </para>
  436. <programlisting language="php"><![CDATA[
  437. $feed = $gdata->getNicknameFeed();
  438. foreach ($feed as $nickname) {
  439. echo ' * ' . $nickname->nickname->name . ' => ' .
  440. $nickname->login->username . "\n";
  441. }
  442. ]]></programlisting>
  443. </sect3>
  444. <sect3 id="zend.gdata.gapps.nicknames.deleting">
  445. <title>Deleting a nickname</title>
  446. <para>
  447. Deleting a nickname to which you already hold a NicknameEntry
  448. for is a simple as calling <methodname>delete()</methodname> on that
  449. entry.
  450. </para>
  451. <programlisting language="php"><![CDATA[
  452. $nickname = $gdata->retrieveNickname('bar');
  453. $nickname->delete();
  454. ]]></programlisting>
  455. <para>
  456. For nicknames which you do not hold a NicknameEntry for, use
  457. the <methodname>deleteNickname()</methodname> convenience method.
  458. </para>
  459. <programlisting language="php"><![CDATA[
  460. $gdata->deleteNickname('bar');
  461. ]]></programlisting>
  462. </sect3>
  463. </sect2>
  464. <sect2 id="zend.gdata.gapps.groups">
  465. <title>Interacting with groups</title>
  466. <para>
  467. Google Groups allows people to post messages like an email list. Google
  468. is depreciating the Email List <acronym>API</acronym>. Google Groups provides some neat
  469. features like nested groups and group owners. If you want to start
  470. a new email lst, it is advisable to use Google Groups instead.
  471. Google's Email List is not compatible with Google Groups. So if you
  472. create an email list, it will not show up as a group. The opposite is
  473. true as well.
  474. </para>
  475. <para>
  476. Each group on a domain is represented as an instance of
  477. <classname>Zend_Gdata_Gapps_GroupEntry</classname>.
  478. </para>
  479. <sect3 id="zend.gdata.gapps.groups.creating">
  480. <title>Creating a group</title>
  481. <para>
  482. Groups can be created by calling the
  483. <methodname>createGroup()</methodname> convenience method:
  484. </para>
  485. <programlisting language="php"><![CDATA[
  486. $gdata->createGroup('friends', 'The Friends Group');
  487. ]]></programlisting>
  488. <para>
  489. Groups can also be created by instantiating
  490. GroupEntry, providing a group id and name for the group,
  491. then calling <methodname>insertGroup()</methodname> on a service
  492. object to upload the entry to the server.
  493. </para>
  494. <programlisting language="php"><![CDATA[
  495. $group = $gdata->newGroupEntry();
  496. $properties[0] = $this->newProperty();
  497. $properties[0]->name = 'groupId';
  498. $properties[0]->value = 'friends';
  499. $properties[1] = $this->newProperty();
  500. $properties[1]->name = 'groupName';
  501. $properties[1]->value = 'The Friends Group';
  502. $group->property = $properties;
  503. $group = $gdata->insertGroup($group);
  504. ]]></programlisting>
  505. </sect3>
  506. <sect3 id="zend.gdata.gapps.groups.retrieveGroup">
  507. <title>Retrieving an individual group</title>
  508. <para>
  509. To retrieve an individual group, call the
  510. <methodname>retrieveGroup()</methodname> convenience method:
  511. </para>
  512. <programlisting language="php"><![CDATA[
  513. $entry = $gdata->retrieveGroup('friends');
  514. foreach ($entry->property as $p) {
  515. echo "Property Name: " . $p->name;
  516. echo "\nProperty Value: " . $p->value . "\n\n";
  517. }
  518. ]]></programlisting>
  519. <para>
  520. This will create a <classname>Zend_Gdata_Gapps_GroupEntry</classname>
  521. object which holds the properties about the group.
  522. </para>
  523. <para>
  524. Alternatively, create a new <classname>Zend_Gdata_Gapps_GroupQuery</classname>,
  525. set its groupId property to the desired group id, and
  526. submit the query by calling <methodname>getGroupEntry()</methodname>
  527. on a service object.
  528. </para>
  529. <programlisting language="php"><![CDATA[
  530. $query = $gdata->newGroupQuery();
  531. $query->setGroupId('friends');
  532. $entry = $gdata->getGroupEntry($query);
  533. foreach ($entry->property as $p) {
  534. echo "Property Name: " . $p->name;
  535. echo "\nProperty Value: " . $p->value . "\n\n";
  536. }
  537. ]]></programlisting>
  538. </sect3>
  539. <sect3 id="zend.gdata.gapps.groups.retrievingAll">
  540. <title>Retrieving all groups in a domain</title>
  541. <para>
  542. To retrieve all groups in a domain, call the convenience
  543. method <methodname>retrieveAllGroups()</methodname>.
  544. </para>
  545. <programlisting language="php"><![CDATA[
  546. $feed = $gdata->retrieveAllGroups();
  547. foreach ($feed->entry as $entry) {
  548. foreach ($entry->property as $p) {
  549. echo "Property Name: " . $p->name;
  550. echo "\nProperty Value: " . $p->value . "\n\n";
  551. }
  552. echo "\n\n";
  553. }
  554. ]]></programlisting>
  555. <para>
  556. This will create a <classname>Zend_Gdata_Gapps_GroupFeed</classname>
  557. object which holds each group on the domain.
  558. </para>
  559. <para>
  560. Alternatively, call <methodname>getGroupFeed()</methodname> on a
  561. service object with no arguments.
  562. </para>
  563. <programlisting language="php"><![CDATA[
  564. $feed = $gdata->getGroupFeed();
  565. foreach ($feed->entry as $entry) {
  566. foreach ($entry->property as $p) {
  567. echo "Property Name: " . $p->name;
  568. echo "\nProperty Value: " . $p->value . "\n\n";
  569. }
  570. echo "\n\n";
  571. }
  572. ]]></programlisting>
  573. </sect3>
  574. <sect3 id="zend.gdata.gapps.groups.deleting">
  575. <title>Deleting a group</title>
  576. <para>
  577. To delete a group, call the <methodname>deleteGroup()</methodname> convenience
  578. method:
  579. </para>
  580. <programlisting language="php"><![CDATA[
  581. $gdata->deleteGroup('friends');
  582. ]]></programlisting>
  583. </sect3>
  584. <sect3 id="zend.gdata.gapps.groups.updating">
  585. <title>Updating a group</title>
  586. <para>
  587. Groups can be updated by calling the
  588. <methodname>updateGroup()</methodname> convenience method:
  589. </para>
  590. <programlisting language="php"><![CDATA[
  591. $gdata->updateGroup('group-id-here', 'Group Name Here');
  592. ]]></programlisting>
  593. <para>
  594. The first parameter is required. The second, third and fourth parameter,
  595. representing the group name, group descscription, and email permission,
  596. respectively are optional. Setting any of these optional parameters
  597. to null will not update that item.
  598. </para>
  599. </sect3>
  600. <sect3 id="zend.gdata.gapps.groups.retrieve">
  601. <title>Retrieving all groups to which a person is a member</title>
  602. <para>
  603. To retrieve all groups to which a particular person is a
  604. member, call the <methodname>retrieveGroups()</methodname>
  605. convenience method:
  606. </para>
  607. <programlisting language="php"><![CDATA[
  608. $feed = $gdata->retrieveGroups('baz@somewhere.com');
  609. foreach ($feed->entry as $entry) {
  610. foreach ($entry->property as $p) {
  611. echo "Property Name: " . $p->name;
  612. echo "\nProperty Value: " . $p->value . "\n\n";
  613. }
  614. echo "\n\n";
  615. }
  616. ]]></programlisting>
  617. <para>
  618. This will create a <classname>Zend_Gdata_Gapps_GroupFeed</classname>
  619. object which holds each group associated with the specified member.
  620. </para>
  621. <para>
  622. Alternatively, create a new <classname>Zend_Gdata_Gapps_GroupQuery</classname>,
  623. set its member property to the desired email address, and
  624. submit the query by calling <methodname>getGroupFeed()</methodname>
  625. on a service object.
  626. </para>
  627. <programlisting language="php"><![CDATA[
  628. $query = $gdata->newGroupQuery();
  629. $query->setMember('baz@somewhere.com');
  630. $feed = $gdata->getGroupFeed($query);
  631. foreach ($feed->entry as $entry) {
  632. foreach ($entry->property as $p) {
  633. echo "Property Name: " . $p->name;
  634. echo "\nProperty Value: " . $p->value . "\n\n";
  635. }
  636. echo "\n\n";
  637. }
  638. ]]></programlisting>
  639. </sect3>
  640. </sect2>
  641. <sect2 id="zend.gdata.gapps.groupMembers">
  642. <title>Interacting with group members</title>
  643. <para>
  644. Each member subscribed to a group is represented by an
  645. instance of <classname>Zend_Gdata_Gapps_MemberEntry</classname>.
  646. Through this class, individual recipients can be added and removed
  647. from groups.
  648. </para>
  649. <sect3 id="zend.gdata.gapps.groupMembers.adding">
  650. <title>Adding a member to a group</title>
  651. <para>
  652. To add a member to a group, simply call the
  653. <methodname>addMemberToGroup()</methodname> convenience method:
  654. </para>
  655. <programlisting language="php"><![CDATA[
  656. $gdata->addMemberToGroup('bar@somewhere.com', 'friends');
  657. ]]></programlisting>
  658. </sect3>
  659. <sect3 id="zend.gdata.gapps.groupMembers.check">
  660. <title>Check to see if member belongs to group</title>
  661. <para>
  662. To check to see if member belongs to group, simply call the
  663. <methodname>isMember()</methodname> convenience method:
  664. </para>
  665. <programlisting language="php"><![CDATA[
  666. $isMember = $gdata->isMember('bar@somewhere.com', 'friends');
  667. var_dump($isMember);
  668. ]]></programlisting>
  669. <para>
  670. The method returns a boolean value. If the member belongs to the
  671. group specified, the method returns true, else it returns false.
  672. </para>
  673. </sect3>
  674. <sect3 id="zend.gdata.gapps.groupMembers.removing">
  675. <title>Removing a member from a group</title>
  676. <para>
  677. To remove a member from a group, call the
  678. <methodname>removeMemberFromGroup()</methodname> convenience
  679. method:
  680. </para>
  681. <programlisting language="php"><![CDATA[
  682. $gdata->removeMemberFromGroup('baz', 'friends');
  683. ]]></programlisting>
  684. </sect3>
  685. <sect3 id="zend.gdata.gapps.groupMembers.retrieving">
  686. <title>Retrieving the list of members to a group</title>
  687. <para>
  688. The convenience method <methodname>retrieveAllMembers()</methodname>
  689. can be used to retrieve the list of members of a group:
  690. </para>
  691. <programlisting language="php"><![CDATA[
  692. $feed = $gdata->retrieveAllMembers('friends');
  693. foreach ($feed as $member) {
  694. foreach ($member->property as $p) {
  695. echo "Property Name: " . $p->name;
  696. echo "\nProperty Value: " . $p->value . "\n\n";
  697. }
  698. }
  699. ]]></programlisting>
  700. <para>
  701. Alternatively, construct a new MemberQuery, set its groupId
  702. property to match the desired group id, and call
  703. <methodname>getMemberFeed()</methodname> on a service object.
  704. </para>
  705. <programlisting language="php"><![CDATA[
  706. $query = $gdata->newMemberQuery();
  707. $query->setGroupId('friends');
  708. $feed = $gdata->getMemberFeed($query);
  709. foreach ($feed as $member) {
  710. foreach ($member->property as $p) {
  711. echo "Property Name: " . $p->name;
  712. echo "\nProperty Value: " . $p->value . "\n\n";
  713. }
  714. }
  715. ]]></programlisting>
  716. <para>
  717. This will create a <classname>Zend_Gdata_Gapps_MemberFeed</classname>
  718. object which holds each member for the selected group.
  719. </para>
  720. </sect3>
  721. </sect2>
  722. <sect2 id="zend.gdata.gapps.groupOwners">
  723. <title>Interacting with group owners</title>
  724. <para>
  725. Each owner associated with a group is represented by an
  726. instance of <classname>Zend_Gdata_Gapps_OwnerEntry</classname>.
  727. Through this class, individual owners can be added and removed
  728. from groups.
  729. </para>
  730. <sect3 id="zend.gdata.gapps.groupOwners.adding">
  731. <title>Adding an owner to a group</title>
  732. <para>
  733. To add an owner to a group, simply call the
  734. <methodname>addOwnerToGroup()</methodname> convenience method:
  735. </para>
  736. <programlisting language="php"><![CDATA[
  737. $gdata->addOwnerToGroup('bar@somewhere.com', 'friends');
  738. ]]></programlisting>
  739. </sect3>
  740. <sect3 id="zend.gdata.gapps.groupOwners.retrieving">
  741. <title>Retrieving the list of the owner of a group</title>
  742. <para>
  743. The convenience method <methodname>retrieveGroupOwners()</methodname>
  744. can be used to retrieve the list of the owners of a group:
  745. </para>
  746. <programlisting language="php"><![CDATA[
  747. $feed = $gdata->retrieveGroupOwners('friends');
  748. foreach ($feed as $owner) {
  749. foreach ($owner->property as $p) {
  750. echo "Property Name: " . $p->name;
  751. echo "\nProperty Value: " . $p->value . "\n\n";
  752. }
  753. }
  754. ]]></programlisting>
  755. <para>
  756. Alternatively, construct a new OwnerQuery, set its groupId
  757. property to match the desired group id, and call
  758. <methodname>getOwnerFeed()</methodname> on a service object.
  759. </para>
  760. <programlisting language="php"><![CDATA[
  761. $query = $gdata->newOwnerQuery();
  762. $query->setGroupId('friends');
  763. $feed = $gdata->getOwnerFeed($query);
  764. foreach ($feed as $owner) {
  765. foreach ($owner->property as $p) {
  766. echo "Property Name: " . $p->name;
  767. echo "\nProperty Value: " . $p->value . "\n\n";
  768. }
  769. }
  770. ]]></programlisting>
  771. <para>
  772. This will create a <classname>Zend_Gdata_Gapps_OwnerFeed</classname>
  773. object which holds each member for the selected group.
  774. </para>
  775. </sect3>
  776. <sect3 id="zend.gdata.gapps.groupOwners.check">
  777. <title>Check to see if an email is the owner of a group</title>
  778. <para>
  779. To check to see if an email is the owner of a group, simply call
  780. the <methodname>isOwner()</methodname> convenience method:
  781. </para>
  782. <programlisting language="php"><![CDATA[
  783. $isOwner = $gdata->isOwner('bar@somewhere.com', 'friends');
  784. var_dump($isOwner);
  785. ]]></programlisting>
  786. <para>
  787. The method returns a boolean value. If the email is the owner of
  788. the group specified, the method returns true, else it returns false.
  789. </para>
  790. </sect3>
  791. <sect3 id="zend.gdata.gapps.groupOwners.removing">
  792. <title>Removing an owner from a group</title>
  793. <para>
  794. To remove an owner from a group, call the
  795. <methodname>removeOwnerFromGroup()</methodname> convenience
  796. method:
  797. </para>
  798. <programlisting language="php"><![CDATA[
  799. $gdata->removeOwnerFromGroup('baz@somewhere.com', 'friends');
  800. ]]></programlisting>
  801. </sect3>
  802. </sect2>
  803. <sect2 id="zend.gdata.gapps.emailLists">
  804. <title>Interacting with email lists</title>
  805. <para>
  806. Email lists allow several users to retrieve email addressed to a
  807. single email address. Users do not need to be a
  808. member of this domain in order to subscribe to an email list
  809. provided their complete email address (including domain) is used.
  810. </para>
  811. <para>
  812. Each email list on a domain is represented as an instance of
  813. <classname>Zend_Gdata_Gapps_EmailListEntry</classname>.
  814. </para>
  815. <sect3 id="zend.gdata.gapps.emailLists.creating">
  816. <title>Creating an email list</title>
  817. <para>
  818. Email lists can be created by calling the
  819. <methodname>createEmailList()</methodname> convenience method:
  820. </para>
  821. <programlisting language="php"><![CDATA[
  822. $gdata->createEmailList('friends');
  823. ]]></programlisting>
  824. <para>
  825. Email lists can also be created by instantiating
  826. EmailListEntry, providing a name for the list, then calling
  827. <methodname>insertEmailList()</methodname> on a service object to upload
  828. the entry to the server.
  829. </para>
  830. <programlisting language="php"><![CDATA[
  831. $list = $gdata->newEmailListEntry();
  832. $list->emailList = $gdata->newEmailList('friends');
  833. $list = $gdata->insertEmailList($list);
  834. ]]></programlisting>
  835. </sect3>
  836. <sect3 id="zend.gdata.gapps.emailList.retrieve">
  837. <title>Retrieving all email lists to which a recipient is subscribed</title>
  838. <para>
  839. To retrieve all email lists to which a particular recipient is
  840. subscribed, call the <methodname>retrieveEmailLists()</methodname>
  841. convenience method:
  842. </para>
  843. <programlisting language="php"><![CDATA[
  844. $feed = $gdata->retrieveEmailLists('baz@somewhere.com');
  845. foreach ($feed as $list) {
  846. echo ' * ' . $list->emailList->name . "\n";
  847. }
  848. ]]></programlisting>
  849. <para>
  850. This will create a <classname>Zend_Gdata_Gapps_EmailListFeed</classname> object
  851. which holds each email list associated with the specified recipient.
  852. </para>
  853. <para>
  854. Alternatively, create a new <classname>Zend_Gdata_Gapps_EmailListQuery</classname>,
  855. set its recipient property to the desired email address, and
  856. submit the query by calling <methodname>getEmailListFeed()</methodname> on
  857. a service object.
  858. </para>
  859. <programlisting language="php"><![CDATA[
  860. $query = $gdata->newEmailListQuery();
  861. $query->setRecipient('baz@somewhere.com');
  862. $feed = $gdata->getEmailListFeed($query);
  863. foreach ($feed as $list) {
  864. echo ' * ' . $list->emailList->name . "\n";
  865. }
  866. ]]></programlisting>
  867. </sect3>
  868. <sect3 id="zend.gdata.gapps.emailLists.retrievingAll">
  869. <title>Retrieving all email lists in a domain</title>
  870. <para>
  871. To retrieve all email lists in a domain, call the convenience
  872. method <methodname>retrieveAllEmailLists()</methodname>.
  873. </para>
  874. <programlisting language="php"><![CDATA[
  875. $feed = $gdata->retrieveAllEmailLists();
  876. foreach ($feed as $list) {
  877. echo ' * ' . $list->emailList->name . "\n";
  878. }
  879. ]]></programlisting>
  880. <para>
  881. This will create a <classname>Zend_Gdata_Gapps_EmailListFeed</classname> object
  882. which holds each email list on the domain.
  883. </para>
  884. <para>
  885. Alternatively, call <methodname>getEmailListFeed()</methodname> on a
  886. service object with no arguments.
  887. </para>
  888. <programlisting language="php"><![CDATA[
  889. $feed = $gdata->getEmailListFeed();
  890. foreach ($feed as $list) {
  891. echo ' * ' . $list->emailList->name . "\n";
  892. }
  893. ]]></programlisting>
  894. </sect3>
  895. <sect3 id="zend.gdata.gapps.emailList.deleting">
  896. <title>Deleting an email list</title>
  897. <para>
  898. To delete an email list, call the <methodname>deleteEmailList()</methodname>
  899. convenience method:
  900. </para>
  901. <programlisting language="php"><![CDATA[
  902. $gdata->deleteEmailList('friends');
  903. ]]></programlisting>
  904. </sect3>
  905. </sect2>
  906. <sect2 id="zend.gdata.gapps.emailListRecipients">
  907. <title>Interacting with email list recipients</title>
  908. <para>
  909. Each recipient subscribed to an email list is represented by an
  910. instance of <classname>Zend_Gdata_Gapps_EmailListRecipient</classname>. Through this
  911. class, individual recipients can be added and removed from email
  912. lists.
  913. </para>
  914. <sect3 id="zend.gdata.gapps.emailListRecipients.adding">
  915. <title>Adding a recipient to an email list</title>
  916. <para>
  917. To add a recipient to an email list, simply call the
  918. <methodname>addRecipientToEmailList()</methodname> convenience method:
  919. </para>
  920. <programlisting language="php"><![CDATA[
  921. $gdata->addRecipientToEmailList('bar@somewhere.com', 'friends');
  922. ]]></programlisting>
  923. </sect3>
  924. <sect3 id="zend.gdata.gapps.emailListRecipients.retrieving">
  925. <title>Retrieving the list of subscribers to an email list</title>
  926. <para>
  927. The convenience method <methodname>retrieveAllRecipients()</methodname>
  928. can be used to retrieve the list of subscribers to an email list:
  929. </para>
  930. <programlisting language="php"><![CDATA[
  931. $feed = $gdata->retrieveAllRecipients('friends');
  932. foreach ($feed as $recipient) {
  933. echo ' * ' . $recipient->who->email . "\n";
  934. }
  935. ]]></programlisting>
  936. <para>
  937. Alternatively, construct a new EmailListRecipientQuery, set
  938. its emailListName property to match the desired email list,
  939. and call <methodname>getEmailListRecipientFeed()</methodname> on a service
  940. object.
  941. </para>
  942. <programlisting language="php"><![CDATA[
  943. $query = $gdata->newEmailListRecipientQuery();
  944. $query->setEmailListName('friends');
  945. $feed = $gdata->getEmailListRecipientFeed($query);
  946. foreach ($feed as $recipient) {
  947. echo ' * ' . $recipient->who->email . "\n";
  948. }
  949. ]]></programlisting>
  950. <para>
  951. This will create a <classname>Zend_Gdata_Gapps_EmailListRecipientFeed</classname>
  952. object which holds each recipient for the selected email list.
  953. </para>
  954. </sect3>
  955. <sect3 id="zend.gdata.gapps.emailListRecipients.removing">
  956. <title>Removing a recipient from an email list</title>
  957. <para>
  958. To remove a recipient from an email list, call the
  959. <methodname>removeRecipientFromEmailList()</methodname> convenience
  960. method:
  961. </para>
  962. <programlisting language="php"><![CDATA[
  963. $gdata->removeRecipientFromEmailList('baz@somewhere.com', 'friends');
  964. ]]></programlisting>
  965. </sect3>
  966. </sect2>
  967. <sect2 id="zend.gdata.gapps.exceptions">
  968. <title>Handling errors</title>
  969. <para>
  970. In addition to the standard suite of exceptions thrown by
  971. <classname>Zend_Gdata</classname>, requests using the Provisioning
  972. <acronym>API</acronym> may also throw a
  973. <classname>Zend_Gdata_Gapps_ServiceException</classname>. These exceptions
  974. indicate that a <acronym>API</acronym> specific error occurred which prevents the
  975. request from completing.
  976. </para>
  977. <para>
  978. Each ServiceException instance may hold one or more Error objects.
  979. Each of these objects contains an error code, reason, and
  980. (optionally) the input which triggered the exception. A complete
  981. list of known error codes is provided in Zend Framework's <acronym>API</acronym>
  982. documentation under <classname>Zend_Gdata_Gapps_Error</classname>. Additionally, the
  983. authoritative error list is available online at <ulink
  984. url="http://code.google.com/apis/apps/gdata_provisioning_api_v2.0_reference.html#appendix_d">Google
  985. Apps Provisioning <acronym>API</acronym> V2.0 Reference: Appendix D</ulink>.
  986. </para>
  987. <para>
  988. While the complete list of errors received is available within
  989. ServiceException as an array by calling <methodname>getErrors()</methodname>,
  990. often it is convenient to know if one specific error occurred. For
  991. these cases the presence of an error can be determined by calling
  992. <methodname>hasError()</methodname>.
  993. </para>
  994. <para>
  995. The following example demonstrates how to detect if a requested
  996. resource doesn't exist and handle the fault gracefully:
  997. </para>
  998. <programlisting language="php"><![CDATA[
  999. function retrieveUser ($username) {
  1000. $query = $gdata->newUserQuery($username);
  1001. try {
  1002. $user = $gdata->getUserEntry($query);
  1003. } catch (Zend_Gdata_Gapps_ServiceException $e) {
  1004. // Set the user to null if not found
  1005. if ($e->hasError(Zend_Gdata_Gapps_Error::ENTITY_DOES_NOT_EXIST)) {
  1006. $user = null;
  1007. } else {
  1008. throw $e;
  1009. }
  1010. }
  1011. return $user;
  1012. }
  1013. ]]></programlisting>
  1014. </sect2>
  1015. </sect1>