Zend_Service_Simpy
is a lightweight wrapper for the free REST API available
for the Simpy social bookmarking service.
In order to use Zend_Service_Simpy
, you should already have a Simpy account.
To get an account, visit the Simpy web site. For more
information on the Simpy REST API, refer to the
Simpy REST API documentation.
The Simpy REST API allows developers to interact with specific aspects of the service that
the Simpy web site offers. The sections following will outline the use of
Zend_Service_Simpy
for each of these areas.
Links: Create, Retrieve, Update, Delete
Tags: Retrieve, Delete, Rename, Merge, Split
Notes: Create, Retrieve, Update, Delete
Watchlists: Get, Get All
When querying links, results are returned in descending order by date added. Links can be searched by title, nickname, tags, note, or even the content of the web page associated with the link. Simpy offers searching by any or all of these fields with phrases, boolean operators, and wildcards. See the search syntax and search fields sections of the Simpy FAQ for more information.
例 43.30. Querying Links
$simpy = new Zend_Service_Simpy('yourusername', 'yourpassword'); /* Search for the 10 links added most recently */ $linkQuery = new Zend_Service_Simpy_LinkQuery(); $linkQuery->setLimit(10); /* Get and display the links */ $linkSet = $simpy->getLinks($linkQuery); foreach ($linkSet as $link) { echo '<a href="'; echo $link->getUrl(); echo '">'; echo $link->getTitle(); echo '</a><br />'; } /* Search for the 5 links added most recently with 'PHP' in the title */ $linkQuery->setQueryString('title:PHP'); $linkQuery->setLimit(5); /* Search for all links with 'French' in the title and 'language' in the tags */ $linkQuery->setQueryString('+title:French +tags:language'); /* Search for all links with 'French' in the title and without 'travel' in the tags */ $linkQuery->setQueryString('+title:French -tags:travel'); /* Search for all links added on 12/9/06 */ $linkQuery->setDate('2006-12-09'); /* Search for all links added after 12/9/06 (excluding that date) */ $linkQuery->setAfterDate('2006-12-09'); /* Search for all links added before 12/9/06 (excluding that date) */ $linkQuery->setBeforeDate('2006-12-09'); /* Search for all links added between 12/1/06 and 12/9/06 (excluding those two dates) */ $linkQuery->setBeforeDate('2006-12-01'); $linkQuery->setAfterDate('2006-12-09');
Links are represented uniquely by their URLs. In other words, if an attempt is made to save a link that has the same URL as an existing link, data for the existing link will be overwritten with the data specified in the save attempt.
例 43.31. Modifying Links
$simpy = new Zend_Service_Simpy('yourusername', 'yourpassword'); /* Save a link */ $simpy->saveLink( 'Zend Framework' // Title 'http://framework.zend.com', // URL Zend_Service_Simpy_Link::ACCESSTYPE_PUBLIC, // Access Type 'zend, framework, php' // Tags 'Zend Framework home page' // Alternative title 'This site rocks!' // Note ); /* Overwrite the existing link with new data */ $simpy->saveLink( 'Zend Framework' 'http://framework.zend.com', Zend_Service_Simpy_Link::ACCESSTYPE_PRIVATE, // Access Type has changed 'php, zend, framework' // Tags have changed order 'Zend Framework' // Alternative title has changed 'This site REALLY rocks!' // Note has changed ); /* Delete the link */ $simpy->deleteLink('http://framework.zend.com'); /* A really easy way to do spring cleaning on your links ;) */ $linkSet = $this->_simpy->getLinks(); foreach ($linkSet as $link) { $this->_simpy->deleteLink($link->getUrl()); }
When retrieved, tags are sorted in decreasing order (i.e. highest first) by the number of links that use the tag.
例 43.32. Working With Tags
$simpy = new Zend_Service_Simpy('yourusername', 'yourpassword'); /* Save a link with tags */ $simpy->saveLink( 'Zend Framework' // Title 'http://framework.zend.com', // URL Zend_Service_Simpy_Link::ACCESSTYPE_PUBLIC, // Access Type 'zend, framework, php' // Tags ); /* Get a list of all tags in use by links and notes */ $tagSet = $simpy->getTags(); /* Display each tag with the number of links using it */ foreach ($tagSet as $tag) { echo $tag->getTag(); echo ' - '; echo $tag->getCount(); echo '<br />'; } /* Remove the 'zend' tag from all links using it */ $simpy->removeTag('zend'); /* Rename the 'framework' tag to 'frameworks' */ $simpy->renameTag('framework', 'frameworks'); /* Split the 'frameworks' tag into 'framework' and 'development', which will remove the 'frameworks' tag for all links that use it and add the tags 'framework' and 'development' to all of those links */ $simpy->splitTag('frameworks', 'framework', 'development'); /* Merge the 'framework' and 'development' tags back into 'frameworks', basically doing the opposite of splitting them */ $simpy->mergeTags('framework', 'development', 'frameworks');
Notes can be saved, retrieved, and deleted. They are uniquely identified by a numeric ID value.
例 43.33. Working With Notes
$simpy = new Zend_Service_Simpy('yourusername', 'yourpassword'); /* Save a note */ $simpy->saveNote( 'Test Note', // Title 'test,note', // Tags 'This is a test note.' // Description ); /* Overwrite an existing note */ $simpy->saveNote( 'Updated Test Note', // Title 'test,note,updated', // Tags 'This is an updated test note.', // Description $note->getId() // Unique identifier ); /* Search for the 10 most recently added notes */ $noteSet = $simpy->getNotes(null, 10); /* Display the notes */ foreach ($noteSet as $note) { echo '<p>'; echo $note->getTitle(); echo '<br />'; echo $note->getDescription(); echo '<br >'; echo $note->getTags(); echo '</p>'; } /* Search for all notes with 'PHP' in the title */ $noteSet = $simpy->getNotes('title:PHP'); /* Search for all notes with 'PHP' in the title and without 'framework' in the description */ $noteSet = $simpy->getNotes('+title:PHP -description:framework'); /* Delete a note */ $simpy->deleteNote($note->getId());
Watchlists cannot be created or removed using the API, only retrieved. Thus, you must set up a watchlist via the Simpy web site prior to attempting to access it using the API.
例 43.34. Retrieving Watchlists
$simpy = new Zend_Service_Simpy('yourusername', 'yourpassword'); /* Get a list of all watchlists */ $watchlistSet = $simpy->getWatchlists(); /* Display data for each watchlist */ foreach ($watchlistSet as $watchlist) { echo $watchlist->getId(); echo '<br />'; echo $watchlist->getName(); echo '<br />'; echo $watchlist->getDescription(); echo '<br />'; echo $watchlist->getAddDate(); echo '<br />'; echo $watchlist->getNewLinks(); echo '<br />'; foreach ($watchlist->getUsers() as $user) { echo $user; echo '<br />'; } foreach ($watchlist->getFilters() as $filter) { echo $filter->getName(); echo '<br />'; echo $filter->getQuery(); echo '<br />'; } } /* Get an individual watchlist by its identifier */ $watchlist = $simpy->getWatchlist($watchlist->getId()); $watchlist = $simpy->getWatchlist(1);