Skip to content

Commit 6b25d08

Browse files
committed
docs: expand README getting started guide
1 parent de117e0 commit 6b25d08

1 file changed

Lines changed: 82 additions & 5 deletions

File tree

README.md

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,95 @@
44
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
55
[![Tests](https://github.com/programmatordev/openweathermap-php-api/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/programmatordev/openweathermap-php-api/actions/workflows/ci.yml?query=branch%3Amain)
66

7-
OpenWeather PHP library built on
8-
[`programmatordev/php-api-sdk`](https://github.com/programmatordev/php-api-sdk).
7+
A fluent PHP client for OpenWeather APIs covering current and forecast weather,
8+
air pollution, geocoding, maps, stations, and One Call. Responses are mapped to
9+
typed entities that safely handle conditional, missing, and `null` data while
10+
keeping common requests concise.
911

10-
The library is currently under development and the public API is not ready for
11-
use yet.
12+
The library is built on
13+
[`programmatordev/php-api-sdk`](https://github.com/programmatordev/php-api-sdk)
14+
and supports client-wide and request-local configuration.
1215

1316
## Requirements
1417

15-
- PHP 8.1 or higher.
18+
- PHP 8.1 or higher
19+
- An OpenWeather API key
20+
21+
## Installation
22+
23+
Install the library with Composer:
24+
25+
```bash
26+
composer require programmatordev/openweathermap-php-api
27+
```
28+
29+
## Getting Started
30+
31+
Create the API client with an OpenWeather API key, then select a resource and
32+
endpoint:
33+
34+
```php
35+
use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;
36+
37+
$api = new OpenWeatherMap($_ENV['OPENWEATHERMAP_API_KEY']);
38+
39+
$current = $api->weather()->current(
40+
latitude: 38.7223,
41+
longitude: -9.1393,
42+
);
43+
44+
echo $current->temperature();
45+
echo $current->temperatureWithUnit();
46+
```
47+
48+
Response properties may be missing or explicitly `null`, so entity getters
49+
return nullable values where appropriate. Collection getters return empty
50+
arrays when the corresponding response collection is absent or `null`.
51+
52+
## Configuration
53+
54+
The client defaults to metric units and English. The equivalent explicit
55+
configuration is:
56+
57+
```php
58+
use ProgrammatorDev\OpenWeatherMap\Enum\Language;
59+
use ProgrammatorDev\OpenWeatherMap\Enum\Units;
60+
use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;
61+
62+
$api = new OpenWeatherMap(
63+
apiKey: $_ENV['OPENWEATHERMAP_API_KEY'],
64+
options: [
65+
'units' => Units::METRIC,
66+
'language' => Language::ENGLISH,
67+
],
68+
);
69+
```
70+
71+
Compatible resources can override those values for one fluent request chain.
72+
The original client configuration and other resource instances remain
73+
unchanged:
74+
75+
```php
76+
$current = $api
77+
->weather()
78+
->withUnits(Units::IMPERIAL)
79+
->withLanguage(Language::PORTUGUESE)
80+
->current(latitude: 38.7223, longitude: -9.1393);
81+
```
82+
83+
`withLanguage()` also accepts a non-empty language-code string, allowing new
84+
OpenWeather languages to be used without waiting for an enum update.
85+
86+
See OpenWeather's
87+
[units of measurement](https://openweathermap.org/api/current?collection=current_forecast#data) and
88+
[multilingual support](https://openweathermap.org/api/current?collection=current_forecast#multi)
89+
documentation for the currently supported values.
1690

1791
## Documentation
1892

93+
The detailed guides cover each API's endpoints, response entities, and usage
94+
examples:
95+
1996
- [One Call 4.0](docs/one-call.md)
2097
- [Air Pollution](docs/air-pollution.md)
2198
- [Weather](docs/weather.md)

0 commit comments

Comments
 (0)