File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 1919 "php" : " ^8.3" ,
2020 "illuminate/contracts" : " ^10.0||^11.0||^12.0" ,
2121 "saloonphp/laravel-plugin" : " ^3.0" ,
22+ "saloonphp/rate-limit-plugin" : " ^2.0" ,
2223 "saloonphp/saloon" : " ^3.0" ,
2324 "spatie/laravel-package-tools" : " ^1.16"
2425 },
Original file line number Diff line number Diff line change 44
55namespace Ziming \LaravelGetResponse ;
66
7+ use Illuminate \Support \Facades \Cache ;
78use Saloon \Contracts \Authenticator ;
89use Saloon \Http \Auth \HeaderAuthenticator ;
910use Saloon \Http \Connector ;
11+ use Saloon \RateLimitPlugin \Contracts \RateLimitStore ;
12+ use Saloon \RateLimitPlugin \Limit ;
13+ use Saloon \RateLimitPlugin \Stores \LaravelCacheStore ;
14+ use Saloon \RateLimitPlugin \Stores \MemoryStore ;
15+ use Saloon \RateLimitPlugin \Traits \HasRateLimits ;
1016
1117/*
1218 * Add Oauth authenticator in the future
1319 */
1420class LaravelGetResponse extends Connector
1521{
22+ use HasRateLimits;
23+
1624 public function __construct (protected readonly string $ token ) {}
1725
1826 protected function defaultAuth (): HeaderAuthenticator
@@ -24,4 +32,24 @@ public function resolveBaseUrl(): string
2432 {
2533 return 'https://api.getresponse.com/v3/ ' ;
2634 }
35+
36+ protected function resolveLimits (): array
37+ {
38+ return [
39+ Limit::allow (80 )
40+ ->everySeconds (1 ),
41+
42+ // 600 seconds is 10 minutes
43+ Limit::allow (30_000 )
44+ ->everySeconds (600 ),
45+ ];
46+ }
47+
48+ protected function resolveRateLimitStore (): RateLimitStore
49+ {
50+ return new LaravelCacheStore (
51+ Cache::store (config ('cache.default ' )
52+ )
53+ );
54+ }
2755}
You can’t perform that action at this time.
0 commit comments