File tree Expand file tree Collapse file tree 6 files changed +24
-24
lines changed Expand file tree Collapse file tree 6 files changed +24
-24
lines changed Original file line number Diff line number Diff line change 13
13
],
14
14
"require" : {
15
15
"php" : " >=8.1" ,
16
+ "myclabs/deep-copy" : " ^1.11" ,
16
17
"programmatordev/php-api-sdk" : " ^0.2.0" ,
17
18
"programmatordev/yet-another-php-validator" : " ^1.1"
18
19
},
Original file line number Diff line number Diff line change 23
23
$coordinate->getLongitude()
24
24
);
25
25
}
26
- // bad request to the api
26
+ // bad request to the API
27
27
catch (BadRequestException $exception) {
28
28
echo $exception->getCode(); // 400
29
29
echo $exception->getMessage();
@@ -39,7 +39,7 @@ 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();
65
65
$coordinate->getLongitude()
66
66
);
67
67
}
68
- // catches all api response errors
68
+ // catches all API response errors
69
69
catch (ApiErrorException $exception) {
70
70
echo $exception->getCode();
71
71
echo $exception->getMessage();
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ class OpenWeatherMap extends Api
20
20
private array $ options ;
21
21
22
22
public function __construct (
23
- #[\SensitiveParameter] private readonly string $ apiKey ,
23
+ #[\SensitiveParameter] private string $ apiKey ,
24
24
array $ options = []
25
25
)
26
26
{
Original file line number Diff line number Diff line change 5
5
use ProgrammatorDev \Api \Method ;
6
6
use ProgrammatorDev \OpenWeatherMap \Entity \Location ;
7
7
use ProgrammatorDev \OpenWeatherMap \OpenWeatherMap ;
8
+ use ProgrammatorDev \OpenWeatherMap \Resource \Util \CacheTrait ;
8
9
use ProgrammatorDev \OpenWeatherMap \Resource \Util \ValidationTrait ;
9
10
use ProgrammatorDev \OpenWeatherMap \Util \EntityTrait ;
10
11
use ProgrammatorDev \Validator \Exception \ValidationException ;
11
12
use Psr \Http \Client \ClientExceptionInterface ;
12
13
13
14
class GeocodingResource
14
15
{
16
+ use CacheTrait;
15
17
use EntityTrait;
16
18
use ValidationTrait;
17
19
18
20
private const NUM_RESULTS = 5 ;
19
21
20
- public function __construct (private readonly OpenWeatherMap $ api ) {}
22
+ public function __construct (private OpenWeatherMap $ api ) {}
21
23
22
24
/**
23
25
* @return Location[]
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace ProgrammatorDev \OpenWeatherMap \Resource \Util ;
4
+
5
+ use function DeepCopy \deep_copy ;
6
+
7
+ trait CacheTrait
8
+ {
9
+ public function withCacheTtl (?int $ ttl ): static
10
+ {
11
+ $ clone = deep_copy ($ this );
12
+ $ clone ->api ->getCacheBuilder ()?->setTtl($ ttl );
13
+
14
+ return $ clone ;
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments