Source for file Response.php
Documentation is available at Response.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* Services_Yahoo Search Response
* Copyright 2005-2006 Martin Jansen
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* @package Services_Yahoo
* @author Martin Jansen <mj@php.net>
* @copyright 2005-2006 Martin Jansen
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @version CVS: $Id: Response.php,v 1.5 2006/10/04 16:16:53 mj Exp $
* @link http://pear.php.net/package/Services_Yahoo
* Services_Yahoo Search Response class
* This class provides methods for accessing the response of a search
* @package Services_Yahoo
* @author Martin Jansen <mj@php.net>
* @copyright 2005-2006 Martin Jansen
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @version CVS: $Id: Response.php,v 1.5 2006/10/04 16:16:53 mj Exp $
private $isValidIterator = true;
private $iteratorCounter = 0;
private $results = array ();
* @param object HTTP_Request Instance of HTTP_Request that was used for the request
* @throws Services_Yahoo_Exception
$this->request = $request;
if ($this->isError () == true ) {
$exception->addErrors ($this->getMessages ());
* Get number of query matches in the database
* This method returns the overall number of matches in the
* @return integer Number of query matches
return (int) $this->returnAttribute ("totalResultsAvailable");
* Get the position of the first result in the overall search
* @return integer Position of the first result in the overall search
return (int) $this->returnAttribute ("firstResultPosition");
* Get number of query matches returned from the search
* This may be lower than the number of results requested if
* there were fewer total results available.
* @return integer Number of query matches returned
return (int) $this->returnAttribute ("totalResultsReturned");
* Get the URL of a webpage containing a map graphic with all returned results plotted on it
* This URL is not part of all search responses, but it is used
* often enough to be part of the general response class.
if (isset ($this->result['ResultSetMapUrl'])) {
return $this->result['ResultSetMapUrl'];
* Determine if there are more matches than the ones that have been returned
* This method may be used as the criteria for displaying
* "Next" links or similar.
* @return boolean True if more results are available, false otherwise.
return ($this->lastResult < $this->getTotal());
* Get the HTTP_Request instance that was used for the query
* Access to the HTTP_Request instance is useful for introspecting
* into the request details. (E.g. for getting the HTTP response
* @return object HTTP_Request Instance of HTTP_Request
// {{{ Iterator implementation
return (array) $this->result['Result'][$this->iteratorCounter];
$this->iteratorCounter++;
if (!isset ($this->result['Result'][$this->iteratorCounter])) {
$this->isValidIterator = false;
return $this->iteratorCounter;
$this->iteratorCounter = 0;
return $this->isValidIterator;
* Parse result set from the response
* @throws Services_Yahoo_Exception
private function parseRequest ()
if ($tmp === false || !is_array($tmp) || !isset ($tmp['ResultSet'])) {
$this->result = $tmp['ResultSet'];
* Determine if an error was returned by the Yahoo API
* This method evaluates the HTTP response code. If it indicates
* an error, the method returns true.
* @return boolean True on error, otherwise false.
private function isError ()
return in_array($this->request->getResponseCode (), array (400 , 403 , 404 , 503 ));
* Get all error messages if the response contained an error
* Returns all errors in an numerically indexed array that were
private function getMessages ()
foreach ($this->result['Message'] as $message) {
$returnValue[] = $message;
* Attempts to get the value of a specific attribute of the top level tag
* @param string Name of the attribute
* @return mixed A string containing the attribute value if the
* attribute exists. NULL otherwise.
private function returnAttribute ($name)
if (isset ($this->result[$name])) {
return $this->result[$name];
Documentation generated on Fri, 20 Apr 2007 14:30:07 -0400 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.
|