cvs: pear /Services_Technorati/Services Technorati.php
| From: | James Stewart | Date: | Thu, 29 Sep 2005 23:24:13 +0000 |
| Subject: | cvs: pear /Services_Technorati/Services Technorati.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-35160@lists.php.net to get a copy of this message | ||
jystewart Thu Sep 29 19:24:13 2005 EDT
Modified files:
/pear/Services_Technorati/Services Technorati.php
Log:
Added ID when working with cache
Initialized return value for _checkOptions() where no options are given
http://cvs.php.net/diff.php/pear/Services_Technorati/Services/Technorati.php?r1=1.16&r2=1.17&ty=u
Index: pear/Services_Technorati/Services/Technorati.php
diff -u pear/Services_Technorati/Services/Technorati.php:1.16
pear/Services_Technorati/Services/Technorati.php:1.17
--- pear/Services_Technorati/Services/Technorati.php:1.16 Sun Sep 25 18:22:06 2005
+++ pear/Services_Technorati/Services/Technorati.php Thu Sep 29 19:24:12 2005
@@ -11,7 +11,7 @@
* @author James Stewart <james@jystewart.net>
* @copyright 2004-2005 James Stewart
* @license http://www.gnu.org/copyleft/lesser.html GNU LGPL
- * @version CVS: $Id: Technorati.php,v 1.16 2005/09/25 22:22:06 jystewart Exp $
+ * @version CVS: $Id: Technorati.php,v 1.17 2005/09/29 23:24:12 jystewart Exp $
* @link http://pear.php.net/package/Services_Technorati
*/
@@ -78,11 +78,24 @@
* @param string apiKey
* @param object cache
*/
- function Services_Technorati($apiKey, $cache = null)
+ function __construct($apiKey, $cache = null)
{
$this->_apiKey = $apiKey;
$this->_cache = $cache;
}
+
+ /**
+ * Create our client. A proxy to the __construct() method to maintain
+ * PHP4 compatibility.
+ *
+ * @access public
+ * @param string apiKey
+ * @param object cache
+ */
+ function Services_Technorati($apiKey, $cache = null)
+ {
+ $this->__construct($apiKey, $cache);
+ }
/**
* Factory methods to create client. This is in place to prepare for
@@ -126,7 +139,6 @@
function _general($query, $chief_param, $valid_options, $options = null)
{
/* Check for invalid options */
-
if (is_array($options)) {
$options = $this->_checkOptions($options, $valid_options);
if (PEAR::isError($options)) {
@@ -138,24 +150,22 @@
}
/* Build cache URI */
-
$filename = $query . "." . str_replace(" ", "_", $query);
if (is_array($options)) {
$filename = $filename . implode("_", $options);
}
/* Check if cached */
-
if (isset($this->_cache) and $cache = $this->_cache->get($filename)) {
return $cache;
}
/* Not cached */
-
$value = $this->_sendRequest($query, $options);
+ /* Save the data in the cache if appropriate. We use the filename as the ID */
if (! PEAR::isError($value) and !empty($this->_cache)) {
- $this->_cache->save($value);
+ $this->_cache->save($value, $filename);
}
return $value;
@@ -325,8 +335,8 @@
$filename = "attention.{$user}";
/* We don't cache this query */
-
$request =& new HTTP_Request($this->_apiUrl . "attention");
+ $request->addHeader('User-Agent', 'Services_Technorati');
$request->setMethod(HTTP_REQUEST_METHOD_POST);
$addfile = $request->addFile("attention.xml", $file);
@@ -336,7 +346,6 @@
$request->addPostData("username", $user);
$request->addPostData("password", md5($password));
- $request->addHeader('User-Agent', 'Services_Technorati');
$request->sendRequest();
@@ -366,15 +375,15 @@
/* Do all the nitty gritty HTTP stuff. Except attentionPost */
$url = sprintf("%s/%s?key=%s", $this->_apiUrl, $query, $this->_apiKey);
- $request =& new HTTP_Request($url);
-
+ $request =& new HTTP_Request($this->_apiUrl . "attention");
+ $request->addHeader('User-Agent', 'Services_Technorati');
+ $request->setURL($url);
+
if (is_array($options)) {
foreach ($options as $key => $value) {
$request->addQueryString($key, $value);
}
}
-
- $request->addHeader('User-Agent', 'Services_Technorati');
$request->sendRequest();
@@ -386,7 +395,7 @@
* _sendRequest and processes it, returning an unserialized version
*
* @access private
- * @param HTTP_Request_Response
+ * @param HTTP_Request $request the request object
* @return array|PEAR_Error
*/
function _processResponse(&$request)
@@ -431,6 +440,7 @@
*/
function _checkOptions($current, $accepted)
{
+ $accepted_options = array();
foreach ($current as $option => $value) {
if (in_array($option, $accepted)) {
$accepted_options[$option] = $value;