Zend_Service_Simpy

Introduction

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

Tags

When retrieved, tags are sorted in decreasing order (i.e. highest first) by the number of links that use the tag.

Example #3 Working With Tags

  1. $simpy = new Zend_Service_Simpy('yourusername', 'yourpassword');
  2.  
  3. /* Save a link with tags */
  4. $simpy->saveLink(
  5.     'Zend Framework' // Title
  6.     'http://framework.zend.com', // URL
  7.     Zend_Service_Simpy_Link::ACCESSTYPE_PUBLIC, // Access Type
  8.     'zend, framework, php' // Tags
  9. );
  10.  
  11. /* Get a list of all tags in use by links and notes */
  12. $tagSet = $simpy->getTags();
  13.  
  14. /* Display each tag with the number of links using it */
  15. foreach ($tagSet as $tag) {
  16.     echo $tag->getTag();
  17.     echo ' - ';
  18.     echo $tag->getCount();
  19.     echo '<br />';
  20. }
  21.  
  22. /* Remove the 'zend' tag from all links using it */
  23. $simpy->removeTag('zend');
  24.  
  25. /* Rename the 'framework' tag to 'frameworks' */
  26. $simpy->renameTag('framework', 'frameworks');
  27.  
  28. /* Split the 'frameworks' tag into 'framework' and
  29. 'development', which will remove the 'frameworks' tag for
  30. all links that use it and add the tags 'framework' and
  31. 'development' to all of those links */
  32. $simpy->splitTag('frameworks', 'framework', 'development');
  33.  
  34. /* Merge the 'framework' and 'development' tags back into
  35. 'frameworks', basically doing the opposite of splitting them */
  36. $simpy->mergeTags('framework', 'development', 'frameworks');

Notes

Notes can be saved, retrieved, and deleted. They are uniquely identified by a numeric ID value.

Example #4 Working With Notes

  1. $simpy = new Zend_Service_Simpy('yourusername', 'yourpassword');
  2.  
  3. /* Save a note */
  4. $simpy->saveNote(
  5.     'Test Note', // Title
  6.     'test,note', // Tags
  7.     'This is a test note.' // Description
  8. );
  9.  
  10. /* Overwrite an existing note */
  11. $simpy->saveNote(
  12.     'Updated Test Note', // Title
  13.     'test,note,updated', // Tags
  14.     'This is an updated test note.', // Description
  15.     $note->getId() // Unique identifier
  16. );
  17.  
  18. /* Search for the 10 most recently added notes */
  19. $noteSet = $simpy->getNotes(null, 10);
  20.  
  21. /* Display the notes */
  22. foreach ($noteSet as $note) {
  23.     echo '<p>';
  24.     echo $note->getTitle();
  25.     echo '<br />';
  26.     echo $note->getDescription();
  27.     echo '<br >';
  28.     echo $note->getTags();
  29.     echo '</p>';
  30. }
  31.  
  32. /* Search for all notes with 'PHP' in the title */
  33. $noteSet = $simpy->getNotes('title:PHP');
  34.  
  35. /* Search for all notes with 'PHP' in the title and
  36. without 'framework' in the description */
  37. $noteSet = $simpy->getNotes('+title:PHP -description:framework');
  38.  
  39. /* Delete a note */
  40. $simpy->deleteNote($note->getId());

Watchlists

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.

Example #5 Retrieving Watchlists

  1. $simpy = new Zend_Service_Simpy('yourusername', 'yourpassword');
  2.  
  3. /* Get a list of all watchlists */
  4. $watchlistSet = $simpy->getWatchlists();
  5.  
  6. /* Display data for each watchlist */
  7. foreach ($watchlistSet as $watchlist) {
  8.     echo $watchlist->getId();
  9.     echo '<br />';
  10.     echo $watchlist->getName();
  11.     echo '<br />';
  12.     echo $watchlist->getDescription();
  13.     echo '<br />';
  14.     echo $watchlist->getAddDate();
  15.     echo '<br />';
  16.     echo $watchlist->getNewLinks();
  17.     echo '<br />';
  18.  
  19.     foreach ($watchlist->getUsers() as $user) {
  20.         echo $user;
  21.         echo '<br />';
  22.     }
  23.  
  24.     foreach ($watchlist->getFilters() as $filter) {
  25.         echo $filter->getName();
  26.         echo '<br />';
  27.         echo $filter->getQuery();
  28.         echo '<br />';
  29.     }
  30. }
  31.  
  32. /* Get an individual watchlist by its identifier */
  33. $watchlist = $simpy->getWatchlist($watchlist->getId());
  34. $watchlist = $simpy->getWatchlist(1);
blog comments powered by Disqus