1 | <?php |
||
2 | namespace Ballen\Metar\Helpers; |
||
3 | |||
4 | use GuzzleHttp\Client as HttpClient; |
||
5 | use \Exception; |
||
6 | |||
7 | /** |
||
8 | * Metar |
||
9 | * |
||
10 | * Metar is a PHP library for retrieveing weather reports (METAR infomation), |
||
11 | * the library supports multiple 'METAR prodivers' including NOAA, VATSIM and IVAO. |
||
12 | * |
||
13 | * @author Bobby Allen <[email protected]> |
||
14 | * @license http://www.gnu.org/licenses/gpl-3.0.html |
||
15 | * @link https://github.com/allebb/metar |
||
16 | * @link http://www.bobbyallen.me |
||
17 | * |
||
18 | */ |
||
19 | class MetarHTTPClient |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * Optional Guzzle Client configuration. |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $guzzleConf = []; |
||
27 | |||
28 | /** |
||
29 | * HTTP Client |
||
30 | * @param array $config Optional Guzzle configuration. |
||
31 | */ |
||
32 | 6 | public function __construct($config = []) |
|
33 | { |
||
34 | 6 | $this->guzzleConf = $config; |
|
35 | 6 | } |
|
36 | |||
37 | /** |
||
38 | * Make a HTTP request and retrieve the body. |
||
39 | * @param string $url The URL to request |
||
40 | * @return \Psr\Http\Message\StreamInterface |
||
41 | */ |
||
42 | 12 | public function getMetarAPIResponse($url) |
|
43 | { |
||
44 | 12 | $client = new HttpClient($this->guzzleConf); |
|
45 | 12 | $response = $client->get($url); |
|
46 | 8 | return $response->getBody() |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
47 | 8 | ->getContents(); |
|
48 | } |
||
49 | } |
||
50 |