diff --git a/README.md b/README.md index a4a603a..a25f377 100644 --- a/README.md +++ b/README.md @@ -2,21 +2,24 @@ A PHP library for fetching data from the Australian Bureau of Meteorology API. -[![CircleCI](https://circleci.com/gh/previousnext/bom-weather.svg?style=svg)](https://circleci.com/gh/previousnext/bom-weather) - - ## Installation ``` composer require previousnext/bom-weather ``` +The library requires a PSR-18 HTTP client and PSR-17 HTTP factories. We recommend using [Guzzle](https://docs.guzzlephp.org/en/stable/). + ## Usage +```php + ### Forecasts ```php -$client = new BomClient(new Client(), new RequestFactory(), new NullLogger()); +$httpClient = new GuzzleHttp\Client(['base_uri' => 'http://www.bom.gov.au/']); +$requestFactory = new Http\Factory\Guzzle\RequestFactory(); +$client = new BomClient($httpClient, $requestFactory, new NullLogger()); $forecast = $client->getForecast('IDN10031'); $issueTime = $forecast->getIssueTime(); @@ -45,7 +48,9 @@ foreach ($locations as $location) { ### Observations ```php -$client = new BomClient(new Client(), new RequestFactory(), new NullLogger()); +$httpClient = new GuzzleHttp\Client(['base_uri' => 'http://www.bom.gov.au/']); +$requestFactory = new Http\Factory\Guzzle\RequestFactory(); +$client = new BomClient($httpClient, $requestFactory, new NullLogger()); $observationList = $client->getObservationList('IDN60901', '95757'); $refreshMessage = $observationList->getRefreshMessage(); @@ -78,13 +83,19 @@ $meanSeaLevel = $pressure->getMeanSeaLevel(); ## Developing -PHP CodeSniffer +**PHP CodeSniffer** ``` ./bin/phpcs ``` -PHPUnit +**PHPUnit** ``` ./bin/phpunit ``` + +**PHPStan** + +``` +./bin/phpstan +``` diff --git a/src/BomClient.php b/src/BomClient.php index a704b2a..2950847 100644 --- a/src/BomClient.php +++ b/src/BomClient.php @@ -51,7 +51,7 @@ public function __construct( */ public function getForecast(string $productId): ?Forecast { try { - $request = $this->requestFactory->createRequest('GET', "http://www.bom.gov.au/fwo/$productId.xml") + $request = $this->requestFactory->createRequest('GET', "fwo/$productId.xml") ->withHeader('Accept-Encoding', 'gzip'); $response = $this->httpClient->sendRequest($request); @@ -80,7 +80,7 @@ public function getForecast(string $productId): ?Forecast { */ public function getObservationList(string $productId, string $wmo): ?ObservationList { try { - $request = $this->requestFactory->createRequest('GET', "http://reg.bom.gov.au/fwo/$productId/$productId.$wmo.json") + $request = $this->requestFactory->createRequest('GET', "fwo/$productId/$productId.$wmo.json") ->withHeader('Accept-Encoding', 'gzip'); $response = $this->httpClient->sendRequest($request);