Zend_Service_Delicious.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <!-- EN-Revision: 15617 -->
  4. <sect1 id="zend.service.delicious">
  5. <title>Zend_Service_Delicious</title>
  6. <sect2 id="zend.service.delicious.introduction">
  7. <title>導入</title>
  8. <para>
  9. <classname>Zend_Service_Delicious</classname> は、
  10. <ulink url="http://del.icio.us">del.icio.us</ulink>
  11. の XML および JSON ウェブサービスを使用するためのシンプルな API です。
  12. このコンポーネントによって、del.icio.us への投稿のうち、
  13. 権限を持っているものについての読み書きが可能になります。
  14. 全ユーザの公開データへの読み込み専用のアクセスも可能です。
  15. </para>
  16. <example id="zend.service.delicious.introduction.getAllPosts">
  17. <title>すべての投稿の取得</title>
  18. <programlisting language="php"><![CDATA[
  19. $delicious = new Zend_Service_Delicious('ユーザ名', 'パスワード');
  20. $posts = $delicious->getAllPosts();
  21. foreach ($posts as $post) {
  22. echo "--\n";
  23. echo "タイトル: {$post->getTitle()}\n";
  24. echo "URL: {$post->getUrl()}\n";
  25. }
  26. ]]></programlisting>
  27. </example>
  28. </sect2>
  29. <sect2 id="zend.service.delicious.retrieving_posts">
  30. <title>投稿の取得</title>
  31. <para>
  32. <classname>Zend_Service_Delicious</classname> には、投稿を取得するメソッドとして
  33. <code>getPosts()</code>、<code>getRecentPosts()</code>
  34. および <code>getAllPosts()</code> の三種類があります。
  35. これらはすべて <classname>Zend_Service_Delicious_PostList</classname>
  36. のインスタンスを返します。ここに、取得したすべての投稿が含まれます。
  37. </para>
  38. <programlisting language="php"><![CDATA[
  39. /**
  40. * 引数にマッチする投稿を取得する。日付や url を省略した場合は
  41. * 直近の日付を使用する
  42. *
  43. * @param string $tag オプションで、タグによる絞込みを行う
  44. * @param Zend_Date $dt オプションで、日付による絞込みを行う
  45. * @param string $url オプションで、url による絞込みを行う
  46. * @return Zend_Service_Delicious_PostList
  47. */
  48. public function getPosts($tag = null, $dt = null, $url = null);
  49. /**
  50. * 直近の投稿を取得する
  51. *
  52. * @param string $tag オプションで、タグによる絞込みを行う
  53. * @param string $count 返す投稿の最大数 (デフォルトは 15)
  54. * @return Zend_Service_Delicious_PostList
  55. */
  56. public function getRecentPosts($tag = null, $count = 15);
  57. /**
  58. * すべての投稿を取得する
  59. *
  60. * @param string $tag オプションで、タグによる絞込みを行う
  61. * @return Zend_Service_Delicious_PostList
  62. */
  63. public function getAllPosts($tag = null);
  64. ]]></programlisting>
  65. </sect2>
  66. <sect2 id="zend.service.delicious.postlist">
  67. <title>Zend_Service_Delicious_PostList</title>
  68. <para>
  69. <classname>Zend_Service_Delicious</classname> のメソッド <code>getPosts()</code>、<code>getAllPosts()</code>、
  70. <code>getRecentPosts()</code> および <code>getUserPosts()</code>
  71. が、このクラスのインスタンスを返します。
  72. </para>
  73. <para>
  74. データへのアクセスを簡単に行うため、このクラスは
  75. <code>Countable</code>、<code>Iterator</code> および
  76. <code>ArrayAccess</code> の三つのインターフェイスを実装しています。
  77. </para>
  78. <example id="zend.service.delicious.postlist.accessing_post_lists">
  79. <title>投稿一覧へのアクセス</title>
  80. <programlisting language="php"><![CDATA[
  81. $delicious = new Zend_Service_Delicious('ユーザ名', 'パスワード');
  82. $posts = $delicious->getAllPosts();
  83. // 投稿数を数えます
  84. echo count($posts);
  85. // 投稿を順次処理します
  86. foreach ($posts as $post) {
  87. echo "--\n";
  88. echo "タイトル: {$post->getTitle()}\n";
  89. echo "URL: {$post->getUrl()}\n";
  90. }
  91. // 配列風のアクセス方式で投稿を取得します
  92. echo $posts[0]->getTitle();
  93. ]]></programlisting>
  94. </example>
  95. <note>
  96. <para>
  97. メソッド <code>ArrayAccess::offsetSet()</code> および <code>ArrayAccess::offsetUnset()</code>
  98. は、この実装では例外をスローします。つまり、<code>unset($posts[0]);</code>
  99. や <code>$posts[0] = 'A';</code> といったコードを書くと例外が発生するということです。
  100. というのも、これらのプロパティは読み込み専用だからです。
  101. </para>
  102. </note>
  103. <para>
  104. 投稿一覧オブジェクトには、二種類のフィルタリング機能が組み込まれています。
  105. タグによるフィルタリングと、URL によるフィルタリングです。
  106. </para>
  107. <example id="zend.service.delicious.postlist.example.withTags">
  108. <title>タグの指定による投稿一覧のフィルタリング</title>
  109. <para>
  110. 特定のタグで投稿を絞り込むには、<code>withTags()</code> を使用します。
  111. ひとつのタグでだけ絞り込みを行う際に便利なように、
  112. <code>withTag()</code> も用意されています。
  113. </para>
  114. <programlisting language="php"><![CDATA[
  115. $delicious = new Zend_Service_Delicious('ユーザ名', 'パスワード');
  116. $posts = $delicious->getAllPosts();
  117. // タグ "php" および "zend" が指定されている投稿のみを表示します
  118. foreach ($posts->withTags(array('php', 'zend')) as $post) {
  119. echo "タイトル: {$post->getTitle()}\n";
  120. echo "URL: {$post->getUrl()}\n";
  121. }
  122. ]]></programlisting>
  123. </example>
  124. <example id="zend.service.delicious.postlist.example.byUrl">
  125. <title>URL の指定による投稿一覧のフィルタリング</title>
  126. <para>
  127. 指定した正規表現にマッチする URL で投稿を絞り込むには
  128. <code>withUrl()</code> メソッドを使用します。
  129. </para>
  130. <programlisting language="php"><![CDATA[
  131. $delicious = new Zend_Service_Delicious('ユーザ名', 'パスワード');
  132. $posts = $delicious->getAllPosts();
  133. // URL に "help" を含む投稿のみを表示します
  134. foreach ($posts->withUrl('/help/') as $post) {
  135. echo "タイトル: {$post->getTitle()}\n";
  136. echo "URL: {$post->getUrl()}\n";
  137. }
  138. ]]></programlisting>
  139. </example>
  140. </sect2>
  141. <sect2 id="zend.service.delicious.editing_posts">
  142. <title>投稿の編集</title>
  143. <example id="zend.service.delicious.editing_posts.post_editing">
  144. <title>投稿の編集</title>
  145. <programlisting language="php"><![CDATA[
  146. $delicious = new Zend_Service_Delicious('ユーザ名', 'パスワード');
  147. $posts = $delicious->getPosts();
  148. // タイトルを設定します
  149. $posts[0]->setTitle('新しいタイトル');
  150. // 変更を保存します
  151. $posts[0]->save();
  152. ]]></programlisting>
  153. </example>
  154. <example id="zend.service.delicious.editing_posts.method_call_chaining">
  155. <title>メソッドコールの連結</title>
  156. <para>
  157. すべての設定用メソッドは post オブジェクトを返すので、
  158. 「流れるようなインターフェイス」を使用してメソッドコールを連結することができます。
  159. </para>
  160. <programlisting language="php"><![CDATA[
  161. $delicious = new Zend_Service_Delicious('ユーザ名', 'パスワード');
  162. $posts = $delicious->getPosts();
  163. $posts[0]->setTitle('新しいタイトル')
  164. ->setNotes('新しいメモ')
  165. ->save();
  166. ]]></programlisting>
  167. </example>
  168. </sect2>
  169. <sect2 id="zend.service.delicious.deleting_posts">
  170. <title>投稿の削除</title>
  171. <para>
  172. 投稿を削除する方法は二通りあります。
  173. 投稿の URL を指定するか、post オブジェクトの
  174. <code>delete()</code> メソッドを実行するかのいずれかです。
  175. </para>
  176. <example id="zend.service.delicious.deleting_posts.deleting_posts">
  177. <title>投稿の削除</title>
  178. <programlisting language="php"><![CDATA[
  179. $delicious = new Zend_Service_Delicious('ユーザ名', 'パスワード');
  180. // URL を指定します
  181. $delicious->deletePost('http://framework.zend.com');
  182. // あるいは、post オブジェクトのメソッドをコールします
  183. $posts = $delicious->getPosts();
  184. $posts[0]->delete();
  185. // deletePost() を使用する、もうひとつの方法
  186. $delicious->deletePost($posts[0]->getUrl());
  187. ]]></programlisting>
  188. </example>
  189. </sect2>
  190. <sect2 id="zend.service.delicious.adding_posts">
  191. <title>新しい投稿の追加</title>
  192. <para>
  193. 投稿を追加するには <code>createNewPost()</code> メソッドをコールする必要があります。
  194. このメソッドは <classname>Zend_Service_Delicious_Post</classname> オブジェクトを返します。
  195. 投稿を編集したら、それを del.icio.us のデータベースに保存するために
  196. <code>save()</code> メソッドをコールします。
  197. </para>
  198. <example id="zend.service.delicious.adding_posts.adding_a_post">
  199. <title>投稿の追加</title>
  200. <programlisting language="php"><![CDATA[
  201. $delicious = new Zend_Service_Delicious('ユーザ名', 'パスワード');
  202. // 新しい投稿を作成し、保存します (メソッドコールの連結を使用します)
  203. $delicious->createNewPost('Zend Framework', 'http://framework.zend.com')
  204. ->setNotes('Zend Framework Homepage')
  205. ->save();
  206. // 新しい投稿を作成し、保存します (メソッドコールの連結を使用しません)
  207. $newPost = $delicious->createNewPost('Zend Framework',
  208. 'http://framework.zend.com');
  209. $newPost->setNotes('Zend Framework Homepage');
  210. $newPost->save();
  211. ]]></programlisting>
  212. </example>
  213. </sect2>
  214. <sect2 id="zend.service.delicious.tags">
  215. <title>タグ</title>
  216. <example id="zend.service.delicious.tags.tags">
  217. <title>タグ</title>
  218. <programlisting language="php"><![CDATA[
  219. $delicious = new Zend_Service_Delicious('ユーザ名', 'パスワード');
  220. // すべてのタグを取得します
  221. print_r($delicious->getTags());
  222. // タグ ZF の名前を zendFramework に変更します
  223. $delicious->renameTag('ZF', 'zendFramework');
  224. ]]></programlisting>
  225. </example>
  226. </sect2>
  227. <sect2 id="zend.service.delicious.bundles">
  228. <title>バンドル</title>
  229. <example id="zend.service.delicious.bundles.example">
  230. <title>バンドル</title>
  231. <programlisting language="php"><![CDATA[
  232. $delicious = new Zend_Service_Delicious('ユーザ名', 'パスワード');
  233. // すべてのバンドルを取得します
  234. print_r($delicious->getBundles());
  235. // someBundle というバンドルを削除します
  236. $delicious->deleteBundle('someBundle');
  237. // バンドルを追加します
  238. $delicious->addBundle('newBundle', array('tag1', 'tag2'));
  239. ]]></programlisting>
  240. </example>
  241. </sect2>
  242. <sect2 id="zend.service.delicious.public_data">
  243. <title>公開データ</title>
  244. <para>
  245. del.icio.us のウェブ API を使用すると、全ユーザの公開データにアクセスできるようになります。
  246. </para>
  247. <table id="zend.service.delicious.public_data.functions_for_retrieving_public_data">
  248. <title>公開データを取得するためのメソッド</title>
  249. <tgroup cols="3">
  250. <thead>
  251. <row>
  252. <entry>名前</entry>
  253. <entry>説明</entry>
  254. <entry>返り値の型</entry>
  255. </row>
  256. </thead>
  257. <tbody>
  258. <row>
  259. <entry><code>getUserFans()</code></entry>
  260. <entry>あるユーザのファンを取得します</entry>
  261. <entry>Array</entry>
  262. </row>
  263. <row>
  264. <entry><code>getUserNetwork()</code></entry>
  265. <entry>あるユーザのネットワークを取得します</entry>
  266. <entry>Array</entry>
  267. </row>
  268. <row>
  269. <entry><code>getUserPosts()</code></entry>
  270. <entry>あるユーザの投稿を取得します</entry>
  271. <entry>Zend_Service_Delicious_PostList</entry>
  272. </row>
  273. <row>
  274. <entry><code>getUserTags()</code></entry>
  275. <entry>あるユーザのタグを取得します</entry>
  276. <entry>Array</entry>
  277. </row>
  278. </tbody>
  279. </tgroup>
  280. </table>
  281. <note>
  282. <para>
  283. これらのメソッドを使用するだけなら、
  284. <classname>Zend_Service_Delicious</classname> オブジェクトの作成時に
  285. ユーザ名とパスワードを指定する必要はありません。
  286. </para>
  287. </note>
  288. <example id="zend.service.delicious.public_data.retrieving_public_data">
  289. <title>公開データの取得</title>
  290. <programlisting language="php"><![CDATA[
  291. // ユーザ名とパスワードは不要です
  292. $delicious = new Zend_Service_Delicious();
  293. // someUser のファンを取得します
  294. print_r($delicious->getUserFans('someUser'));
  295. // someUser のネットワークを取得します
  296. print_r($delicious->getUserNetwork('someUser'));
  297. // someUser のタグを取得します
  298. print_r($delicious->getUserTags('someUser'));
  299. ]]></programlisting>
  300. </example>
  301. <sect3 id="zend.service.delicious.public_data.posts">
  302. <title>公開投稿</title>
  303. <para>
  304. 公開投稿を <code>getUserPosts()</code> メソッドで取得すると、
  305. <classname>Zend_Service_Delicious_PostList</classname> オブジェクトが返されます。ここには
  306. <classname>Zend_Service_Delicious_SimplePost</classname> オブジェクトが含まれ、
  307. その中には URL やタイトル、メモ、タグといった投稿に関する基本情報が含まれます。
  308. </para>
  309. <table id="zend.service.delicious.public_data.posts.SimplePost_methods">
  310. <title>Zend_Service_Delicious_SimplePost クラスのメソッド</title>
  311. <tgroup cols="3">
  312. <thead>
  313. <row>
  314. <entry>名前</entry>
  315. <entry>説明</entry>
  316. <entry>返り値の型</entry>
  317. </row>
  318. </thead>
  319. <tbody>
  320. <row>
  321. <entry><code>getNotes()</code></entry>
  322. <entry>投稿のメモを返します</entry>
  323. <entry>String</entry>
  324. </row>
  325. <row>
  326. <entry><code>getTags()</code></entry>
  327. <entry>投稿のタグを返します</entry>
  328. <entry>Array</entry>
  329. </row>
  330. <row>
  331. <entry><code>getTitle()</code></entry>
  332. <entry>投稿のタイトルを返します</entry>
  333. <entry>String</entry>
  334. </row>
  335. <row>
  336. <entry><code>getUrl()</code></entry>
  337. <entry>投稿の URL を返します</entry>
  338. <entry>String</entry>
  339. </row>
  340. </tbody>
  341. </tgroup>
  342. </table>
  343. </sect3>
  344. </sect2>
  345. <sect2 id="zend.service.delicious.httpclient">
  346. <title>HTTP クライアント</title>
  347. <para>
  348. <classname>Zend_Service_Delicious</classname> は、<code>Zend_Rest_Client</code>
  349. を使用して del.icio.us ウェブサービスへの HTTP リクエストを作成します。
  350. <classname>Zend_Service_Delicious</classname> が使用する HTTP
  351. クライアントを変更するには、<classname>Zend_Rest_Client</classname>
  352. の HTTP クライアントを変更する必要があります。
  353. </para>
  354. <example id="zend.service.delicious.httpclient.changing">
  355. <title>Zend_Rest_Client の HTTP クライアントの変更</title>
  356. <programlisting language="php"><![CDATA[
  357. $myHttpClient = new My_Http_Client();
  358. Zend_Rest_Client::setHttpClient($myHttpClient);
  359. ]]></programlisting>
  360. </example>
  361. <para>
  362. <classname>Zend_Service_Delicious</classname> で複数のリクエストを作成する際に
  363. それを高速化するなら、接続をキープするように HTTP クライアントを設定するとよいでしょう。
  364. </para>
  365. <example id="zend.service.delicious.httpclient.keepalive">
  366. <title>HTTP クライアントを、接続を保持し続けるように設定する</title>
  367. <programlisting language="php"><![CDATA[
  368. Zend_Rest_Client::getHttpClient()->setConfig(array(
  369. 'keepalive' => true
  370. ));
  371. ]]></programlisting>
  372. </example>
  373. <note>
  374. <para>
  375. <classname>Zend_Service_Delicious</classname> オブジェクトを作成する際に、
  376. <classname>Zend_Rest_Client</classname> の SSL トランスポートは
  377. <code>'ssl'</code> と設定されます。デフォルトの <code>'ssl2'</code>
  378. ではありません。これは、del.icio.us 側の問題で、
  379. <code>'ssl2'</code> を使用するとリクエストの処理に時間がかかる
  380. (ほぼ 2 秒くらい) ためです。
  381. </para>
  382. </note>
  383. </sect2>
  384. </sect1>
  385. <!--
  386. vim:se ts=4 sw=4 et:
  387. -->