1111 * @see http://www.OpenWeatherMap.org
1212 * @see http://www.OpenWeatherMap.org/about
1313 * @see http://www.OpenWeatherMap.org/copyright
14+ * @see http://openweathermap.org/appid
1415 */
1516
1617require_once ('Util.php ' );
1718
19+ /**
20+ * Main static class for the OpenWeatherMap-PHP-API.
21+ */
1822class OpenWeatherMap
1923{
24+ /**
25+ * @const $url The basic api url to fetch data from.
26+ */
2027 const url = "http://api.openweathermap.org/data/2.5/weather? " ;
2128
29+ /**
30+ * Directly returns the xml/json/html string returned by OpenWeatherMap.
31+ *
32+ * @param array|int|string $query The place to get weather information for. For possible values see below.
33+ * @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
34+ * @param string $lang The language to use for descriptions, default is 'en'. For possible values see below.
35+ * @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details.
36+ * @param string $mode The format of the data fetched. Possible values are 'json', 'html' and 'xml' (default).
37+ *
38+ * @return bool|string Returns false on failure and the fetched data in the format you specified on success.
39+ *
40+ * @warning If an error occured, OpenWeatherMap returns data in json format ALWAYS
41+ *
42+ * There are three ways to specify the place to get weather information for:
43+ * - Use the city name: $query must be a string containing the city name.
44+ * - Use the city id: $query must be an integer containing the city id.
45+ * - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values.
46+ *
47+ * Available languages are (as of 17. July 2013):
48+ * - English - en
49+ * - Russian - ru
50+ * - Italian - it
51+ * - Spanish - sp
52+ * - Ukrainian - ua
53+ * - German - de
54+ * - Portuguese - pt
55+ * - Romanian - ro
56+ * - Polish - pl
57+ * - Finnish - fi
58+ * - Dutch - nl
59+ * - French - fr
60+ * - Bulgarian - bg
61+ * - Swedish - se
62+ * - Chinese Traditional - zh_tw
63+ * - Chinese Simplified - zh_cn
64+ * - Turkish - tr
65+ */
2266 static public function getRawData ($ query , $ units = 'imperial ' , $ lang = 'en ' , $ appid = '' , $ mode = 'xml ' )
2367 {
2468 switch ($ query ) {
@@ -45,6 +89,43 @@ static public function getRawData($query, $units = 'imperial', $lang = 'en', $ap
4589 return file_get_contents ($ url );
4690 }
4791
92+ /**
93+ * Returns the current weather at the place you specified as an object.
94+ *
95+ * @param array|int|string $query The place to get weather information for. For possible values see below.
96+ * @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
97+ * @param string $lang The language to use for descriptions, default is 'en'. For possible values see below.
98+ * @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details.
99+ *
100+ * @throws Exception If $query has a wrong format. For valid formats see below.
101+ * @throws OpenWeatherMap_Exception If OpenWeatherMap returns an error.
102+ *
103+ * @return object Returns a new Weather object.
104+ *
105+ * There are three ways to specify the place to get weather information for:
106+ * - Use the city name: $query must be a string containing the city name.
107+ * - Use the city id: $query must be an integer containing the city id.
108+ * - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values.
109+ *
110+ * Available languages are (as of 17. July 2013):
111+ * - English - en
112+ * - Russian - ru
113+ * - Italian - it
114+ * - Spanish - sp
115+ * - Ukrainian - ua
116+ * - German - de
117+ * - Portuguese - pt
118+ * - Romanian - ro
119+ * - Polish - pl
120+ * - Finnish - fi
121+ * - Dutch - nl
122+ * - French - fr
123+ * - Bulgarian - bg
124+ * - Swedish - se
125+ * - Chinese Traditional - zh_tw
126+ * - Chinese Simplified - zh_cn
127+ * - Turkish - tr
128+ */
48129 static public function getWeather ($ query , $ units = 'imperial ' , $ lang = 'en ' , $ appid = '' )
49130 {
50131 return new Weather ($ query , $ units , $ lang , $ appid );
0 commit comments