@@ -15,36 +15,36 @@ use ProgrammatorDev\OpenWeatherMap\Exception\UnauthorizedException;
15
15
use ProgrammatorDev\OpenWeatherMap\Exception\UnexpectedErrorException;
16
16
17
17
try {
18
- $location = $openWeatherMap->geocoding()->getByZipCode('1000-001', 'pt');
18
+ $location = $api->geocoding()->getByZipCode('1000-001', 'pt');
19
+ $coordinate = $location->getCoordinate();
19
20
20
- $weather = $openWeatherMap ->oneCall()->getWeather(
21
- $location->getCoordinate()-> getLatitude(),
22
- $location->getCoordinate() ->getLongitude()
21
+ $weather = $api ->oneCall()->getWeather(
22
+ $coordinate-> getLatitude(),
23
+ $coordinate ->getLongitude()
23
24
);
24
25
}
25
- // Bad requests to the API
26
- // If this library is making a good job validating input data, this should not happen
26
+ // bad request to the api
27
27
catch (BadRequestException $exception) {
28
28
echo $exception->getCode(); // 400
29
29
echo $exception->getMessage();
30
30
}
31
- // Invalid API key or trying to request an endpoint with no granted access
31
+ // invalid API key or trying to request an endpoint with no granted access
32
32
catch (UnauthorizedException $exception) {
33
33
echo $exception->getCode(); // 401
34
34
echo $exception->getMessage();
35
35
}
36
- // Resource not found
37
- // For example, when trying to get a location with a zip/post code that does not exist
36
+ // resource not found
37
+ // for example, when trying to get a location with a zip code that does not exist
38
38
catch (NotFoundException $exception) {
39
39
echo $exception->getCode(); // 404
40
40
echo $exception->getMessage();
41
41
}
42
- // API key requests quota exceeded
42
+ // api key requests quota exceeded
43
43
catch (TooManyRequestsException $exception) {
44
44
echo $exception->getCode(); // 429
45
45
echo $exception->getMessage();
46
46
}
47
- // Any other error, probably an internal error
47
+ // any other error, probably an internal error
48
48
catch (UnexpectedErrorException $exception) {
49
49
echo $exception->getCode(); // 5xx
50
50
echo $exception->getMessage();
@@ -57,14 +57,15 @@ To catch all API errors with a single exception, `ApiErrorException` is availabl
57
57
use ProgrammatorDev\OpenWeatherMap\Exception\ApiErrorException;
58
58
59
59
try {
60
- $location = $openWeatherMap->geocoding()->getByZipCode('1000-001', 'pt');
60
+ $location = $api->geocoding()->getByZipCode('1000-001', 'pt');
61
+ $coordinate = $location->getCoordinate();
61
62
62
- $weather = $openWeatherMap ->oneCall()->getWeather(
63
- $location->getCoordinate()-> getLatitude(),
64
- $location->getCoordinate() ->getLongitude()
63
+ $weather = $api ->oneCall()->getWeather(
64
+ $coordinate-> getLatitude(),
65
+ $coordinate ->getLongitude()
65
66
);
66
67
}
67
- // Catches all API response errors
68
+ // catches all api response errors
68
69
catch (ApiErrorException $exception) {
69
70
echo $exception->getCode();
70
71
echo $exception->getMessage();
@@ -76,14 +77,14 @@ catch (ApiErrorException $exception) {
76
77
To catch invalid input data (like an out of range coordinate, blank location name, etc.), the ` ValidationException ` is available:
77
78
78
79
``` php
79
- use ProgrammatorDev\YetAnotherPhpValidator \Exception\ValidationException;
80
+ use ProgrammatorDev\Validator \Exception\ValidationException;
80
81
81
82
try {
82
- // An invalid latitude value is given
83
- $weather = $openWeatherMap ->weather()->getCurrent(999, 50);
83
+ // an invalid latitude value is given
84
+ $weather = $api ->weather()->getCurrent(999, 50);
84
85
}
85
86
catch (ValidationException $exception) {
86
- // Should print:
87
+ // should print:
87
88
// The latitude value should be between -90 and 90, 999 given.
88
89
echo $exception->getMessage();
89
90
}
0 commit comments