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
$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) {
}
/* 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.
Example #2 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());
}
Notes
Notes can be saved, retrieved, and deleted. They are uniquely
identified by a numeric ID value.
Example #4 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 $note-> getDescription();
}
/* 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
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
$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 $watchlist-> getName();
echo $watchlist-> getDescription();
echo $watchlist-> getAddDate();
echo $watchlist-> getNewLinks();
foreach ($watchlist->getUsers() as $user) {
}
foreach ($watchlist->getFilters() as $filter) {
echo $filter-> getQuery();
}
}
/* Get an individual watchlist by its identifier */
$watchlist = $simpy->getWatchlist($watchlist->getId());
$watchlist = $simpy->getWatchlist(1);
|
|