Skip to content

Commit

Permalink
Use relative URLs. Update docs (#9)
Browse files Browse the repository at this point in the history
* Use relative URLs. Update docs
  • Loading branch information
kimpepper authored Jan 13, 2024
1 parent f54c3fa commit 935bb57
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -78,13 +83,19 @@ $meanSeaLevel = $pressure->getMeanSeaLevel();

## Developing

PHP CodeSniffer
**PHP CodeSniffer**
```
./bin/phpcs
```

PHPUnit
**PHPUnit**

```
./bin/phpunit
```

**PHPStan**

```
./bin/phpstan
```
4 changes: 2 additions & 2 deletions src/BomClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 935bb57

Please sign in to comment.