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

Source for file weather.com-basic.php

Documentation is available at weather.com-basic.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
  3.  
  4. /**
  5.  * Basic example for the Weather.com-service
  6.  *
  7.  * PHP versions 4 and 5
  8.  *
  9.  * <LICENSE>
  10.  * Copyright (c) 2005-2011, Alexander Wirtz
  11.  * All rights reserved.
  12.  * 
  13.  * Redistribution and use in source and binary forms, with or without
  14.  * modification, are permitted provided that the following conditions
  15.  * are met:
  16.  * o Redistributions of source code must retain the above copyright notice,
  17.  *   this list of conditions and the following disclaimer.
  18.  * o Redistributions in binary form must reproduce the above copyright notice,
  19.  *   this list of conditions and the following disclaimer in the documentation
  20.  *   and/or other materials provided with the distribution.
  21.  * o Neither the name of the software nor the names of its contributors
  22.  *   may be used to endorse or promote products derived from this software
  23.  *   without specific prior written permission.
  24.  * 
  25.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  29.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35.  * POSSIBILITY OF SUCH DAMAGE.
  36.  * </LICENSE>
  37.  * 
  38.  * @category    Web Services
  39.  * @package     Services_Weather
  40.  * @author      Alexander Wirtz <eru@php.net>
  41.  * @copyright   2005-2011 Alexander Wirtz
  42.  * @license     http://www.opensource.org/licenses/bsd-license.php  BSD License
  43.  * @version     SVN: $Id$
  44.  * @link        http://pear.php.net/package/Services_Weather
  45.  * @filesource
  46.  */
  47.  
  48. require_once "Services/Weather.php";
  49.  
  50. // Object initialization - error checking is important, because of
  51. // handling exceptions such as missing PEAR modules
  52. $weatherDotCom &Services_Weather::service("WeatherDotCom"array("debug" => 2"httpTimeout" => 30));
  53. if (Services_Weather::isError($weatherDotCom)) {
  54.     die("Error: ".$weatherDotCom->getMessage()."\n");
  55. }
  56.  
  57. // Set weather.com partner data
  58. $weatherDotCom->setAccountData("<PartnerID>""<LicenseKey>");
  59.  
  60. /* Erase comments to enable caching
  61. $status = $weatherDotCom->setCache("file", array("cache_dir" => "/tmp/cache/"));
  62. if (Services_Weather::isError($status)) {
  63.     echo "Error: ".$status->getMessage()."\n";
  64. }
  65. */
  66.  
  67. $weatherDotCom->setUnitsFormat("metric");
  68. $weatherDotCom->setDateTimeFormat("d.m.Y""H:i");
  69.  
  70. // First get code for location
  71. $search $weatherDotCom->searchLocation("Bonn, Germany");
  72. if (Services_Weather::isError($search)) {
  73.     die("Error: ".$search->getMessage()."\n");
  74. }
  75.  
  76. // Now iterate through available functions for retrieving data
  77. foreach (array("getLocation""getWeather""getForecast"as $function{
  78.     $data $weatherDotCom->$function($search);
  79.     if (Services_Weather::isError($data)) {
  80.         echo "Error: ".$data->getMessage()."\n";
  81.         continue;
  82.     }
  83.  
  84.     var_dump($data);
  85. }
  86. ?>

Documentation generated on Mon, 11 Mar 2019 15:50:59 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.