Zend_Service_ReCaptcha | Zend_Service Programmer's Reference Guide | Zend_Service_SlideShare

# 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

# Links

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.

Example #1 Querying Links

1. $simpy = new Zend_Service_Simpy('yourusername', 'yourpassword');
3. /* Search for the 10 links added most recently */
4. $linkQuery = new Zend_Service_Simpy_LinkQuery();
5. $linkQuery->setLimit(10);
7. /* Get and display the links */
8. $linkSet = $simpy->getLinks($linkQuery);
9. foreach ($linkSet as $link) {
10. echo '<a href="';
11. echo $link->getUrl();
12. echo '">';
13. echo $link->getTitle();
14. echo '</a><br />';
15. }
17. /* Search for the 5 links added most recently with 'PHP' in
18. the title */
19. $linkQuery->setQueryString('title:PHP');
20. $linkQuery->setLimit(5);
22. /* Search for all links with 'French' in the title and
23. 'language' in the tags */
24. $linkQuery->setQueryString('+title:French +tags:language');
26. /* Search for all links with 'French' in the title and without
27. 'travel' in the tags */
28. $linkQuery->setQueryString('+title:French -tags:travel');
30. /* Search for all links added on 12/9/06 */
31. $linkQuery->setDate('2006-12-09');
33. /* Search for all links added after 12/9/06 (excluding that
34. date) */
35. $linkQuery->setAfterDate('2006-12-09');
37. /* Search for all links added before 12/9/06 (excluding that
38. date) */
39. $linkQuery->setBeforeDate('2006-12-09');
41. /* Search for all links added between 12/1/06 and 12/9/06
42. (excluding those two dates) */
43. $linkQuery->setBeforeDate('2006-12-01');
44. $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.

Example #2 Modifying Links

1. $simpy = new Zend_Service_Simpy('yourusername', 'yourpassword');
3. /* Save a link */
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. 'Zend Framework home page' // Alternative title
10. 'This site rocks!' // Note
11. );
13. /* Overwrite the existing link with new data */
14. $simpy->saveLink(
15. 'Zend Framework'
16. 'http://framework.zend.com',
17. Zend_Service_Simpy_Link::ACCESSTYPE_PRIVATE, // Access Type has changed
18. 'php, zend, framework' // Tags have changed order
19. 'Zend Framework' // Alternative title has changed
20. 'This site REALLY rocks!' // Note has changed
21. );
23. /* Delete the link */
24. $simpy->deleteLink('http://framework.zend.com');
26. /* A really easy way to do spring cleaning on your links ;) */
27. $linkSet = $this->_simpy->getLinks();
28. foreach ($linkSet as $link) {
29. $this->_simpy->deleteLink($link->getUrl());
30. }

# 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');
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. );
11. /* Get a list of all tags in use by links and notes */
12. $tagSet = $simpy->getTags();
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. }
22. /* Remove the 'zend' tag from all links using it */
23. $simpy->removeTag('zend');
25. /* Rename the 'framework' tag to 'frameworks' */
26. $simpy->renameTag('framework', 'frameworks');
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');
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');
3. /* Save a note */
4. $simpy->saveNote(
5. 'Test Note', // Title
6. 'test,note', // Tags
7. 'This is a test note.' // Description
8. );
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. );
18. /* Search for the 10 most recently added notes */
19. $noteSet = $simpy->getNotes(null, 10);
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. }
32. /* Search for all notes with 'PHP' in the title */
33. $noteSet = $simpy->getNotes('title:PHP');
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');
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');
3. /* Get a list of all watchlists */
4. $watchlistSet = $simpy->getWatchlists();
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 />';
19. foreach ($watchlist->getUsers() as $user) {
20. echo $user;
21. echo '<br />';
22. }
24. foreach ($watchlist->getFilters() as $filter) {
25. echo $filter->getName();
26. echo '<br />';
27. echo $filter->getQuery();
28. echo '<br />';
29. }
30. }
32. /* Get an individual watchlist by its identifier */
33. $watchlist = $simpy->getWatchlist($watchlist->getId());
34. $watchlist = $simpy->getWatchlist(1);

Zend_Service_ReCaptcha | Zend_Service Programmer's Reference Guide | Zend_Service_SlideShare