Zend_Service_Delicious.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.service.delicious">
  4. <title>Zend_Service_Delicious</title>
  5. <sect2 id="zend.service.delicious.introduction">
  6. <title>Introduction</title>
  7. <para>
  8. <classname>Zend_Service_Delicious</classname> is simple API for using
  9. <ulink url="http://del.icio.us">del.icio.us</ulink>
  10. XML and JSON web services. This component gives you read-write access to posts at del.icio.us
  11. if you provide credentials. It also allows read-only access to public data of all users.
  12. </para>
  13. <example id="zend.service.delicious.introduction.getAllPosts">
  14. <title>Get all posts</title>
  15. <programlisting language="php"><![CDATA[
  16. $delicious = new Zend_Service_Delicious('username', 'password');
  17. $posts = $delicious->getAllPosts();
  18. foreach ($posts as $post) {
  19. echo "--\n";
  20. echo "Title: {$post->getTitle()}\n";
  21. echo "Url: {$post->getUrl()}\n";
  22. }
  23. ]]></programlisting>
  24. </example>
  25. </sect2>
  26. <sect2 id="zend.service.delicious.retrieving_posts">
  27. <title>Retrieving posts</title>
  28. <para>
  29. <classname>Zend_Service_Delicious</classname> provides three methods for retrieving posts: <code>getPosts()</code>,
  30. <code>getRecentPosts()</code> and <code>getAllPosts()</code>. All of these
  31. methods return an instance of <classname>Zend_Service_Delicious_PostList</classname>, which
  32. holds all retrieved posts.
  33. </para>
  34. <programlisting language="php"><![CDATA[
  35. /**
  36. * Get posts matching the arguments. If no date or url is given,
  37. * most recent date will be used.
  38. *
  39. * @param string $tag Optional filtering by tag
  40. * @param Zend_Date $dt Optional filtering by date
  41. * @param string $url Optional filtering by url
  42. * @return Zend_Service_Delicious_PostList
  43. */
  44. public function getPosts($tag = null, $dt = null, $url = null);
  45. /**
  46. * Get recent posts
  47. *
  48. * @param string $tag Optional filtering by tag
  49. * @param string $count Maximal number of posts to be returned
  50. * (default 15)
  51. * @return Zend_Service_Delicious_PostList
  52. */
  53. public function getRecentPosts($tag = null, $count = 15);
  54. /**
  55. * Get all posts
  56. *
  57. * @param string $tag Optional filtering by tag
  58. * @return Zend_Service_Delicious_PostList
  59. */
  60. public function getAllPosts($tag = null);
  61. ]]></programlisting>
  62. </sect2>
  63. <sect2 id="zend.service.delicious.postlist">
  64. <title>Zend_Service_Delicious_PostList</title>
  65. <para>
  66. Instances of this class are returned by the <code>getPosts()</code>, <code>getAllPosts()</code>,
  67. <code>getRecentPosts()</code>, and <code>getUserPosts()</code> methods of <classname>Zend_Service_Delicious</classname>.
  68. </para>
  69. <para>
  70. For easier data access this class implements the <code>Countable</code>, <code>Iterator</code>, and
  71. <code>ArrayAccess</code> interfaces.
  72. </para>
  73. <example id="zend.service.delicious.postlist.accessing_post_lists">
  74. <title>Accessing post lists</title>
  75. <programlisting language="php"><![CDATA[
  76. $delicious = new Zend_Service_Delicious('username', 'password');
  77. $posts = $delicious->getAllPosts();
  78. // count posts
  79. echo count($posts);
  80. // iterate over posts
  81. foreach ($posts as $post) {
  82. echo "--\n";
  83. echo "Title: {$post->getTitle()}\n";
  84. echo "Url: {$post->getUrl()}\n";
  85. }
  86. // get post using array access
  87. echo $posts[0]->getTitle();
  88. ]]></programlisting>
  89. </example>
  90. <note>
  91. <para>
  92. The <code>ArrayAccess::offsetSet()</code> and <code>ArrayAccess::offsetUnset()</code> methods
  93. throw exceptions in this implementation. Thus, code like <code>unset($posts[0]);</code> and
  94. <code>$posts[0] = 'A';</code> will throw exceptions because these properties are read-only.
  95. </para>
  96. </note>
  97. <para>
  98. Post list objects have two built-in filtering capabilities. Post lists may be filtered by tags and by URL.
  99. </para>
  100. <example id="zend.service.delicious.postlist.example.withTags">
  101. <title>Filtering a Post List with Specific Tags</title>
  102. <para>
  103. Posts may be filtered by specific tags using <code>withTags()</code>. As a convenience,
  104. <code>withTag()</code> is also provided for when only a single tag needs to be specified.
  105. </para>
  106. <programlisting language="php"><![CDATA[
  107. $delicious = new Zend_Service_Delicious('username', 'password');
  108. $posts = $delicious->getAllPosts();
  109. // Print posts having "php" and "zend" tags
  110. foreach ($posts->withTags(array('php', 'zend')) as $post) {
  111. echo "Title: {$post->getTitle()}\n";
  112. echo "Url: {$post->getUrl()}\n";
  113. }
  114. ]]></programlisting>
  115. </example>
  116. <example id="zend.service.delicious.postlist.example.byUrl">
  117. <title>Filtering a Post List by URL</title>
  118. <para>
  119. Posts may be filtered by URL matching a specified regular expression using the <code>withUrl()</code>
  120. method:
  121. </para>
  122. <programlisting language="php"><![CDATA[
  123. $delicious = new Zend_Service_Delicious('username', 'password');
  124. $posts = $delicious->getAllPosts();
  125. // Print posts having "help" in the URL
  126. foreach ($posts->withUrl('/help/') as $post) {
  127. echo "Title: {$post->getTitle()}\n";
  128. echo "Url: {$post->getUrl()}\n";
  129. }
  130. ]]></programlisting>
  131. </example>
  132. </sect2>
  133. <sect2 id="zend.service.delicious.editing_posts">
  134. <title>Editing posts</title>
  135. <example id="zend.service.delicious.editing_posts.post_editing">
  136. <title>Post editing</title>
  137. <programlisting language="php"><![CDATA[
  138. $delicious = new Zend_Service_Delicious('username', 'password');
  139. $posts = $delicious->getPosts();
  140. // set title
  141. $posts[0]->setTitle('New title');
  142. // save changes
  143. $posts[0]->save();
  144. ]]></programlisting>
  145. </example>
  146. <example id="zend.service.delicious.editing_posts.method_call_chaining">
  147. <title>Method call chaining</title>
  148. <para>
  149. Every setter method returns the post object so that you can chain method calls using a fluent interface.
  150. </para>
  151. <programlisting language="php"><![CDATA[
  152. $delicious = new Zend_Service_Delicious('username', 'password');
  153. $posts = $delicious->getPosts();
  154. $posts[0]->setTitle('New title')
  155. ->setNotes('New notes')
  156. ->save();
  157. ]]></programlisting>
  158. </example>
  159. </sect2>
  160. <sect2 id="zend.service.delicious.deleting_posts">
  161. <title>Deleting posts</title>
  162. <para>
  163. There are two ways to delete a post, by specifying the post URL or by calling the <code>delete()</code>
  164. method upon a post object.
  165. </para>
  166. <example id="zend.service.delicious.deleting_posts.deleting_posts">
  167. <title>Deleting posts</title>
  168. <programlisting language="php"><![CDATA[
  169. $delicious = new Zend_Service_Delicious('username', 'password');
  170. // by specifying URL
  171. $delicious->deletePost('http://framework.zend.com');
  172. // or by calling the method upon a post object
  173. $posts = $delicious->getPosts();
  174. $posts[0]->delete();
  175. // another way of using deletePost()
  176. $delicious->deletePost($posts[0]->getUrl());
  177. ]]></programlisting>
  178. </example>
  179. </sect2>
  180. <sect2 id="zend.service.delicious.adding_posts">
  181. <title>Adding new posts</title>
  182. <para>
  183. To add a post you first need to call the <code>createNewPost()</code> method, which returns a
  184. <classname>Zend_Service_Delicious_Post</classname> object. When you edit the post, you need to save it
  185. to the del.icio.us database by calling the <code>save()</code> method.
  186. </para>
  187. <example id="zend.service.delicious.adding_posts.adding_a_post">
  188. <title>Adding a post</title>
  189. <programlisting language="php"><![CDATA[
  190. $delicious = new Zend_Service_Delicious('username', 'password');
  191. // create a new post and save it (with method call chaining)
  192. $delicious->createNewPost('Zend Framework', 'http://framework.zend.com')
  193. ->setNotes('Zend Framework Homepage')
  194. ->save();
  195. // create a new post and save it (without method call chaining)
  196. $newPost = $delicious->createNewPost('Zend Framework',
  197. 'http://framework.zend.com');
  198. $newPost->setNotes('Zend Framework Homepage');
  199. $newPost->save();
  200. ]]></programlisting>
  201. </example>
  202. </sect2>
  203. <sect2 id="zend.service.delicious.tags">
  204. <title>Tags</title>
  205. <example id="zend.service.delicious.tags.tags">
  206. <title>Tags</title>
  207. <programlisting language="php"><![CDATA[
  208. $delicious = new Zend_Service_Delicious('username', 'password');
  209. // get all tags
  210. print_r($delicious->getTags());
  211. // rename tag ZF to zendFramework
  212. $delicious->renameTag('ZF', 'zendFramework');
  213. ]]></programlisting>
  214. </example>
  215. </sect2>
  216. <sect2 id="zend.service.delicious.bundles">
  217. <title>Bundles</title>
  218. <example id="zend.service.delicious.bundles.example">
  219. <title>Bundles</title>
  220. <programlisting language="php"><![CDATA[
  221. $delicious = new Zend_Service_Delicious('username', 'password');
  222. // get all bundles
  223. print_r($delicious->getBundles());
  224. // delete bundle someBundle
  225. $delicious->deleteBundle('someBundle');
  226. // add bundle
  227. $delicious->addBundle('newBundle', array('tag1', 'tag2'));
  228. ]]></programlisting>
  229. </example>
  230. </sect2>
  231. <sect2 id="zend.service.delicious.public_data">
  232. <title>Public data</title>
  233. <para>
  234. The del.icio.us web API allows access to the public data of all users.
  235. </para>
  236. <table id="zend.service.delicious.public_data.functions_for_retrieving_public_data">
  237. <title>Methods for retrieving public data</title>
  238. <tgroup cols="3">
  239. <thead>
  240. <row>
  241. <entry>Name</entry>
  242. <entry>Description</entry>
  243. <entry>Return type</entry>
  244. </row>
  245. </thead>
  246. <tbody>
  247. <row>
  248. <entry><code>getUserFans()</code></entry>
  249. <entry>Retrieves fans of a user</entry>
  250. <entry>Array</entry>
  251. </row>
  252. <row>
  253. <entry><code>getUserNetwork()</code></entry>
  254. <entry>Retrieves network of a user</entry>
  255. <entry>Array</entry>
  256. </row>
  257. <row>
  258. <entry><code>getUserPosts()</code></entry>
  259. <entry>Retrieves posts of a user</entry>
  260. <entry>Zend_Service_Delicious_PostList</entry>
  261. </row>
  262. <row>
  263. <entry><code>getUserTags()</code></entry>
  264. <entry>Retrieves tags of a user</entry>
  265. <entry>Array</entry>
  266. </row>
  267. </tbody>
  268. </tgroup>
  269. </table>
  270. <note>
  271. <para>
  272. When using only these methods, a username and password combination is not required when constructing
  273. a new <classname>Zend_Service_Delicious</classname> object.
  274. </para>
  275. </note>
  276. <example id="zend.service.delicious.public_data.retrieving_public_data">
  277. <title>Retrieving public data</title>
  278. <programlisting language="php"><![CDATA[
  279. // username and password are not required
  280. $delicious = new Zend_Service_Delicious();
  281. // get fans of user someUser
  282. print_r($delicious->getUserFans('someUser'));
  283. // get network of user someUser
  284. print_r($delicious->getUserNetwork('someUser'));
  285. // get tags of user someUser
  286. print_r($delicious->getUserTags('someUser'));
  287. ]]></programlisting>
  288. </example>
  289. <sect3 id="zend.service.delicious.public_data.posts">
  290. <title>Public posts</title>
  291. <para>
  292. When retrieving public posts with the <code>getUserPosts()</code> method, a
  293. <classname>Zend_Service_Delicious_PostList</classname> object is returned, and it contains
  294. <classname>Zend_Service_Delicious_SimplePost</classname> objects, which contain basic information
  295. about the posts, including URL, title, notes, and tags.
  296. </para>
  297. <table id="zend.service.delicious.public_data.posts.SimplePost_methods">
  298. <title>Methods of the Zend_Service_Delicious_SimplePost class</title>
  299. <tgroup cols="3">
  300. <thead>
  301. <row>
  302. <entry>Name</entry>
  303. <entry>Description</entry>
  304. <entry>Return type</entry>
  305. </row>
  306. </thead>
  307. <tbody>
  308. <row>
  309. <entry><code>getNotes()</code></entry>
  310. <entry>Returns notes of a post</entry>
  311. <entry>String</entry>
  312. </row>
  313. <row>
  314. <entry><code>getTags()</code></entry>
  315. <entry>Returns tags of a post</entry>
  316. <entry>Array</entry>
  317. </row>
  318. <row>
  319. <entry><code>getTitle()</code></entry>
  320. <entry>Returns title of a post</entry>
  321. <entry>String</entry>
  322. </row>
  323. <row>
  324. <entry><code>getUrl()</code></entry>
  325. <entry>Returns URL of a post</entry>
  326. <entry>String</entry>
  327. </row>
  328. </tbody>
  329. </tgroup>
  330. </table>
  331. </sect3>
  332. </sect2>
  333. <sect2 id="zend.service.delicious.httpclient">
  334. <title>HTTP client</title>
  335. <para>
  336. <classname>Zend_Service_Delicious</classname> uses <classname>Zend_Rest_Client</classname> for making HTTP requests
  337. to the del.icio.us web service. To change which HTTP client <classname>Zend_Service_Delicious</classname>
  338. uses, you need to change the HTTP client of <classname>Zend_Rest_Client</classname>.
  339. </para>
  340. <example id="zend.service.delicious.httpclient.changing">
  341. <title>Changing the HTTP client of Zend_Rest_Client</title>
  342. <programlisting language="php"><![CDATA[
  343. $myHttpClient = new My_Http_Client();
  344. Zend_Rest_Client::setHttpClient($myHttpClient);
  345. ]]></programlisting>
  346. </example>
  347. <para>
  348. When you are making more than one request with <classname>Zend_Service_Delicious</classname> to speed your
  349. requests, it's better to configure your HTTP client to keep connections alive.
  350. </para>
  351. <example id="zend.service.delicious.httpclient.keepalive">
  352. <title>Configuring your HTTP client to keep connections alive</title>
  353. <programlisting language="php"><![CDATA[
  354. Zend_Rest_Client::getHttpClient()->setConfig(array(
  355. 'keepalive' => true
  356. ));
  357. ]]></programlisting>
  358. </example>
  359. <note>
  360. <para>
  361. When a <classname>Zend_Service_Delicious</classname> object is constructed, the SSL transport
  362. of <classname>Zend_Rest_Client</classname> is set to <code>'ssl'</code> rather than the default of
  363. <code>'ssl2'</code>. This is because del.icio.us has some problems with <code>'ssl2'</code>, such
  364. as requests taking a long time to complete (around 2 seconds).
  365. </para>
  366. </note>
  367. </sect2>
  368. </sect1>
  369. <!--
  370. vim:se ts=4 sw=4 et:
  371. -->