Skip to content

Commit 9e5db00

Browse files
committed
docs: simplify API usage guidance
1 parent 0bcdaec commit 9e5db00

11 files changed

Lines changed: 79 additions & 91 deletions

File tree

AGENTS.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ Composer with PSR-4 autoloading under the
1010
## Sources Of Truth
1111

1212
- Use the official OpenWeather documentation for endpoint paths, parameters,
13-
response fields, availability, and subscription constraints.
13+
response fields, and current access requirements.
1414
- Use the installed PHP API SDK documentation and source for its supported
1515
authoring patterns.
1616
- Read existing resources, entities, tests, and documentation before changing
1717
related behavior.
18-
- Do not infer API availability from OpenWeather documentation sidebars; verify
19-
it against the current official API catalog or pricing information.
18+
- Do not infer API access from documentation sidebars; verify it against the
19+
current official API documentation.
2020

2121
## Code Changes
2222

@@ -71,6 +71,7 @@ Composer with PSR-4 autoloading under the
7171
- Update public documentation alongside implemented API areas.
7272
- Keep method signatures, examples, supported endpoints, and response entities
7373
aligned with the implementation.
74-
- Clearly distinguish standard free-plan APIs from APIs requiring separate or
75-
paid subscriptions.
76-
- Document potentially billable or destructive behavior prominently.
74+
- Avoid hard-coded claims about plans, prices, quotas, or allowances. Link to
75+
the official OpenWeather documentation for current access requirements.
76+
- Document destructive behavior and actions that send additional requests
77+
prominently.

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
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

77
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.
8+
air pollution, geocoding, maps, stations, and One Call. Responses use typed
9+
entities that safely handle conditional, missing, and `null` data.
1110

