Zend_Service_Delicious.xml 19 KB

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