Zend_Service_Delicious
(Àº)´Â,
del.icio.us
ÀÇ XML ¹× JSON À¥ ¼ºñ½º¸¦ »ç¿ëÇϱâ À§ÇÑ ½ÉÇÃÇÑ API ÀÔ´Ï´Ù.
ÀÌ ÄÄÆÛ³ÍÆ®¿¡ ÀÇÇØ¼,del.icio.us ¿¡ÀÇ Åõ°í °¡¿îµ¥,
±ÇÇÑÀ» °¡Áö°í ÀÖ´Â °Í¿¡ ´ëÇÑ ÀÐ°í ¾²±â°¡ °¡´ÉÇÏ°Ô µË´Ï´Ù.
ÀüÀ¯ÀúÀÇ °ø°³ µ¥ÀÌÅÍ¿¡ÀÇ Àоîµé¿© Àü¿ëÀÇ ¾×¼¼½ºµµ °¡´ÉÇÕ´Ï´Ù.
·Ê 34.14. ¸ðµç Åõ°íÀÇ Ãëµæ
<?php
$delicious = new Zend_Service_Delicious('À¯Àú¸í', 'ÆÐ½º¿öµå');
$posts = $delicious->getAllPosts();
foreach ($posts as $post) {
echo "--n";
echo "ŸÀÌÆ²: {$post->getTitle()}n";
echo "URL: {$post->getUrl()}n";
}
Zend_Service_Delicious
¿¡´Â, Åõ°í¸¦ ÃëµæÇÏ´Â ¸Þ¼Òµå·Î¼
getPosts()
,getRecentPosts()
¹× getAllPosts()
ÀÇ 3Á¾·ù°¡ ÀÖ½À´Ï´Ù.
À̰͵éÀº ¸ðµÎ Zend_Service_Delicious_PostList
ÀÇ ÀνºÅϽº¸¦ µ¹·ÁÁÝ´Ï´Ù.¿©±â¿¡, ÃëµæÇÑ ¸ðµç Åõ°í°¡ Æ÷ÇԵ˴ϴÙ.
<?php
/**
* Àμö¿¡ ¸ÅÄ¡ÇÏ´Â Åõ°í¸¦ ÃëµæÇÑ´Ù.ÀÏÀÚ³ª url (À»)¸¦ »ý·« ÇßÀ» °æ¿ì´Â, ¹Ù·Î ¿·ÀÇ ÀÏÀÚ¸¦ »ç¿ëÇÑ´Ù
*
* @param string $tag ¿É¼ÇÀ¸·Î, ű׿¡ ÀÇÇÑ ¾ö¼±À» ½Ç½ÃÇÑ´Ù
* @param Zend_Date $dt ¿É¼ÇÀ¸·Î, ÀÏÀÚ¿¡ ÀÇÇÑ ¾ö¼±À» ½Ç½ÃÇÑ´Ù
* @param string $url ¿É¼ÇÀ¸·Î,url ¿¡ ÀÇÇÑ ¾ö¼±À» ½Ç½ÃÇÑ´Ù
* @return Zend_Service_Delicious_PostList
*/
public function getPosts($tag = null, $dt = null, $url = null);
/**
* ¹Ù·Î ¿·ÀÇ Åõ°í¸¦ ÃëµæÇÑ´Ù
*
* @param string $tag ¿É¼ÇÀ¸·Î, ű׿¡ ÀÇÇÑ ¾ö¼±À» ½Ç½ÃÇÑ´Ù
* @param string $count µ¹·ÁÁÖ´Â Åõ°íÀÇ ÃÖ´ë¼ö (µðÆúÆ®´Â 15)
* @return Zend_Service_Delicious_PostList
*/
public function getRecentPosts($tag = null, $count = 15);
/**
* ¸ðµç Åõ°í¸¦ ÃëµæÇÑ´Ù
*
* @param string $tag ¿É¼ÇÀ¸·Î, ű׿¡ ÀÇÇÑ ¾ö¼±À» ½Ç½ÃÇÑ´Ù
* @return Zend_Service_Delicious_PostList
*/
public function getAllPosts($tag = null);
Zend_Service_Delicious
ÀÇ ¸Þ¼Òµå getPosts()
,getAllPosts()
,
getRecentPosts()
¹× getUserPosts()
ÇÏÁö¸¸, ÀÌ Å¬·¡½ºÀÇ ÀνºÅϽº¸¦ µ¹·ÁÁÝ´Ï´Ù.
µ¥ÀÌÅÍ¿¡ÀÇ ¾×¼¼½º¸¦ °£´ÜÇÏ°Ô ½Ç½ÃÇϱâ À§ÇØ, ÀÌ Å¬·¡½º´Â
Countable
,Iterator
¹×
ArrayAccess
ÀÇ ¼¼ °³ÀÇ ÀÎÅÍÆäÀ̽º¸¦ ½ÇÀåÇϰí ÀÖ½À´Ï´Ù.
·Ê 34.15. Åõ°í À϶÷¿¡ÀÇ ¾×¼¼½º
<?php
$delicious = new Zend_Service_Delicious('À¯Àú¸í', 'ÆÐ½º¿öµå');
$posts = $delicious->getAllPosts();
// Åõ°í¼ö¸¦ ¼Á´Ï´Ù
echo count($posts);
// Åõ°í¸¦ Â÷·ÊÂ÷·Ê ó¸®ÇÕ´Ï´Ù
foreach ($posts as $post) {
echo "--n";
echo "ŸÀÌÆ²: {$post->getTitle()}n";
echo "URL: {$post->getUrl()}n";
}
// ¹è¿Ç³ÀÇ ¾×¼¼½º ¹æ½ÄÀ¸·Î Åõ°í¸¦ ÃëµæÇÕ´Ï´Ù
echo $posts[0]->getTitle();
![]() |
ÁÖÀÇ |
---|---|
¸Þ¼Òµå |
Åõ°í À϶÷ ¿ÀºêÁ§Æ®¿¡´Â, 2Á¾·ùÀÇ ÇÊÅ͸µ ±â´ÉÀÌ Â¥³Ö¾îÁö°í ÀÖ½À´Ï´Ù. ű׿¡ ÀÇÇÑ ÇÊÅ͸µ°úURL ¿¡ ÀÇÇÑ ÇÊÅ͸µÀÔ´Ï´Ù.
·Ê 34.16. ű×ÀÇ ÁöÁ¤¿¡ ÀÇÇÑ Åõ°í À϶÷ÀÇ ÇÊÅ͸µ
ƯÁ¤ÀÇ Å±׷ΠÅõ°í¸¦ Á¼È÷·Á¸é ,withTags()
(À»)¸¦ »ç¿ëÇÕ´Ï´Ù.
ÇϳªÀÇ Å±׷θ¸ ÃßÃâÀ» ½Ç½ÃÇÒ ¶§¿¡ Æí¸®ÇϰÔ,
withTag()
µµ ÁغñµÇ¾î ÀÖ½À´Ï´Ù.
<?php
$delicious = new Zend_Service_Delicious('username', 'password');
$posts = $delicious->getAllPosts();
// ÅÂ±× "php" ¹× "zend" ÇÏÁö¸¸ ÁöÁ¤µÇ¾î ÀÖ´Â Åõ°í¸¸À» Ç¥½ÃÇÕ´Ï´Ù
foreach ($posts->withTags(array('php', 'zend')) as $post) {
echo "ŸÀÌÆ²: {$post->getTitle()}n";
echo "URL: {$post->getUrl()}n";
}
·Ê 34.17. URL ÀÇ ÁöÁ¤¿¡ ÀÇÇÑ Åõ°í À϶÷ÀÇ ÇÊÅ͸µ
ÁöÁ¤ÇÑ Á¤±Ô Ç¥Çö¿¡ ¸ÅÄ¡ÇÑ´Ù URL ±×¸®°í Åõ°í¸¦ Á¼È÷·Á¸é
withUrl()
¸Þ¼Òµå¸¦ »ç¿ëÇÕ´Ï´Ù.
<?php
$delicious = new Zend_Service_Delicious('username', 'password');
$posts = $delicious->getAllPosts();
// URL ¿¡ "help" (À»)¸¦ Æ÷ÇÔÇÑ Åõ°í¸¸À» Ç¥½ÃÇÕ´Ï´Ù
foreach ($posts->withUrl('/help/') as $post) {
echo "ŸÀÌÆ²: {$post->getTitle()}n";
echo "URL: {$post->getUrl()}n";
}
·Ê 34.18. Åõ°íÀÇ ÆíÁý
<?php
$delicious = new Zend_Service_Delicious('À¯Àú¸í', 'ÆÐ½º¿öµå');
$posts = $delicious->getPosts();
// ŸÀÌÆ²À» ¼³Á¤ÇÕ´Ï´Ù
$posts[0]->setTitle('»õ·Î¿î ŸÀÌÆ²');
// º¯°æÀ» º¸Á¸ÇÕ´Ï´Ù
$posts[0]->save();
·Ê 34.19. ¸Þ¼Òµå ÄÝÀÇ ¿¬°á
¸ðµç ¼³Á¤¿ë ¸Þ¼Òµå´Â post ¿ÀºêÁ§Æ®¸¦ µ¹·ÁÁֹǷÎ, ¡¸È帣´Â ÀÎÅÍÆäÀ̽º¡¹¸¦ »ç¿ëÇØ ¸Þ¼Òµå ÄÝÀ» ¿¬°áÇÒ ¼ö ÀÖ½À´Ï´Ù.
<?php
$delicious = new Zend_Service_Delicious('À¯Àú¸í', 'ÆÐ½º¿öµå');
$posts = $delicious->getPosts();
$posts[0]->setTitle('»õ·Î¿î ŸÀÌÆ²')
->setNotes('»õ·Î¿î ¸Þ¸ð')
->save();
Åõ°í¸¦ »èÁ¦ÇÏ´Â ¹æ¹ýÀº 2ÅëÀÖ½À´Ï´Ù.
Åõ°íÀÇ URL (À»)¸¦ ÁöÁ¤ÇÏ´ÂÁö,post ¿ÀºêÁ§Æ®ÀÇ
delete()
¸Þ¼Òµå¸¦ ½ÇÇàÇÒ±îÀÇ ¸ÓÁö¾Ê¾ÆÀΰ¡ÀÔ´Ï´Ù.
·Ê 34.20. Åõ°íÀÇ »èÁ¦
<?php
$delicious = new Zend_Service_Delicious('À¯Àú¸í', 'ÆÐ½º¿öµå');
// URL (À»)¸¦ ÁöÁ¤ÇÕ´Ï´Ù
$delicious->deletePost('http://framework.zend.com');
// ȤÀº,post ¿ÀºêÁ§Æ®ÀÇ ¸Þ¼Òµå¸¦ ÄÝ ÇÕ´Ï´Ù
$posts = $delicious->getPosts();
$posts[0]->delete();
// deletePost() (À»)¸¦ »ç¿ëÇÏ´Â, ¶Ç ÇϳªÀÇ ¹æ¹ý
$delicious->deletePost($posts[0]->getUrl());
Åõ°í¸¦ Ãß°¡ÇÏ·Á¸é createNewPost()
¸Þ¼Òµå¸¦ ÄÝ ÇÒ Çʿ䰡 ÀÖ½À´Ï´Ù.
ÀÌ ¸Þ¼Òµå´Â Zend_Service_Delicious_Post
¿ÀºêÁ§Æ®¸¦ µ¹·ÁÁÝ´Ï´Ù.
Åõ°í¸¦ ÆíÁýÇϸé, ±×°ÍÀ» del.icio.us ÀÇ µ¥ÀÌŸº£À̽º¿¡ º¸Á¸Çϱâ À§Çؼ
save()
¸Þ¼Òµå¸¦ ÄÝ ÇÕ´Ï´Ù.
·Ê 34.21. Åõ°íÀÇ Ãß°¡
<?php
$delicious = new Zend_Service_Delicious('À¯Àú¸í', 'ÆÐ½º¿öµå');
// »õ·Î¿î Åõ°í¸¦ ÀÛ¼ºÇØ, º¸Á¸ÇÕ´Ï´Ù (¸Þ¼Òµå ÄÝÀÇ ¿¬°áÀ» »ç¿ëÇÕ´Ï´Ù)
$delicious->createNewPost('Zend Framework', 'http://framework.zend.com')
->setNotes('Zend Framework Homepage')
->save();
// »õ·Î¿î Åõ°í¸¦ ÀÛ¼ºÇØ, º¸Á¸ÇÕ´Ï´Ù (¸Þ¼Òµå ÄÝÀÇ ¿¬°áÀ» »ç¿ëÇÏÁö ¾Ê½À´Ï´Ù)
$newPost = $delicious->createNewPost('Zend Framework', 'http://framework.zend.com');
$newPost->setNotes('Zend Framework Homepage');
$newPost->save();
·Ê 34.22. ű×
<?php
$delicious = new Zend_Service_Delicious('À¯Àú¸í', 'ÆÐ½º¿öµå');
// ¸ðµç ű׸¦ ÃëµæÇÕ´Ï´Ù
print_r($delicious->getTags());
// ÅÂ±× ZF ÀÇ À̸§À» zendFramework (À¸)·Î º¯°æÇÕ´Ï´Ù
$delicious->renameTag('ZF', 'zendFramework');
·Ê 34.23. ¹øµé
<?php
$delicious = new Zend_Service_Delicious('À¯Àú¸í', 'ÆÐ½º¿öµå');
// ¸ðµç ¹øµéÀ» ÃëµæÇÕ´Ï´Ù
print_r($delicious->getBundles());
// someBundle ±×·¸´Ù°í ÇÏ´Â ¹øµéÀ» »èÁ¦ÇÕ´Ï´Ù
$delicious->deleteBundle('someBundle');
// ¹øµéÀ» Ãß°¡ÇÕ´Ï´Ù
$delicious->addBundle('newBundle', array('tag1', 'tag2'));
del.icio.us ÀÇ À¥ API (À»)¸¦ »ç¿ëÇϸé, ÀüÀ¯ÀúÀÇ °ø°³ µ¥ÀÌÅÍ¿¡ ¾×¼¼½º ÇÒ ¼ö ÀÖ°Ô µË´Ï´Ù.
Ç¥ 34.10. °ø°³ µ¥ÀÌÅ͸¦ ÃëµæÇϱâ À§ÇÑ ¸Þ¼Òµå
À̸§ | ¼³¸í | µ¹¾Æ°¡ °ªÀÇ ÇüÅ |
---|---|---|
getUserFans() |
¾î´À À¯Àú ÆÒÀ» ÃëµæÇÕ´Ï´Ù | Array |
getUserNetwork() |
¾î´À À¯ÀúÀÇ ³×Æ®¿öÅ©¸¦ ÃëµæÇÕ´Ï´Ù | Array |
getUserPosts() |
¾î´À À¯ÀúÀÇ Åõ°í¸¦ ÃëµæÇÕ´Ï´Ù | Zend_Service_Delicious_PostList |
getUserTags() |
¾î´À À¯ÀúÀÇ Å±׸¦ ÃëµæÇÕ´Ï´Ù | Array |
![]() |
ÁÖÀÇ |
---|---|
ÀÌ·¯ÇÑ ¸Þ¼Òµå¸¦ »ç¿ëÇÏ´Â °Í »ÓÀ̸é,
|
·Ê 34.24. °ø°³ µ¥ÀÌÅÍÀÇ Ãëµæ
<?php
// À¯Àú¸íÀ¸·Î ÆÐ½º¿öµå´Â ºÒÇÊ¿äÇÕ´Ï´Ù
$delicious = new Zend_Service_Delicious();
// someUser ÀÇ ÆÒÀ» ÃëµæÇÕ´Ï´Ù
print_r($delicious->getUserFans('someUser'));
// someUser ÀÇ ³×Æ®¿öÅ©¸¦ ÃëµæÇÕ´Ï´Ù
print_r($delicious->getUserNetwork('someUser'));
// someUser ÀÇ Å±׸¦ ÃëµæÇÕ´Ï´Ù
print_r($delicious->getUserTags('someUser'));
°ø°³ Åõ°í¸¦ getUserPosts()
¸Þ¼Òµå·Î ÃëµæÇϸé,
Zend_Service_Delicious_PostList
¿ÀºêÁ§Æ®°¡ µ¹·ÁÁÖ¾îÁý´Ï´Ù.¿©±â¿¡´Â
Zend_Service_Delicious_SimplePost
¿ÀºêÁ§Æ®°¡ Æ÷ÇԵǾî
±× Áß¿¡´Â URL (ÀÌ)³ª ŸÀÌÆ², ¸Þ¸ð, ű׶ó°í ÇÏ´Â Åõ°í¿¡ °üÇÑ ±âº» Á¤º¸°¡ Æ÷ÇԵ˴ϴÙ.
Ç¥ 34.11. Zend_Service_Delicious_SimplePost
Ŭ·¡½ºÀÇ ¸Þ¼Òµå
À̸§ | ¼³¸í | µ¹¾Æ°¡ °ªÀÇ ÇüÅ |
---|---|---|
getNotes() |
Åõ°íÀÇ ¸Þ¸ð¸¦ µ¹·ÁÁÝ´Ï´Ù | String |
getTags() |
Åõ°íÀÇ Å±׸¦ µ¹·ÁÁÝ´Ï´Ù | Array |
getTitle() |
Åõ°íÀÇ Å¸ÀÌÆ²À» µ¹·ÁÁÝ´Ï´Ù | String |
getUrl() |
Åõ°íÀÇ URL (À»)¸¦ µ¹·ÁÁÝ´Ï´Ù | String |
Zend_Service_Delicious
(Àº)´Â,Zend_Rest_Client
(À»)¸¦ »ç¿ëÇØ del.icio.us À¥ ¼ºñ½º¿¡ÀÇ HTTP ¸®Äù½ºÆ®¸¦ ÀÛ¼ºÇÕ´Ï´Ù.
Zend_Service_Delicious
ÇÏÁö¸¸ »ç¿ëÇÑ´Ù HTTP
Ŭ¶óÀÌ¾ðÆ®¸¦ º¯°æÇÏ·Á¸é ,Zend_Rest_Client
ÀÇ HTTP Ŭ¶óÀÌ¾ðÆ®¸¦ º¯°æÇÒ Çʿ䰡 ÀÖ½À´Ï´Ù.
·Ê 34.25. Zend_Rest_Client
ÀÇ HTTP Ŭ¶óÀ̾ðÆ®ÀÇ º¯°æ
<?php
$myHttpClient = new My_Http_Client();
Zend_Rest_Client::setHttpClient($myHttpClient);
Zend_Service_Delicious
±×¸®°í º¹¼öÀÇ ¸®Äù½ºÆ®¸¦ ÀÛ¼ºÇÒ ¶§¿¡
±×°ÍÀ» °í¼ÓÈÇÑ´Ù¸é, Á¢¼ÓÀ» Áö۵µ·Ï(µíÀÌ) HTTP Ŭ¶óÀÌ¾ðÆ®¸¦ ¼³Á¤Çϸé ÁÁÀ» °ÍÀÔ´Ï´Ù.
·Ê 34.26. HTTP Ŭ¶óÀÌ¾ðÆ®¸¦, Á¢¼ÓÀ» °è¼Ó º¸°ü À¯ÁöÇϵµ·Ï(µíÀÌ) ¼³Á¤ÇÑ´Ù
<?php
Zend_Rest_Client::getHttpClient()->setConfig(array(
'keepalive' => true
));
![]() |
ÁÖÀÇ |
---|---|
|