Zend_Service_Delicious.xml 18 KB

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