|
4 | 4 | */ |
5 | 5 | declare(strict_types = 1); |
6 | 6 |
|
| 7 | +use \Attogram\Weatherbit\Weatherbit; |
| 8 | + |
7 | 9 | ini_set('display_errors', '1'); |
8 | 10 | ini_set('display_startup_errors', '1'); |
9 | 11 | error_reporting(E_ALL); |
|
15 | 17 | $city = isset($_GET['city']) ? $_GET['city'] : ''; |
16 | 18 | $country = isset($_GET['country']) ? $_GET['country'] : ''; |
17 | 19 | $days = isset($_GET['days']) ? intval($_GET['days']) : 1; |
| 20 | +$ip = isset($_GET['ip']) ? $_GET['ip'] : $_SERVER['REMOTE_ADDR']; |
| 21 | + |
| 22 | +$pageTitle= 'Weatherbit v' . Weatherbit::VERSION . ' web test'; |
18 | 23 |
|
19 | 24 | ?> |
20 | 25 | <html> |
21 | 26 | <head> |
22 | | - <title>Weatherbit API Test</title> |
| 27 | + <title><?= $pageTitle ?></title> |
23 | 28 | </head> |
24 | 29 | <body> |
25 | | - <h1>Weatherbit API Test</h1> |
| 30 | + <h1><?= $pageTitle ?></h1> |
26 | 31 | <form> |
27 | 32 | Call: <select name="call"> |
28 | 33 | <option value="forecast"<?= $call == 'forecast' ? ' selected="selected"' : '' ?>>Daily Weather Forecast</option> |
29 | 34 | <option value="current"<?= $call == 'current' ? ' selected="selected"' : '' ?>>Current Weather</option> |
| 35 | + <option value="usage"<?= $call == 'usage' ? ' selected="selected"' : '' ?>>API Usage</option> |
30 | 36 | </select><br /><br /> |
31 | | - API Key: <input name="key" type="text" value="<?= htmlentities($key) ?>" size="32" /><br /><br /> |
| 37 | + API Key: <input name="key" type="text" value="<?= htmlentities($key) ?>" size="35" /><br /><br /> |
32 | 38 | City: <input name="city" type="text" value="<?= htmlentities($city) ?>" size="20" /><br /><br /> |
33 | | - Country: <?= countryPulldown($country) ?><br /><br /> |
34 | | - Forecast Days (1-16): <input name="days" type="text" value="<?= $days ?>" size="2" maxlength="2"/> |
| 39 | + Country: <input name="country" type="text" value="<?= htmlentities($country) ?>" size="20" /> (2 Letter Country Code)<br /><br /> |
| 40 | + Forecast Days (1-16): <input name="days" type="text" value="<?= $days ?>" size="2" maxlength="2" /><br /><br /> |
| 41 | + IP: <input name="ip" type="text" value="<?= $ip ?>" size="20" /> |
35 | 42 | <br /><br /> |
36 | 43 | <input type="hidden" name="run" value="test" /> |
37 | 44 | <input type="submit" value=" Get Weatherbit API Response " /> |
|
48 | 55 | $error = ''; |
49 | 56 |
|
50 | 57 | try { |
51 | | - $weatherbit = new \Attogram\Weatherbit\Weatherbit(); |
| 58 | + $weatherbit = new Weatherbit(); |
52 | 59 | $weatherbit->setKey($key); |
53 | | - $weatherbit->setCity($city); |
54 | | - $weatherbit->setCountry($country); |
55 | 60 | switch($call) { |
56 | 61 | case 'forecast': |
| 62 | + $weatherbit->setCity($city); |
| 63 | + $weatherbit->setCountry($country); |
57 | 64 | $data = $weatherbit->getDailyForecast($days); |
58 | 65 | break; |
59 | 66 | case 'current': |
| 67 | + $weatherbit->setCity($city); |
| 68 | + $weatherbit->setCountry($country); |
60 | 69 | $data = $weatherbit->getCurrent(); |
61 | 70 | break; |
| 71 | + case 'usage': |
| 72 | + $data = $weatherbit->getUsage(); |
| 73 | + break; |
62 | 74 | default: |
63 | 75 | throw new Exception('Invalid Call type'); |
64 | 76 | break; |
|
77 | 89 |
|
78 | 90 | testFooter(); |
79 | 91 |
|
80 | | - |
81 | | -/** |
82 | | - * @param string $selectedCountryCode - (optional, default '') 2 letter country code of selected country |
83 | | - * @return string - html select pulldown |
84 | | - */ |
85 | | -function countryPulldown($selectedCountryCode = '') |
86 | | -{ |
87 | | - $countries = [ |
88 | | - '' => '', |
89 | | - 'US' => 'United States', |
90 | | - 'NL' => 'Netherlands', |
91 | | - 'DE' => 'Germany', |
92 | | - 'AF' => 'Afghanistan', |
93 | | - 'AX' => 'Åland Islands', |
94 | | - 'AL' => 'Albania', |
95 | | - 'DZ' => 'Algeria', |
96 | | - 'AS' => 'American Samoa', |
97 | | - 'AD' => 'Andorra', |
98 | | - 'AO' => 'Angola', |
99 | | - 'AI' => 'Anguilla', |
100 | | - 'AQ' => 'Antarctica', |
101 | | - 'AG' => 'Antigua and Barbuda', |
102 | | - 'AR' => 'Argentina', |
103 | | - 'AM' => 'Armenia', |
104 | | - 'AW' => 'Aruba', |
105 | | - 'AU' => 'Australia', |
106 | | - 'AT' => 'Austria', |
107 | | - 'AZ' => 'Azerbaijan', |
108 | | - 'BS' => 'Bahamas', |
109 | | - 'BH' => 'Bahrain', |
110 | | - 'BD' => 'Bangladesh', |
111 | | - 'BB' => 'Barbados', |
112 | | - 'BY' => 'Belarus', |
113 | | - 'BE' => 'Belgium', |
114 | | - 'BZ' => 'Belize', |
115 | | - 'BJ' => 'Benin', |
116 | | - 'BM' => 'Bermuda', |
117 | | - 'BT' => 'Bhutan', |
118 | | - 'BO' => 'Bolivia', |
119 | | - 'BQ' => 'Bonaire, Sint Eustatius and Saba', |
120 | | - 'BA' => 'Bosnia and Herzegovina', |
121 | | - 'BW' => 'Botswana', |
122 | | - 'BV' => 'Bouvet Island', |
123 | | - 'BR' => 'Brazil', |
124 | | - 'IO' => 'British Indian Ocean Territory', |
125 | | - 'BN' => 'Brunei Darussalam', |
126 | | - 'BG' => 'Bulgaria', |
127 | | - 'BF' => 'Burkina Faso', |
128 | | - 'BI' => 'Burundi', |
129 | | - 'KH' => 'Cambodia', |
130 | | - 'CM' => 'Cameroon', |
131 | | - 'CA' => 'Canada', |
132 | | - 'CV' => 'Cape Verde', |
133 | | - 'KY' => 'Cayman Islands', |
134 | | - 'CF' => 'Central African Republic', |
135 | | - 'TD' => 'Chad', |
136 | | - 'CL' => 'Chile', |
137 | | - 'CN' => 'China', |
138 | | - 'CX' => 'Christmas Island', |
139 | | - 'CC' => 'Cocos (Keeling) Islands', |
140 | | - 'CO' => 'Colombia', |
141 | | - 'KM' => 'Comoros', |
142 | | - 'CG' => 'Congo', |
143 | | - 'CD' => 'Congo, the Democratic Republic of', |
144 | | - 'CK' => 'Cook Islands', |
145 | | - 'CR' => 'Costa Rica', |
146 | | - 'CI' => "Côte d'Ivoire", |
147 | | - 'HR' => 'Croatia', |
148 | | - 'CU' => 'Cuba', |
149 | | - 'CW' => 'Curaçao', |
150 | | - 'CY' => 'Cyprus', |
151 | | - 'CZ' => 'Czech Republic', |
152 | | - 'DK' => 'Denmark', |
153 | | - 'DJ' => 'Djibouti', |
154 | | - 'DM' => 'Dominica', |
155 | | - 'DO' => 'Dominican Republic', |
156 | | - 'EC' => 'Ecuador', |
157 | | - 'EG' => 'Egypt', |
158 | | - 'SV' => 'El Salvador', |
159 | | - 'GQ' => 'Equatorial Guinea', |
160 | | - 'ER' => 'Eritrea', |
161 | | - 'EE' => 'Estonia', |
162 | | - 'ET' => 'Ethiopia', |
163 | | - 'FK' => 'Falkland Islands (Malvinas)', |
164 | | - 'FO' => 'Faroe Islands', |
165 | | - 'FJ' => 'Fiji', |
166 | | - 'FI' => 'Finland', |
167 | | - 'FR' => 'France', |
168 | | - 'GF' => 'French Guiana', |
169 | | - 'PF' => 'French Polynesia', |
170 | | - 'TF' => 'French Southern Territories', |
171 | | - 'GA' => 'Gabon', |
172 | | - 'GM' => 'Gambia', |
173 | | - 'GE' => 'Georgia', |
174 | | - 'DE' => 'Germany', |
175 | | - 'GH' => 'Ghana', |
176 | | - 'GI' => 'Gibraltar', |
177 | | - 'GR' => 'Greece', |
178 | | - 'GL' => 'Greenland', |
179 | | - 'GD' => 'Grenada', |
180 | | - 'GP' => 'Guadeloupe', |
181 | | - 'GU' => 'Guam', |
182 | | - 'GT' => 'Guatemala', |
183 | | - 'GG' => 'Guernsey', |
184 | | - 'GN' => 'Guinea', |
185 | | - 'GW' => 'Guinea-Bissau', |
186 | | - 'GY' => 'Guyana', |
187 | | - 'HT' => 'Haiti', |
188 | | - 'HM' => 'Heard Island and McDonald Islands', |
189 | | - 'VA' => 'Holy See (Vatican City State)', |
190 | | - 'HN' => 'Honduras', |
191 | | - 'HK' => 'Hong Kong', |
192 | | - 'HU' => 'Hungary', |
193 | | - 'IS' => 'Iceland', |
194 | | - 'IN' => 'India', |
195 | | - 'ID' => 'Indonesia', |
196 | | - 'IR' => 'Iran, Islamic Republic of', |
197 | | - 'IQ' => 'Iraq', |
198 | | - 'IE' => 'Ireland', |
199 | | - 'IM' => 'Isle of Man', |
200 | | - 'IL' => 'Israel', |
201 | | - 'IT' => 'Italy', |
202 | | - 'JM' => 'Jamaica', |
203 | | - 'JP' => 'Japan', |
204 | | - 'JE' => 'Jersey', |
205 | | - 'JO' => 'Jordan', |
206 | | - 'KZ' => 'Kazakhstan', |
207 | | - 'KE' => 'Kenya', |
208 | | - 'KI' => 'Kiribati', |
209 | | - 'KP' => "Korea, Democratic People's Republic of", |
210 | | - 'KR' => 'Korea, Republic of', |
211 | | - 'KW' => 'Kuwait', |
212 | | - 'KG' => 'Kyrgyzstan', |
213 | | - 'LA' => "Lao People's Democratic Republic", |
214 | | - 'LV' => 'Latvia', |
215 | | - 'LB' => 'Lebanon', |
216 | | - 'LS' => 'Lesotho', |
217 | | - 'LR' => 'Liberia', |
218 | | - 'LY' => 'Libya', |
219 | | - 'LI' => 'Liechtenstein', |
220 | | - 'LT' => 'Lithuania', |
221 | | - 'LU' => 'Luxembourg', |
222 | | - 'MO' => 'Macao', |
223 | | - 'MK' => 'Macedonia, the former Yugoslav Republic of', |
224 | | - 'MG' => 'Madagascar', |
225 | | - 'MW' => 'Malawi', |
226 | | - 'MY' => 'Malaysia', |
227 | | - 'MV' => 'Maldives', |
228 | | - 'ML' => 'Mali', |
229 | | - 'MT' => 'Malta', |
230 | | - 'MH' => 'Marshall Islands', |
231 | | - 'MQ' => 'Martinique', |
232 | | - 'MR' => 'Mauritania', |
233 | | - 'MU' => 'Mauritius', |
234 | | - 'YT' => 'Mayotte', |
235 | | - 'MX' => 'Mexico', |
236 | | - 'FM' => 'Micronesia, Federated States of', |
237 | | - 'MD' => 'Moldova, Republic of', |
238 | | - 'MC' => 'Monaco', |
239 | | - 'MN' => 'Mongolia', |
240 | | - 'ME' => 'Montenegro', |
241 | | - 'MS' => 'Montserrat', |
242 | | - 'MA' => 'Morocco', |
243 | | - 'MZ' => 'Mozambique', |
244 | | - 'MM' => 'Myanmar', |
245 | | - 'NA' => 'Namibia', |
246 | | - 'NR' => 'Nauru', |
247 | | - 'NP' => 'Nepal', |
248 | | - 'NL' => 'Netherlands', |
249 | | - 'NC' => 'New Caledonia', |
250 | | - 'NZ' => 'New Zealand', |
251 | | - 'NI' => 'Nicaragua', |
252 | | - 'NE' => 'Niger', |
253 | | - 'NG' => 'Nigeria', |
254 | | - 'NU' => 'Niue', |
255 | | - 'NF' => 'Norfolk Island', |
256 | | - 'MP' => 'Northern Mariana Islands', |
257 | | - 'NO' => 'Norway', |
258 | | - 'OM' => 'Oman', |
259 | | - 'PK' => 'Pakistan', |
260 | | - 'PW' => 'Palau', |
261 | | - 'PS' => 'Palestinian Territory, Occupied', |
262 | | - 'PA' => 'Panama', |
263 | | - 'PG' => 'Papua New Guinea', |
264 | | - 'PY' => 'Paraguay', |
265 | | - 'PE' => 'Peru', |
266 | | - 'PH' => 'Philippines', |
267 | | - 'PN' => 'Pitcairn', |
268 | | - 'PL' => 'Poland', |
269 | | - 'PT' => 'Portugal', |
270 | | - 'PR' => 'Puerto Rico', |
271 | | - 'QA' => 'Qatar', |
272 | | - 'RE' => 'Réunion', |
273 | | - 'RO' => 'Romania', |
274 | | - 'RU' => 'Russian Federation', |
275 | | - 'RW' => 'Rwanda', |
276 | | - 'BL' => 'Saint Barthélemy', |
277 | | - 'SH' => 'Saint Helena, Ascension and Tristan da Cunha', |
278 | | - 'KN' => 'Saint Kitts and Nevis', |
279 | | - 'LC' => 'Saint Lucia', |
280 | | - 'MF' => 'Saint Martin (French part)', |
281 | | - 'PM' => 'Saint Pierre and Miquelon', |
282 | | - 'VC' => 'Saint Vincent and the Grenadines', |
283 | | - 'WS' => 'Samoa', |
284 | | - 'SM' => 'San Marino', |
285 | | - 'ST' => 'Sao Tome and Principe', |
286 | | - 'SA' => 'Saudi Arabia', |
287 | | - 'SN' => 'Senegal', |
288 | | - 'RS' => 'Serbia', |
289 | | - 'SC' => 'Seychelles', |
290 | | - 'SL' => 'Sierra Leone', |
291 | | - 'SG' => 'Singapore', |
292 | | - 'SX' => 'Sint Maarten (Dutch part)', |
293 | | - 'SK' => 'Slovakia', |
294 | | - 'SI' => 'Slovenia', |
295 | | - 'SB' => 'Solomon Islands', |
296 | | - 'SO' => 'Somalia', |
297 | | - 'ZA' => 'South Africa', |
298 | | - 'GS' => 'South Georgia and the South Sandwich Islands', |
299 | | - 'SS' => 'South Sudan', |
300 | | - 'ES' => 'Spain', |
301 | | - 'LK' => 'Sri Lanka', |
302 | | - 'SD' => 'Sudan', |
303 | | - 'SR' => 'Suriname', |
304 | | - 'SJ' => 'Svalbard and Jan Mayen', |
305 | | - 'SZ' => 'Swaziland', |
306 | | - 'SE' => 'Sweden', |
307 | | - 'CH' => 'Switzerland', |
308 | | - 'SY' => 'Syrian Arab Republic', |
309 | | - 'TW' => 'Taiwan, Province of China', |
310 | | - 'TJ' => 'Tajikistan', |
311 | | - 'TZ' => 'Tanzania, United Republic of', |
312 | | - 'TH' => 'Thailand', |
313 | | - 'TL' => 'Timor-Leste', |
314 | | - 'TG' => 'Togo', |
315 | | - 'TK' => 'Tokelau', |
316 | | - 'TO' => 'Tonga', |
317 | | - 'TT' => 'Trinidad and Tobago', |
318 | | - 'TN' => 'Tunisia', |
319 | | - 'TR' => 'Turkey', |
320 | | - 'TM' => 'Turkmenistan', |
321 | | - 'TC' => 'Turks and Caicos Islands', |
322 | | - 'TV' => 'Tuvalu', |
323 | | - 'UG' => 'Uganda', |
324 | | - 'UA' => 'Ukraine', |
325 | | - 'AE' => 'United Arab Emirates', |
326 | | - 'GB' => 'United Kingdom', |
327 | | - 'US' => 'United States', |
328 | | - 'UM' => 'United States Minor Outlying Islands', |
329 | | - 'UY' => 'Uruguay', |
330 | | - 'UZ' => 'Uzbekistan', |
331 | | - 'VU' => 'Vanuatu', |
332 | | - 'VE' => 'Venezuela, Bolivarian Republic of', |
333 | | - 'VN' => 'Viet Nam', |
334 | | - 'VG' => 'Virgin Islands, British', |
335 | | - 'VI' => 'Virgin Islands, U.S.', |
336 | | - 'WF' => 'Wallis and Futuna', |
337 | | - 'EH' => 'Western Sahara', |
338 | | - 'YE' => 'Yemen', |
339 | | - 'ZM' => 'Zambia', |
340 | | - 'ZW' => 'Zimbabwe', |
341 | | - |
342 | | - ]; |
343 | | - |
344 | | - $pulldown = '<select name="country">'; |
345 | | - foreach ($countries as $code => $country) { |
346 | | - $selected = ''; |
347 | | - if ($code == strtoupper($selectedCountryCode)) { |
348 | | - $selected = ' selected="selected"'; |
349 | | - } |
350 | | - $pulldown .= '<option value="' . $code . '"' . $selected . '>' . $country . '</option>'; |
351 | | - } |
352 | | - |
353 | | - return $pulldown . '</select>'; |
354 | | -} |
355 | | - |
356 | 92 | function testFooter() |
357 | 93 | { |
358 | 94 | print '<br /><hr />' . gmdate('Y-m-d H:i:s') . ' UTC</body></html>'; |
|
0 commit comments