Services_Yahoo_JP
[ class tree: Services_Yahoo_JP ] [ index: Services_Yahoo_JP ] [ all elements ]

Source for file AbstractNews.php

Documentation is available at AbstractNews.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3.  
  4. /**
  5.  * Abstract News class
  6.  *
  7.  * PHP version 5
  8.  *
  9.  * LICENSE: This source file is subject to the New BSD license that is
  10.  * available through the world-wide-web at the following URI:
  11.  * http://www.opensource.org/licenses/bsd-license.php. If you did not receive
  12.  * a copy of the New BSD License and are unable to obtain it through the web,
  13.  * please send a note to license@php.net so we can mail you a copy immediately.
  14.  *
  15.  * @category  Services
  16.  * @package   Services_Yahoo_JP
  17.  * @author    Tetsuya Nakase <phpizer@gmail.com>
  18.  * @copyright 2008 Tetsuya Nakase
  19.  * @license   http://www.opensource.org/licenses/bsd-license.php BSD
  20.  * @version   CVS: $Id: AbstractNews.php,v 1.1 2008/04/28 15:59:30 tetsuya Exp $
  21.  * @link      http://phpize.net
  22.  */
  23.  
  24. require_once 'Services/Yahoo/JP/News/Response.php';
  25. require_once 'HTTP/Request.php';
  26.  
  27. /**
  28.  * Abstract News class
  29.  *
  30.  * This abstract class serves as the base class for all different
  31.  * types of news that available through Services_Yahoo.
  32.  *
  33.  * @category  Services
  34.  * @package   Services_Yahoo_JP
  35.  * @author    Tetsuya Nakase <phpizer@gmail.com>
  36.  * @copyright 2008 Tetsuya Nakase
  37.  * @license   http://www.opensource.org/licenses/bsd-license.php BSD
  38.  * @version   Release: 0.0.1
  39.  * @link      http://phpize.net
  40.  */
  41. {
  42.     /**
  43.      * parameter
  44.      *
  45.      * @access protected
  46.      * @var    array 
  47.      */
  48.     protected $parameters = array('appid' => 'PEAR_Services_Y_JP');
  49.  
  50.     /**
  51.      * Submits the News
  52.      *
  53.      * This method submits the News and handles the response.  It
  54.      * returns an instance of Services_Yahoo_Result which may be used
  55.      * to further make use of the result.
  56.      *
  57.      * @return object Services_Yahoo_Response News result
  58.      * @throws Services_Yahoo_Exception
  59.      */
  60.     public function submit()
  61.     {
  62.         $url $this->requestURL '?';
  63.  
  64.         foreach ($this->parameters as $key => $value{
  65.             if (is_array($value)) {
  66.                 foreach ($value as $value2{
  67.                     $url .= $key '=' urlencode($value2'&';
  68.                 }
  69.                 continue;
  70.             }
  71.  
  72.             $url .= $key '=' urlencode($value'&';
  73.         }
  74.  
  75.         $request = new HTTP_Request($url);
  76.  
  77.         $result $request->sendRequest();
  78.         if (PEAR::isError($result)) {
  79.             throw new Services_Yahoo_Exception($result->getMessage());
  80.         }
  81.  
  82.         return new Services_Yahoo_JP_News_Response($request);
  83.     }
  84.  
  85.     /**
  86.      * Set Application ID
  87.      *
  88.      * An Application ID is a string that uniquely identifies your
  89.      * application. Think of it as like a User-Agent string. If you
  90.      * have multiple applications, you should use a different ID for
  91.      * each one. You can register your ID and make sure nobody is
  92.      * already using your ID on Yahoo's Application ID registration
  93.      * page.
  94.      *
  95.      * The ID defaults to "PEAR_Services_Y_JP", but you are free to
  96.      * change it to whatever you want.  Please note that the access
  97.      * to the Yahoo API is not limited via the Application ID but via
  98.      * the IP address of the host where the package is used.
  99.      *
  100.      * @param string $id Application ID
  101.      *
  102.      * @return void 
  103.      */
  104.     public function withAppID($id)
  105.     {
  106.         $this->parameters['appid'$id;
  107.     }
  108.  
  109.     /**
  110.      * Returns an element from the parameters
  111.      *
  112.      * @param string $name Name of the element
  113.      *
  114.      * @return string Value of the parameter idenfied by $name
  115.      */
  116.     protected function getParameter($name)
  117.     {
  118.         if (isset($this->parameters[$name])) {
  119.             return $this->parameters[$name];
  120.         }
  121.  
  122.         return '';
  123.     }
  124.  
  125.     /**
  126.      * Set the word
  127.      *
  128.      * @param string $word Search word in Topics
  129.      *
  130.      * @return void 
  131.      */
  132.     public function setWord($word)
  133.     {
  134.         $this->parameters['word'$word;
  135.     }
  136.  
  137.     /**
  138.      * Set the topicname
  139.      *
  140.      * @param string $topicname Search topics name
  141.      *
  142.      * @return void 
  143.      */
  144.     public function setTopicname($topicname)
  145.     {
  146.         $this->parameters['topicname'$topicname;
  147.     }
  148.  
  149.     /**
  150.      * Set the category
  151.      *
  152.      * @param string $category Search category
  153.      *
  154.      * @return void 
  155.      */
  156.     public function setCategory($category)
  157.     {
  158.         $this->parameters['category'$category;
  159.     }
  160.  
  161.     /**
  162.      * Set the topflg. It's only on the Yahoo!JAPAN's Top Page
  163.      *
  164.      * @return void 
  165.      */
  166.     public function setTopflg()
  167.     {
  168.         $this->parameters['topflg'= 1;
  169.     }
  170.  
  171.     /**
  172.      * Set the midashiflg. It has a midashi.
  173.      *
  174.      * @return void 
  175.      */
  176.     public function setMidashiflg()
  177.     {
  178.         $this->parameters['midashiflg'= 1;
  179.     }
  180.  
  181.     /**
  182.      * Set the relatedsite
  183.      *
  184.      * @param int $relatedsite It's a flag for showing related site
  185.      *
  186.      * @return void 
  187.      */
  188.     public function setRelatedsite($relatedsite = 1)
  189.     {
  190.         $this->parameters['relatedsite'$relatedsite;
  191.     }
  192.  
  193.     /**
  194.      * Set the sorder
  195.      *
  196.      * @param string $order An order to sort.
  197.      *
  198.      * @return void 
  199.      */
  200.     public function setOrder($order)
  201.     {
  202.         $this->parameters['order'$order;
  203.     }
  204.  
  205.     /**
  206.      * Set the sort
  207.      *
  208.      * @param string $sort An item to sort.
  209.      *
  210.      * @return void 
  211.      */
  212.     public function setSort($sort)
  213.     {
  214.         $this->parameters['sort'$sort;
  215.     }
  216.  
  217.     /**
  218.      * Set the num
  219.      *
  220.      * @param int $num Appoint the indication number.
  221.      *
  222.      * @return void 
  223.      */
  224.     public function setNum($num)
  225.     {
  226.         $this->parameters['num'$num;
  227.     }
  228. }
  229. ?>

Documentation generated on Fri, 19 Sep 2008 21:30:05 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.