1211
The library is built on
1312
[`programmatordev/php-api-sdk`](https://github.com/programmatordev/php-api-sdk)
@@ -45,9 +44,9 @@ echo $current->temperature();
4544
echo $current->temperatureWithUnit();
4645
```
4746

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`.
47+
Response properties may be missing or `null`, so getters return nullable values
48+
where appropriate. Collection getters return empty arrays when the response
49+
does not contain that collection.
5150

5251
## Configuration
5352

UPGRADE-4.0.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
# Upgrading To 4.0
22

3-
Version 4 is a complete rewrite of the library. Backward compatibility with
4-
earlier releases is intentionally not preserved, and existing integrations
5-
should treat this release as a new implementation even where the usage remains
6-
familiar.
3+
Version 4 is a complete rewrite. It is not backward compatible with earlier
4+
releases. Existing integrations should adopt it as a new implementation, even
5+
where the usage looks familiar.
76

87
## Upgrade Expectations
98

109
- Previous resources, entities, methods, namespaces, and configuration are not
1110
part of the current public contract.
12-
- Compatibility aliases, deprecated transitional APIs, and an old-to-new API
13-
mapping are not provided.
11+
- Compatibility aliases, transitional APIs, and an old-to-new API mapping are
12+
not provided.
1413
- Integrations should be rebuilt against the current [README](README.md) and
1514
[API guides](README.md#apis).
1615
- Application tests should be reviewed and updated before adopting the new
@@ -22,13 +21,11 @@ familiar.
2221
- The client is built on
2322
[`programmatordev/php-api-sdk` 3](https://github.com/programmatordev/php-api-sdk).
2423
- Current weather, forecasts, air pollution, geocoding, maps, stations, and One
25-
Call 4.0 are supported. Access depends on the OpenWeather products enabled for
26-
the API key.
27-
- Metric units and English are the defaults, with client-wide configuration and
28-
immutable request-local overrides where supported.
29-
- Response entities tolerate missing, explicitly `null`, conditional, and
30-
unknown fields. Known non-null fields with invalid types produce hydration
31-
errors.
24+
Call 4.0 are supported.
25+
- Metric units and English are the defaults. They can be configured for the
26+
client or changed for one request chain where supported.
27+
- Response entities accept missing, `null`, conditional, and unknown fields.
28+
Known non-null fields with invalid types produce hydration errors.
3229
- OpenWeather API failures use a documented exception hierarchy; transport,
3330
decoding, and hydration failures remain distinguishable. See
3431
[Error Handling](docs/errors.md).

docs/air-pollution.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Air Pollution
22

3-
Current, forecast, and historical air pollution are included in OpenWeather's
4-
standard free and paid subscriptions.
3+
This guide covers current, forecast, and historical air pollution.
54

65
## Current
76

@@ -103,7 +102,7 @@ Forecast periods use the same OpenWeather Air Quality Index and fixed
103102
The Historical Air Pollution API returns hourly observations for a coordinate
104103
and date range. See the
105104
[official Air Pollution API documentation](https://openweathermap.org/api/air-pollution)
106-
for availability and API details.
105+
for API details.
107106

108107
Use `history()` with a latitude, longitude, start date, and end date. The date
109108
arguments accept any `DateTimeInterface` implementation. The end must be after

docs/errors.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Error Handling
22

3-
The library distinguishes unsuccessful OpenWeather responses from local input,
4-
transport, decoding, and response-mapping failures.
3+
The library separates OpenWeather API errors from invalid input, HTTP client
4+
failures, decoding errors, and invalid response data.
55

66
## OpenWeather API Errors
77

@@ -54,7 +54,7 @@ try {
5454
} catch (TooManyRequestsException $exception) {
5555
// Defer or slow down further requests.
5656
} catch (UnauthorizedException $exception) {
57-
// Check the API key and its access to the requested product.
57+
// Check the API key and whether it can use this endpoint.
5858
} catch (ApiException $exception) {
5959
// Handle any other unsuccessful OpenWeather response.
6060
}
@@ -71,7 +71,7 @@ extend `ApiException`:
7171
| `Psr\Http\Client\ClientExceptionInterface` | The PSR-18 client could not complete the HTTP request. |
7272
| `JsonException` | A successful response expected to contain JSON could not be decoded. |
7373
| `HydrationException` | A known response property contains an invalid type or value. |
74-
| `UnexpectedValueException` | A non-JSON response, such as a map tile, has an unexpected payload or media type. |
74+
| `UnexpectedValueException` | A non-JSON response, such as a map tile, has unexpected content or a wrong content type. |
7575

7676
Missing, explicitly `null`, conditional, and unknown response properties are
7777
tolerated. `HydrationException` is reserved for known non-null properties whose

docs/geocoding.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Geocoding
22

3-
The Geocoding API is available on OpenWeather's standard free and paid
4-
subscriptions. See the
3+
See the
54
[official Geocoding API documentation](https://openweathermap.org/api/geocoding-api)
65
for API details.
76

docs/maps.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Maps
22

33
Weather Maps API 1.0 provides current cloud, precipitation, sea-level pressure,
4-
wind-speed, and temperature overlays. It is available on OpenWeather's standard
5-
free and paid subscriptions. See the
4+
wind-speed, and temperature overlays. See the
65
[official Weather Maps documentation](https://openweathermap.org/api/weathermaps)
76
for API details.
87

@@ -85,7 +84,7 @@ The returned format can be passed to
8584
[Leaflet](https://leafletjs.com/reference.html#tilelayer),
8685
[OpenLayers](https://openlayers.org/en/latest/apidoc/module-ol_source_XYZ-XYZ.html),
8786
or a [MapLibre raster source](https://maplibre.org/maplibre-style-spec/sources/).
88-
Like a concrete tile URL, the template contains the API key and does not make an
87+
Like a specific tile URL, the template contains the API key and does not make an
8988
HTTP request when generated.
9089

9190
## Tile Coordinates

docs/one-call.md

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# One Call 4.0
22

3-
One Call 4.0 requires a separate OpenWeather subscription and includes free
4-
daily API calls. Consult OpenWeather's official documentation for the current
5-
allowance, pricing, usage limits, and account configuration before using these
6-
endpoints in production.
3+
OpenWeather manages access and usage terms for One Call 4.0. Consult the
4+
[official One Call documentation](https://openweathermap.org/api/one-call-4)
5+
for current requirements before using these endpoints.
76

87
## Current
98

109
See OpenWeather's
1110
[official One Call API 4.0 documentation](https://openweathermap.org/api/one-call-4#current)
12-
for API details and current subscription terms.
11+
for API details.
1312

1413
Use `current()` with a latitude and longitude.
1514

@@ -24,9 +23,9 @@ $current = $api->oneCall()->current(
2423
);
2524
```
2625

27-
Every response property may be absent or explicitly `null`. Coordinates and
28-
timezone metadata describe the requested location, while `dateTime()` and the
29-
astronomical timestamps remain UTC values.
26+
Every response property may be absent or `null`. Coordinates and timezone
27+
details describe the requested location. `dateTime()`, sunrise, and sunset use
28+
UTC.
3029

3130
```php
3231
echo $current->coordinates()?->latitude();
@@ -53,7 +52,7 @@ $current = $api
5352
->current(38.7223, -9.1393);
5453
```
5554

56-
Measurement getters return nullable values. Companion methods provide the unit
55+
Measurement getters return nullable values. Related methods provide the unit
5756
and a formatted value. With the default metric configuration, for example:
5857

5958
```php
@@ -80,7 +79,7 @@ $timeline = $api->oneCall()->minuteTimeline(
8079
);
8180
```
8281

83-
The response exposes location metadata and forecast periods. Each period
82+
The response contains location details and forecast periods. Each period
8483
provides its UTC date and time, precipitation, and any referenced alert IDs.
8584

8685
```php
@@ -124,7 +123,7 @@ Use `startAt` to select a future starting point and `count` to limit the number
124123
of periods returned. Both are optional, and `count` must be positive when
125124
provided.
126125

127-
The response exposes location metadata, up to 50 periods, and pagination when
126+
The response contains location details, up to 50 periods, and pagination when
128127
OpenWeather provides it.
129128

130129
```php
@@ -138,8 +137,8 @@ foreach ($timeline->periods() as $period) {
138137
}
139138
```
140139

141-
The 15-minute, one-hour, and one-day timelines normalize OpenWeather's
142-
fractional precipitation probability to a percentage:
140+
Precipitation probability follows the same getter pattern as other
141+
measurements:
143142

144143
```php
145144
$period->precipitationProbability(); // 91.0
@@ -177,8 +176,8 @@ $timeline = $api->oneCall()->hourTimeline(
177176
);
178177
```
179178

180-
The response contains up to 20 periods. Historical and forecast periods expose
181-
their UTC date and time through `dateTime()`.
179+
The response contains up to 20 periods. `dateTime()` returns each period's UTC
180+
date and time.
182181

183182
```php
184183
foreach ($timeline->periods() as $period) {
@@ -220,9 +219,9 @@ $timeline = $api->oneCall()->dayTimeline(
220219
);
221220
```
222221

223-
The response contains up to 10 periods. Daily periods provide UTC dates,
224-
astronomy, daily temperatures, weather measurements, conditions, precipitation
225-
probability, rain, snow, and alert references.
222+
The response contains up to 10 periods. Daily periods provide UTC dates, sun
223+
and moon times, daily temperatures, weather measurements, conditions,
224+
precipitation probability, rain, snow, and alert references.
226225

227226
```php
228227
foreach ($timeline->periods() as $period) {
@@ -237,12 +236,12 @@ foreach ($timeline->periods() as $period) {
237236
}
238237
```
239238

240-
OpenWeather does not currently define units for the daily scalar rain and snow
241-
values, so these getters return raw nullable floats.
239+
OpenWeather does not define units for the daily `rain` and `snow` values, so
240+
these getters return nullable floats without conversion.
242241

243242
## Timeline Pagination
244243

245-
The 15-minute, one-hour, and one-day timelines provide explicit pagination.
244+
The 15-minute, one-hour, and one-day timelines support pagination.
246245

247246
```php
248247
$timeline = $api->oneCall()->hourTimeline(
@@ -266,11 +265,8 @@ echo $pagination->nextPageUrl();
266265

267266
The availability checks and URL getters do not make another API request.
268267
`previousPage()` and `nextPage()` request the corresponding page when its URL
269-
is available and otherwise return `null`. Pagination does not iterate
270-
automatically. Every pagination request counts as a separate One Call API call
271-
under your OpenWeather subscription; consult the
272-
[official documentation](https://openweathermap.org/api/one-call-4#pagination)
273-
for current usage and billing terms.
268+
is available and otherwise return `null`. The library does not fetch every page
269+
automatically. Each page navigation sends a separate API request.
274270

275271
## Alert
276272

@@ -308,7 +304,7 @@ foreach ($current->alertIds() as $id) {
308304
}
309305
```
310306

311-
Alerts provide sender and event information, validity dates, localized
307+
Alerts provide sender and event information, start and end times, localized
312308
descriptions, and tags.
313309

314310
`description()` returns the first exact language-code match or `null`.

docs/setup.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
`OpenWeatherMap` uses PHP API SDK's `setup()` method for client-wide HTTP
44
configuration. Most applications can rely on PHP-HTTP discovery and use the
5-
client without additional setup. Configure the following extension points when
6-
the application needs to provide its own infrastructure or request behavior.
5+
client without additional setup. Use the options below when the application
6+
needs its own HTTP services or request behavior.
77

88
```php
99
use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;
1010

1111
$api = new OpenWeatherMap($_ENV['OPENWEATHERMAP_API_KEY']);
1212
```
1313

14-
The examples below use infrastructure supplied by the application:
14+
The examples below use objects supplied by the application:
1515
`$httpClient` implements PSR-18, `$cachePool` implements PSR-6, and `$logger`
1616
implements PSR-3.
1717

@@ -31,7 +31,7 @@ Use `client()` to provide a specific PSR-18 client instead.
3131
$api->setup()->client($httpClient);
3232
```
3333

34-
The returned client builder can also receive custom request and stream
34+
`client()` returns a builder that can also receive custom request and stream
3535
factories.
3636

3737
See the official PHP API SDK
@@ -40,9 +40,9 @@ for all client and factory options.
4040

4141
## Cache
4242

43-
Use `cache()` with a PSR-6 cache pool to cache eligible HTTP responses. The
44-
fallback TTL is used when a response does not provide a supported cache
45-
directive. GET and HEAD requests are cacheable by default. Packagist lists
43+
Use `cache()` with a PSR-6 cache pool to cache supported HTTP responses. The
44+
default TTL sets the cache lifetime when a response does not provide one. GET
45+
and HEAD requests are cacheable by default. Packagist lists
4646
available [PSR-6 cache implementations](https://packagist.org/providers/psr/cache-implementation).
4747

4848
```php
@@ -53,7 +53,8 @@ $api
5353
```
5454

5555
Cache configuration is client-wide. After configuring a pool, `withCache()` can
56-
override cache behavior for one immutable request chain.
56+
change cache behavior for one request chain without changing the client-wide
57+
settings.
5758

5859
```php
5960
use ProgrammatorDev\Api\Builder\CacheBuilder;
@@ -99,7 +100,7 @@ $retryPlugin = new RetryPlugin([
99100
$api->setup()->plugins()->add($retryPlugin, priority: 25);
100101
```
101102

102-
Retries make additional OpenWeather requests and can affect quotas or billing.
103+
Retries may send additional OpenWeather requests.
103104
Plugin priority controls middleware order. Priority `25` places this retry
104105
plugin after authentication and before cache; consult the linked documentation
105106
when choosing priorities for other plugins.
@@ -128,9 +129,9 @@ $api->setup()->hooks()->beforeRequest(
128129
);
129130
```
130131

131-
Return a PSR-7 request to replace it for the remainder of the request pipeline,
132-
or return `null` when no replacement is required. Response hooks follow the
133-
same pattern with a PSR-7 response.
132+
Return a PSR-7 request to use it for the current request, or return `null` to
133+
keep the original request. Response hooks follow the same pattern with a PSR-7
134+
response.
134135

135136
See the official PHP API SDK
136137
[hook documentation](https://github.com/programmatordev/php-api-sdk/blob/main/docs/13-hooks.md)

0 commit comments

Comments
 (0)