1111 */
1212class API extends Request
1313{
14- /**
15- * Retrieves weather data by a weather station ID.
16- * See https://www.wunderground.com/wundermap/ for more information
17- *
18- * @param string $id
19- * @return array
20- * @throws \ErrorException
21- */
22- public function getByPWSId ($ id )
23- {
24- return $ this ->fetch (['query ' => 'pws: ' . $ id ])->getResponseArray ();
25- } // function
26-
27-
28- /**
29- * Retrieves weather data by a airport code.
30- *
31- * @param string $code
32- * @return array
33- * @throws \ErrorException
34- */
35- public function getByAirportCode ($ code )
36- {
37- return $ this ->fetch (['query ' => $ code ])->getResponseArray ();
38- } // function
39-
40-
41- /**
42- * Retrieves weather data by geo coordinates.
43- *
44- * @param float $lat
45- * @param float $lng
46- * @return array
47- * @throws \ErrorException
48- */
49- public function getByCoordinates ($ lat , $ lng )
50- {
51- return $ this ->fetch (['query ' => $ lat . ', ' . $ lng ])->getResponseArray ();
52- } // function
53-
54-
55- /**
56- * Retrieves weather data by a given country and city name.
57- *
58- * @param string $country
59- * @param string $city
60- * @return array
61- * @throws \ErrorException
62- */
63- public function getByLocation ($ country , $ city )
64- {
65- return $ this ->fetch (['query ' => $ country . '/ ' . $ city ])->getResponseArray ();
66- } // function
67-
68-
69- /**
70- * Retrieves weather data by a given country and city name.
71- *
72- * @param string|int $zipcode
73- * @return array
74- * @throws \ErrorException
75- */
76- public function getByUSZipcode ($ zipcode )
77- {
78- return $ this ->fetch (['query ' => $ zipcode ])->getResponseArray ();
79- } // function
80-
81-
82- /**
83- * Retrieves weather data by a given country and city name.
84- *
85- * @param string $state
86- * @param string $city
87- * @return array
88- * @throws \ErrorException
89- */
90- public function getByUSCity ($ state , $ city )
91- {
92- $ c = str_replace (' ' , '_ ' , $ city );
93- return $ this ->fetch (['query ' => $ state . '/ ' . $ c ])->getResponseArray ();
94- } // function
95-
96-
97- /**
98- * Retrieves hourly and daily weather forecast data by a given location (country+city, coordinates,
99- * zipcode, etc) for the next three days (daily records) or 36 hours (hourly records).
100- * Daily records will include today, hourly records will include the current hour.
101- *
102- * @param string $location any valid Country/City, Lat,Lon, Airport code, etc.
103- * @return array
104- * @throws \ErrorException
105- */
106- public function getForecast ($ location )
107- {
108- return $ this ->setFeatures (['forecast ' , 'hourly ' ])->setQuery ($ location )->fetch ()->getResponseArray ();
109- } // function
110-
111-
112- /**
113- * Retrieves hourly and daily weather forecast data by a given
114- * location (country+city, coordinates, zipcode, etc) for the next 10 days.
115- * Daily records will include today, hourly records will include the current hour.
116- *
117- * @param string $location Country/City, Lat,Lon, Airport code, etc.
118- * @return array
119- * @throws \ErrorException
120- */
121- public function getExtendedForecast ($ location )
122- {
123- return $ this ->setFeatures (['forecast10day ' , 'hourly10day ' ])->setQuery ($ location )->fetch ()->getResponseArray ();
124- } // function
125-
126-
127- /**
128- * Retrieves observed weather records and the daily summary for the specified date.
129- *
130- * @param string $date any valid {@link http://php.net/manual/en/datetime.formats.date.php Date Formats} format
131- * @param string $location Country/City, Lat,Lon, Airport code, etc.
132- * @return array
133- * @throws \ErrorException
134- */
135- public function getHistoric ($ date , $ location )
136- {
137- $ d = date ('Ymd ' , strtotime ($ date ));
138-
139- return $ this ->setFeature ("history_ $ d " )->setQuery ($ location )->fetch ()->getResponseArray ();
140- } // function
141-
142-
143- } // class
14+ /**
15+ * Retrieves weather data by a weather station ID.
16+ * See https://www.wunderground.com/wundermap/ for more information
17+ *
18+ * @param string $id
19+ * @return array
20+ * @throws \ErrorException
21+ */
22+ public function getByPWSId ($ id )
23+ {
24+ return $ this ->fetch (['query ' => 'pws: ' . $ id ])->getResponseArray ();
25+ }
26+
27+ /**
28+ * Retrieves weather data by a airport code.
29+ *
30+ * @param string $code
31+ * @return array
32+ * @throws \ErrorException
33+ */
34+ public function getByAirportCode ($ code )
35+ {
36+ return $ this ->fetch (['query ' => $ code ])->getResponseArray ();
37+ }
38+
39+ /**
40+ * Retrieves weather data by geo coordinates.
41+ *
42+ * @param float $lat
43+ * @param float $lng
44+ * @return array
45+ * @throws \ErrorException
46+ */
47+ public function getByCoordinates ($ lat , $ lng )
48+ {
49+ return $ this ->fetch (['query ' => $ lat . ', ' . $ lng ])->getResponseArray ();
50+ }
51+
52+ /**
53+ * Retrieves weather data by a given country and city name.
54+ *
55+ * @param string $country
56+ * @param string $city
57+ * @return array
58+ * @throws \ErrorException
59+ */
60+ public function getByLocation ($ country , $ city )
61+ {
62+ return $ this ->fetch (['query ' => $ country . '/ ' . $ city ])->getResponseArray ();
63+ }
64+
65+ /**
66+ * Retrieves weather data by a given country and city name.
67+ *
68+ * @param string|int $zipcode
69+ * @return array
70+ * @throws \ErrorException
71+ */
72+ public function getByUSZipcode ($ zipcode )
73+ {
74+ return $ this ->fetch (['query ' => $ zipcode ])->getResponseArray ();
75+ }
76+
77+ /**
78+ * Retrieves weather data by a given country and city name.
79+ *
80+ * @param string $state
81+ * @param string $city
82+ * @return array
83+ * @throws \ErrorException
84+ */
85+ public function getByUSCity ($ state , $ city )
86+ {
87+ $ c = str_replace (' ' , '_ ' , $ city );
88+
89+ return $ this ->fetch (['query ' => $ state . '/ ' . $ c ])->getResponseArray ();
90+ }
91+
92+ /**
93+ * Retrieves hourly and daily weather forecast data by a given location (country+city, coordinates,
94+ * zipcode, etc) for the next three days (daily records) or 36 hours (hourly records).
95+ * Daily records will include today, hourly records will include the current hour.
96+ *
97+ * @param string $location any valid Country/City, Lat,Lon, Airport code, etc.
98+ * @return array
99+ * @throws \ErrorException
100+ */
101+ public function getForecast ($ location )
102+ {
103+ return $ this ->setFeatures (['forecast ' , 'hourly ' ])->setQuery ($ location )->fetch ()->getResponseArray ();
104+ }
105+
106+ /**
107+ * Retrieves hourly and daily weather forecast data by a given
108+ * location (country+city, coordinates, zipcode, etc) for the next 10 days.
109+ * Daily records will include today, hourly records will include the current hour.
110+ *
111+ * @param string $location Country/City, Lat,Lon, Airport code, etc.
112+ * @return array
113+ * @throws \ErrorException
114+ */
115+ public function getExtendedForecast ($ location )
116+ {
117+ return $ this ->setFeatures (['forecast10day ' , 'hourly10day ' ])->setQuery ($ location )->fetch ()->getResponseArray ();
118+ }
119+
120+ /**
121+ * Retrieves observed weather records and the daily summary for the specified date.
122+ *
123+ * @param string $date any valid {@link http://php.net/manual/en/datetime.formats.date.php Date Formats} format
124+ * @param string $location Country/City, Lat,Lon, Airport code, etc.
125+ * @return array
126+ * @throws \ErrorException
127+ */
128+ public function getHistoric ($ date , $ location )
129+ {
130+ $ d = date ('Ymd ' , strtotime ($ date ));
131+
132+ return $ this ->setFeature ("history_ $ d " )->setQuery ($ location )->fetch ()->getResponseArray ();
133+ }
134+ }
0 commit comments