Skip to content

Commit 514fb63

Browse files
committed
docs: updated config and geocoding resource
1 parent df731d3 commit 514fb63

5 files changed

+53
-170
lines changed

README.md

+9-20
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,26 @@ You must sign up for an [OpenWeatherMap account](https://openweathermap.org/appi
1919

2020
## Installation
2121

22-
You can install the library via [Composer](https://getcomposer.org/):
22+
Install the library via [Composer](https://getcomposer.org/):
2323

2424
```bash
2525
composer require programmatordev/openweathermap-php-api
2626
```
2727

28-
To use the library, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):
29-
30-
```php
31-
require_once 'vendor/autoload.php';
32-
```
33-
3428
## Basic Usage
3529

3630
Simple usage looks like:
3731

3832
```php
39-
use ProgrammatorDev\OpenWeatherMap\Config;
4033
use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;
4134

42-
// Initialize
43-
$openWeatherMap = new OpenWeatherMap(
44-
new Config([
45-
'applicationKey' => 'yourappkey'
46-
])
47-
);
48-
49-
// Get current weather by coordinate (latitude, longitude)
50-
$currentWeather = $openWeatherMap->weather()->getCurrent(50, 50);
51-
// Show current temperature
52-
echo $currentWeather->getTemperature();
35+
// initialize
36+
$api = new OpenWeatherMap('yourapikey');
37+
38+
// get current weather by coordinate (latitude, longitude)
39+
$weather = $api->weather()->getCurrent(50, 50);
40+
// show current temperature
41+
echo $weather->getTemperature();
5342
```
5443

5544
## Documentation
@@ -58,7 +47,7 @@ echo $currentWeather->getTemperature();
5847
- [Configuration](docs/02-configuration.md)
5948
- [Supported APIs](docs/03-supported-apis.md)
6049
- [Error Handling](docs/04-error-handling.md)
61-
- [Objects](docs/05-objects.md)
50+
- [Entities](docs/05-entities)
6251

6352
## Contributing
6453

docs/01-usage.md

+8-19
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,24 @@ You must sign up for an [OpenWeatherMap account](https://openweathermap.org/appi
1616

1717
## Installation
1818

19-
You can install the library via [Composer](https://getcomposer.org/):
19+
Install the library via [Composer](https://getcomposer.org/):
2020

2121
```bash
2222
composer require programmatordev/openweathermap-php-api
2323
```
2424

25-
To use the library, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):
26-
27-
```php
28-
require_once 'vendor/autoload.php';
29-
```
30-
3125
## Basic Usage
3226

3327
Simple usage looks like:
3428

3529
```php
36-
use ProgrammatorDev\OpenWeatherMap\Config;
3730
use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;
3831

39-
// Initialize
40-
$openWeatherMap = new OpenWeatherMap(
41-
new Config([
42-
'applicationKey' => 'yourappkey'
43-
])
44-
);
45-
46-
// Get current weather by coordinate (latitude, longitude)
47-
$currentWeather = $openWeatherMap->weather()->getCurrent(50, 50);
48-
// Show current temperature
49-
echo $currentWeather->getTemperature();
32+
// initialize
33+
$api = new OpenWeatherMap('yourapikey');
34+
35+
// get current weather by coordinate (latitude, longitude)
36+
$weather = $api->weather()->getCurrent(50, 50);
37+
// show current temperature
38+
echo $weather->getTemperature();
5039
```

docs/02-configuration.md

+11-74
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,38 @@
22

33
- [Default Configuration](#default-configuration)
44
- [Options](#options)
5-
- [applicationKey](#applicationkey)
65
- [unitSystem](#unitsystem)
76
- [language](#language)
8-
- [httpClientBuilder](#httpclientbuilder)
9-
- [cache](#cache)
10-
- [logger](#logger)
11-
- [Config Object](#config-object)
127

138
## Default Configuration
149

15-
Only the `applicationKey` option is required:
16-
1710
```php
18-
use ProgrammatorDev\OpenWeatherMap\Config;
19-
use ProgrammatorDev\OpenWeatherMap\HttpClient\HttpClientBuilder;
2011
use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;
2112

22-
$openWeatherMap = new OpenWeatherMap(
23-
new Config([
24-
'applicationKey' => 'yourappkey', // required
25-
'unitSystem' => 'metric',
26-
'language' => 'en',
27-
'httpClientBuilder' => new HttpClientBuilder(),
28-
'cache' => null,
29-
'logger' => null
30-
])
31-
);
13+
$api = new OpenWeatherMap('yourapikey', [
14+
'unitSystem' => 'metric',
15+
'language' => 'en'
16+
]);
3217
```
3318

3419
## Options
3520

36-
### `applicationKey`
37-
38-
Required for all requests. Check the [API Key](01-usage.md#api-key) section for more information.
39-
4021
### `unitSystem`
4122

4223
Unit system used when retrieving data.
4324
Affects temperature and speed values.
4425

4526
Available options are `metric`, `imperial` and `standard`.
46-
Pre-defined [constants](../src/UnitSystem/UnitSystem.php) are also available.
4727

4828
Example:
4929

5030
```php
51-
use ProgrammatorDev\OpenWeatherMap\Config;
5231
use ProgrammatorDev\OpenWeatherMap\UnitSystem\UnitSystem;
5332
use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;
5433

55-
$openWeatherMap = new OpenWeatherMap(
56-
new Config([
57-
'applicationKey' => 'yourappkey',
58-
'unitSystem' => UnitSystem::IMPERIAL
59-
])
60-
);
34+
$api = new OpenWeatherMap('yourapikey',
35+
'unitSystem' => UnitSystem::IMPERIAL
36+
]);
6137
```
6238

6339
### `language`
@@ -66,21 +42,16 @@ Language used when retrieving data.
6642
It seems to only affect weather conditions descriptions.
6743

6844
List of all available languages can be found [here](https://openweathermap.org/api/one-call-3#multi).
69-
Pre-defined [constants](../src/Language/Language.php) are also available.
7045

7146
Example:
7247

7348
```php
74-
use ProgrammatorDev\OpenWeatherMap\Config;
7549
use ProgrammatorDev\OpenWeatherMap\Language\Language;
7650
use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;
7751

78-
$openWeatherMap = new OpenWeatherMap(
79-
new Config([
80-
'applicationKey' => 'yourappkey',
81-
'language' => Language::PORTUGUESE
82-
])
83-
);
52+
$api = new OpenWeatherMap('yourapikey',
53+
'language' => Language::PORTUGUESE
54+
]);
8455
```
8556

8657
### `httpClientBuilder`
@@ -226,38 +197,4 @@ $openWeatherMap = new OpenWeatherMap(
226197
```
227198

228199
> **Note**
229-
> If a `cache` implementation is configured, cache events will also be logged.
230-
231-
## Config Object
232-
233-
Configuration getters and setters for all options are available to access and change after initialization:
234-
235-
```php
236-
use ProgrammatorDev\OpenWeatherMap\Config;
237-
use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;
238-
239-
$openWeatherMap = new OpenWeatherMap(
240-
new Config([
241-
'applicationKey' => 'yourappkey'
242-
])
243-
);
244-
245-
// Using applicationKey as an example,
246-
// but getters and setters are available for all options
247-
$openWeatherMap->config()->getApplicationKey();
248-
$openWeatherMap->config()->setApplicationKey('newappkey');
249-
```
250-
251-
Just take into account that any change will affect any subsequent request globally:
252-
253-
```php
254-
// Using default 'metric' unit system
255-
$openWeatherMap->weather()->getCurrent(50, 50);
256-
257-
// Set new unit system
258-
$openWeatherMap->config()->setUnitSystem(UnitSystem::IMPERIAL);
259-
260-
// Using 'imperial' unit system
261-
$openWeatherMap->weather()->getCurrent(50, 50);
262-
$openWeatherMap->weather()->getForecast(50, 50);
263-
```
200+
> If a `cache` implementation is configured, cache events will also be logged.

docs/03-supported-apis.md

+24-42
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
- [getHistory](#gethistory)
1515
- [Geocoding](#geocoding)
1616
- [getByLocationName](#getbylocationname)
17-
- [getByZipCode](#getbyzipcode)
1817
- [getByCoordinate](#getbycoordinate)
18+
- [getByZipCode](#getbyzipcode)
1919
- [Common Methods](#common-methods)
2020
- [withUnitSystem](#withunitsystem)
2121
- [withLanguage](#withlanguage)
@@ -33,7 +33,7 @@ getWeather(float $latitude, float $longitude): OneCall
3333

3434
Get current and forecast (minutely, hourly and daily) weather data.
3535

36-
Returns a [`OneCall`](05-objects.md#onecall) object:
36+
Returns a [`OneCall`](05-entities#onecall) object:
3737

3838
```php
3939
$weather = $openWeatherMap->oneCall()->getWeather(50, 50);
@@ -49,7 +49,7 @@ getHistoryMoment(float $latitude, float $longitude, \DateTimeInterface $dateTime
4949

5050
Get weather data from a single moment in the past.
5151

52-
Returns a [`WeatherLocation`](05-objects.md#weatherlocation) object:
52+
Returns a [`WeatherLocation`](05-entities#weatherlocation) object:
5353

5454
```php
5555
$weather = $openWeatherMap->oneCall()->getHistoryMoment(50, 50, new \DateTime('2023-01-01 12:00:00'));
@@ -65,7 +65,7 @@ getHistoryAggregate(float $latitude, float $longitude, \DateTimeInterface $date)
6565

6666
Get aggregated weather data from a single day in the past.
6767

68-
Returns a [`WeatherAggregate`](05-objects.md#weatheraggregate) object:
68+
Returns a [`WeatherAggregate`](05-entities#weatheraggregate) object:
6969

7070
```php
7171
$weather = $openWeatherMap->oneCall()->getHistoryAggregate(50, 50, new \DateTime('1985-07-19'));
@@ -83,7 +83,7 @@ getCurrent(float $latitude, float $longitude): WeatherLocation
8383

8484
Get current weather data.
8585

86-
Returns a [`WeatherLocation`](05-objects.md#weatherlocation-1) object:
86+
Returns a [`WeatherLocation`](05-entities#weatherlocation-1) object:
8787

8888
```php
8989
$weather = $openWeatherMap->weather()->getCurrent(50, 50);
@@ -99,7 +99,7 @@ getForecast(float $latitude, float $longitude, int $numResults = 40): WeatherLoc
9999

100100
Get weather forecast data per 3-hour steps for the next 5 days.
101101

102-
Returns a [`WeatherLocationList`](05-objects.md#weatherlocationlist) object:
102+
Returns a [`WeatherLocationList`](05-entities#weatherlocationlist) object:
103103

104104
```php
105105
// Since it returns 3-hour steps,
@@ -122,7 +122,7 @@ getCurrent(float $latitude, float $longitude): AirPollutionLocation
122122

123123
Get current air pollution data.
124124

125-
Returns a [`AirPollutionLocation`](05-objects.md#airpollutionlocation) object:
125+
Returns a [`AirPollutionLocation`](05-entities#airpollutionlocation) object:
126126

127127
```php
128128
$airPollution = $openWeatherMap->airPollution()->getCurrent(50, 50);
@@ -139,7 +139,7 @@ getForecast(float $latitude, float $longitude): AirPollutionLocationList
139139

140140
Get air pollution forecast data per 1-hour for the next 24 hours.
141141

142-
Returns a [`AirPollutionLocationList`](05-objects.md#airpollutionlocationlist) object:
142+
Returns a [`AirPollutionLocationList`](05-entities#airpollutionlocationlist) object:
143143

144144
```php
145145
$airPollutionForecast = $openWeatherMap->airPollution()->getForecast(50, 50);
@@ -159,7 +159,7 @@ getHistory(float $latitude, float $longitude, \DateTimeInterface $startDate, \Da
159159

160160
Get air pollution history data between two dates.
161161

162-
Returns a [`AirPollutionLocationList`](05-objects.md#airpollutionlocationlist) object:
162+
Returns a [`AirPollutionLocationList`](05-entities#airpollutionlocationlist) object:
163163

164164
```php
165165
$startDate = new \DateTime('-7 days'); // 7 days ago
@@ -177,62 +177,44 @@ foreach ($airPollutionHistory->getList() as $airPollution) {
177177

178178
#### `getByLocationName`
179179

180+
Get locations by location name. Returns an array of [`Location`](05-entities#location) entities:
181+
180182
```php
181183
/**
182184
* @return Location[]
183185
*/
184186
getByLocationName(string $locationName, int $numResults = 5): array
185187
```
186188

187-
Get locations data by location name.
188-
189-
Returns an array of [`Location`](05-objects.md#location) objects:
190-
191-
```php
192-
$locations = $openWeatherMap->geocoding()->getByLocationName('lisbon');
193-
194-
foreach ($locations as $location) {
195-
echo $location->getName();
196-
echo $location->getCountryCode();
197-
}
198-
```
199-
200-
#### `getByZipCode`
201-
202-
```php
203-
getByZipCode(string $zipCode, string $countryCode): ZipCodeLocation
204-
```
205-
206-
Get location data by zip/post code.
207-
208-
Returns a [`ZipCodeLocation`](05-objects.md#zipcodelocation) object:
209-
210189
```php
211-
$location = $openWeatherMap->geocoding()->getByZipCode('1000-001', 'pt');
212-
213-
echo $location->getName();
190+
$api->geocoding()->getByLocationName('lisbon');
214191
```
215192

216193
#### `getByCoordinate`
217194

195+
Get locations by coordinate. Returns an array of [`Location`](05-entities#location) entities:
196+
218197
```php
219198
/**
220199
* @return Location[]
221200
*/
222201
getByCoordinate(float $latitude, float $longitude, int $numResults = 5): array
223202
```
224203

225-
Get locations data by coordinate.
204+
```php
205+
$api->geocoding()->getByCoordinate(50, 50);
206+
```
207+
208+
#### `getByZipCode`
226209

227-
Returns an array of [`Location`](05-objects.md#location) objects:
210+
Get location by zip code. Returns a [`Location`](05-entities#location) entity:
228211

229212
```php
230-
$locations = $openWeatherMap->geocoding()->getByCoordinate(50, 50);
213+
getByZipCode(string $zipCode, string $countryCode): Location
214+
```
231215

232-
foreach ($locations as $location) {
233-
echo $location->getName();
234-
echo $location->getCountryCode();
235-
}
216+
```php
217+
$api->geocoding()->getByZipCode('1000-001', 'pt');
236218
```
237219

238220
## Common Methods

0 commit comments

Comments
 (0)