1
1
# Supported APIs
2
2
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) `
22
29
23
30
Get current and forecast (minutely, hourly and daily) weather data.
24
31
@@ -30,7 +37,7 @@ $weather = $openWeatherMap->getOneCall()->getWeather(50, 50);
30
37
echo $weather->getCurrent()->getTemperature();
31
38
```
32
39
33
- ### ` getHistoryMoment(float $latitude, float $longitude, \DateTimeInterface $dateTime) `
40
+ #### ` getHistoryMoment(float $latitude, float $longitude, \DateTimeInterface $dateTime) `
34
41
35
42
Get weather data from a single moment in the past.
36
43
@@ -42,7 +49,7 @@ $weather = $openWeatherMap->getOneCall()->getHistoryMoment(50, 50, new \DateTime
42
49
echo $weather->getTemperature();
43
50
```
44
51
45
- ### ` getHistoryAggregate(float $latitude, float $longitude, \DateTimeInterface $date) `
52
+ #### ` getHistoryAggregate(float $latitude, float $longitude, \DateTimeInterface $date) `
46
53
47
54
Get aggregated weather data from a single day in the past.
48
55
@@ -54,9 +61,9 @@ $weather = $openWeatherMap->getOneCall()->getHistoryAggregate(50, 50, new \DateT
54
61
echo $weather->getTemperature();
55
62
```
56
63
57
- ## Weather
64
+ ### Weather
58
65
59
- ### ` getCurrent(float $latitude, float $longitude) `
66
+ #### ` getCurrent(float $latitude, float $longitude) `
60
67
61
68
Get current weather data.
62
69
@@ -68,7 +75,7 @@ $weather = $openWeatherMap->getWeather()->getCurrent(50, 50);
68
75
echo $weather->getTemperature();
69
76
```
70
77
71
- ### ` getForecast(float $latitude, float $longitude, int $numResults = 40) `
78
+ #### ` getForecast(float $latitude, float $longitude, int $numResults = 40) `
72
79
73
80
Get weather forecast data per 3-hour steps for the next 5 days.
74
81
@@ -85,9 +92,9 @@ foreach ($weatherForecast->getList() as $weather) {
85
92
}
86
93
```
87
94
88
- ## Air Pollution
95
+ ### Air Pollution
89
96
90
- ### ` getCurrent(float $latitude, float $longitude) `
97
+ #### ` getCurrent(float $latitude, float $longitude) `
91
98
92
99
Get current air pollution data.
93
100
@@ -100,7 +107,7 @@ echo $airPollution->getAirQuality()->getQualitativeName();
100
107
echo $airPollution->getCarbonMonoxide();
101
108
```
102
109
103
- ### ` getForecast(float $latitude, float $longitude) `
110
+ #### ` getForecast(float $latitude, float $longitude) `
104
111
105
112
Get air pollution forecast data per 1-hour for the next 24 hours.
106
113
@@ -116,7 +123,7 @@ foreach ($airPollutionForecast->getList() as $airPollution) {
116
123
}
117
124
```
118
125
119
- ### ` getHistory(float $latitude, float $longitude, \DateTimeInterface $startDate, \DateTimeInterface $endDate) `
126
+ #### ` getHistory(float $latitude, float $longitude, \DateTimeInterface $startDate, \DateTimeInterface $endDate) `
120
127
121
128
Get air pollution history data between two dates.
122
129
@@ -134,9 +141,9 @@ foreach ($airPollutionHistory->getList() as $airPollution) {
134
141
}
135
142
```
136
143
137
- ## Geocoding
144
+ ### Geocoding
138
145
139
- ### ` getByLocationName(string $locationName, int $numResults = 5) `
146
+ #### ` getByLocationName(string $locationName, int $numResults = 5) `
140
147
141
148
Get locations data by location name.
142
149
@@ -151,7 +158,7 @@ foreach ($locations as $location) {
151
158
}
152
159
```
153
160
154
- ### ` getByZipCode(string $zipCode, string $countryCode) `
161
+ #### ` getByZipCode(string $zipCode, string $countryCode) `
155
162
156
163
Get location data by zip/post code.
157
164
@@ -163,7 +170,7 @@ $location = $openWeatherMap->getGeocoding()->getByZipCode('1000-001', 'pt');
163
170
echo $location->getName();
164
171
```
165
172
166
- ### ` getByCoordinate(float $latitude, float $longitude, int $numResults = 5) `
173
+ #### ` getByCoordinate(float $latitude, float $longitude, int $numResults = 5) `
167
174
168
175
Get locations data by coordinate.
169
176
@@ -177,3 +184,51 @@ foreach ($locations as $location) {
177
184
echo $location->getCountryCode();
178
185
}
179
186
```
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
+ ```
0 commit comments