Skip to content

Commit 7f4b38b

Browse files
committed
feat(docs): added common methods to supported apis page
1 parent 9f0e25d commit 7f4b38b

File tree

2 files changed

+94
-39
lines changed

2 files changed

+94
-39
lines changed

docs/03-supported-apis.md

Lines changed: 87 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
# Supported APIs
22

3-
- [One Call](#one-call)
4-
- [getWeather](#getweatherfloat-latitude-float-longitude)
5-
- [getHistoryMoment](#gethistorymomentfloat-latitude-float-longitude-datetimeinterface-datetime)
6-
- [getHistoryAggregate](#gethistoryaggregatefloat-latitude-float-longitude-datetimeinterface-date)
7-
- [Weather](#weather)
8-
- [getCurrent](#getcurrentfloat-latitude-float-longitude)
9-
- [getForecast](#getforecastfloat-latitude-float-longitude-int-numresults--40)
10-
- [Air Pollution](#air-pollution)
11-
- [getCurrent](#getcurrentfloat-latitude-float-longitude-1)
12-
- [getForecast](#getforecastfloat-latitude-float-longitude)
13-
- [getHistory](#gethistoryfloat-latitude-float-longitude-datetimeinterface-startdate-datetimeinterface-enddate)
14-
- [Geocoding](#geocoding)
15-
- [getByLocationName](#getbylocationnamestring-locationname-int-numresults--5)
16-
- [getByZipCode](#getbyzipcodestring-zipcode-string-countrycode)
17-
- [getByCoordinate](#getbycoordinatefloat-latitude-float-longitude-int-numresults--5)
18-
19-
## One Call
20-
21-
### `getWeather(float $latitude, float $longitude)`
3+
- [APIs](#apis)
4+
- [One Call](#one-call)
5+
- [getWeather](#getweatherfloat-latitude-float-longitude)
6+
- [getHistoryMoment](#gethistorymomentfloat-latitude-float-longitude-datetimeinterface-datetime)
7+
- [getHistoryAggregate](#gethistoryaggregatefloat-latitude-float-longitude-datetimeinterface-date)
8+
- [Weather](#weather)
9+
- [getCurrent](#getcurrentfloat-latitude-float-longitude)
10+
- [getForecast](#getforecastfloat-latitude-float-longitude-int-numresults--40)
11+
- [Air Pollution](#air-pollution)
12+
- [getCurrent](#getcurrentfloat-latitude-float-longitude-1)
13+
- [getForecast](#getforecastfloat-latitude-float-longitude)
14+
- [getHistory](#gethistoryfloat-latitude-float-longitude-datetimeinterface-startdate-datetimeinterface-enddate)
15+
- [Geocoding](#geocoding)
16+
- [getByLocationName](#getbylocationnamestring-locationname-int-numresults--5)
17+
- [getByZipCode](#getbyzipcodestring-zipcode-string-countrycode)
18+
- [getByCoordinate](#getbycoordinatefloat-latitude-float-longitude-int-numresults--5)
19+
- [Common Methods](#common-methods)
20+
- [withUnitSystem](#withunitsystemstring-unitsystem)
21+
- [withLanguage](#withlanguagestring-language)
22+
- [withCacheTtl](#withcachettlint-time)
23+
24+
## APIs
25+
26+
### One Call
27+
28+
#### `getWeather(float $latitude, float $longitude)`
2229

2330
Get current and forecast (minutely, hourly and daily) weather data.
2431

@@ -30,7 +37,7 @@ $weather = $openWeatherMap->getOneCall()->getWeather(50, 50);
3037
echo $weather->getCurrent()->getTemperature();
3138
```
3239

33-
### `getHistoryMoment(float $latitude, float $longitude, \DateTimeInterface $dateTime)`
40+
#### `getHistoryMoment(float $latitude, float $longitude, \DateTimeInterface $dateTime)`
3441

3542
Get weather data from a single moment in the past.
3643

@@ -42,7 +49,7 @@ $weather = $openWeatherMap->getOneCall()->getHistoryMoment(50, 50, new \DateTime
4249
echo $weather->getTemperature();
4350
```
4451

45-
### `getHistoryAggregate(float $latitude, float $longitude, \DateTimeInterface $date)`
52+
#### `getHistoryAggregate(float $latitude, float $longitude, \DateTimeInterface $date)`
4653

4754
Get aggregated weather data from a single day in the past.
4855

@@ -54,9 +61,9 @@ $weather = $openWeatherMap->getOneCall()->getHistoryAggregate(50, 50, new \DateT
5461
echo $weather->getTemperature();
5562
```
5663

57-
## Weather
64+
### Weather
5865

59-
### `getCurrent(float $latitude, float $longitude)`
66+
#### `getCurrent(float $latitude, float $longitude)`
6067

6168
Get current weather data.
6269

@@ -68,7 +75,7 @@ $weather = $openWeatherMap->getWeather()->getCurrent(50, 50);
6875
echo $weather->getTemperature();
6976
```
7077

71-
### `getForecast(float $latitude, float $longitude, int $numResults = 40)`
78+
#### `getForecast(float $latitude, float $longitude, int $numResults = 40)`
7279

7380
Get weather forecast data per 3-hour steps for the next 5 days.
7481

@@ -85,9 +92,9 @@ foreach ($weatherForecast->getList() as $weather) {
8592
}
8693
```
8794

88-
## Air Pollution
95+
### Air Pollution
8996

90-
### `getCurrent(float $latitude, float $longitude)`
97+
#### `getCurrent(float $latitude, float $longitude)`
9198

9299
Get current air pollution data.
93100

@@ -100,7 +107,7 @@ echo $airPollution->getAirQuality()->getQualitativeName();
100107
echo $airPollution->getCarbonMonoxide();
101108
```
102109

103-
### `getForecast(float $latitude, float $longitude)`
110+
#### `getForecast(float $latitude, float $longitude)`
104111

105112
Get air pollution forecast data per 1-hour for the next 24 hours.
106113

@@ -116,7 +123,7 @@ foreach ($airPollutionForecast->getList() as $airPollution) {
116123
}
117124
```
118125

119-
### `getHistory(float $latitude, float $longitude, \DateTimeInterface $startDate, \DateTimeInterface $endDate)`
126+
#### `getHistory(float $latitude, float $longitude, \DateTimeInterface $startDate, \DateTimeInterface $endDate)`
120127

121128
Get air pollution history data between two dates.
122129

@@ -134,9 +141,9 @@ foreach ($airPollutionHistory->getList() as $airPollution) {
134141
}
135142
```
136143

137-
## Geocoding
144+
### Geocoding
138145

139-
### `getByLocationName(string $locationName, int $numResults = 5)`
146+
#### `getByLocationName(string $locationName, int $numResults = 5)`
140147

141148
Get locations data by location name.
142149

@@ -151,7 +158,7 @@ foreach ($locations as $location) {
151158
}
152159
```
153160

154-
### `getByZipCode(string $zipCode, string $countryCode)`
161+
#### `getByZipCode(string $zipCode, string $countryCode)`
155162

156163
Get location data by zip/post code.
157164

@@ -163,7 +170,7 @@ $location = $openWeatherMap->getGeocoding()->getByZipCode('1000-001', 'pt');
163170
echo $location->getName();
164171
```
165172

166-
### `getByCoordinate(float $latitude, float $longitude, int $numResults = 5)`
173+
#### `getByCoordinate(float $latitude, float $longitude, int $numResults = 5)`
167174

168175
Get locations data by coordinate.
169176

@@ -177,3 +184,51 @@ foreach ($locations as $location) {
177184
echo $location->getCountryCode();
178185
}
179186
```
187+
188+
## Common Methods
189+
190+
#### `withUnitSystem(string $unitSystem)`
191+
192+
Makes a request with a different unit system from the one globally defined in the [configuration](02-configuration.md#unitsystem).
193+
194+
Only available for [`OneCall`](#one-call) and [`Weather`](#weather) APIs.
195+
196+
```php
197+
use ProgrammatorDev\OpenWeatherMap\UnitSystem\UnitSystem;
198+
199+
// Uses 'imperial' unit system for this request alone
200+
$openWeatherMap->getWeather()
201+
->withUnitSystem(UnitSystem::IMPERIAL)
202+
->getCurrent(50, 50);
203+
```
204+
205+
#### `withLanguage(string $language)`
206+
207+
Makes a request with a different language from the one globally defined in the [configuration](02-configuration.md#language).
208+
209+
Only available for [`OneCall`](#one-call) and [`Weather`](#weather) APIs.
210+
211+
```php
212+
use ProgrammatorDev\OpenWeatherMap\Language\Language
213+
214+
// Uses 'pt' language for this request alone
215+
$openWeatherMap->getWeather()
216+
->withLanguage(Language::PORTUGUESE)
217+
->getCurrent(50, 50);
218+
```
219+
220+
#### `withCacheTtl(?int $time)`
221+
222+
Makes a request and saves into cache with the provided time duration value (in seconds).
223+
Check the [Cache TTL](02-configuration.md#cache-ttl) section for more information regarding default values.
224+
225+
Available for all APIs if `cache` is enabled in the [configuration](02-configuration.md#cache).
226+
227+
```php
228+
use ProgrammatorDev\OpenWeatherMap\Language\Language
229+
230+
// Cache will be saved for 1 hour for this request alone
231+
$openWeatherMap->getWeather()
232+
->withCacheTtl(3600)
233+
->getCurrent(50, 50);
234+
```

docs/05-objects.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,19 @@
5555

5656
### OneCall
5757

58-
`getCoordinate()`: [`Coordinate`](05-objects.md#coordinate)
58+
`getCoordinate()`: [`Coordinate`](#coordinate)
5959

60-
`getTimezone()`: [`Timezone`](05-objects.md#timezone)
60+
`getTimezone()`: [`Timezone`](#timezone)
6161

62-
`getCurrent()`: [`Weather`](05-objects.md#weather)
62+
`getCurrent()`: [`Weather`](#weather)
6363

64-
`getMinutelyForecast()`: [`?MinuteForecast[]`](05-objects.md#minuteforecast)
64+
`getMinutelyForecast()`: [`?MinuteForecast[]`](#minuteforecast)
6565

66-
`getHourlyForecast()`: [`Weather[]`](05-objects.md#weather)
66+
`getHourlyForecast()`: [`Weather[]`](#weather)
6767

68-
`getDailyForecast()`: [`Weather[]`](05-objects.md#weather)
68+
`getDailyForecast()`: [`Weather[]`](#weather)
6969

70-
`getAlerts()`: [`?Alert[]`](05-objects.md#alert)
70+
`getAlerts()`: [`?Alert[]`](#alert)
7171

7272
### Weather
7373

0 commit comments

Comments
 (0)