Cache integration API reads and refresh them on a schedule
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 28s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Hickmeister
2026-10-11 19:01:32 +01:00
co-authored by Claude Sonnet 5.5
parent 8bee8d42c7
commit 2fe4fbd91e
10 changed files with 253 additions and 24 deletions
+11 -7
View File
@@ -11,6 +11,8 @@ class Etsy
{
private const API_URL = 'https://api.etsy.com/v3';
public function __construct(private IntegrationCache $cache) {}
/** @var array{keystring: ?string, shared_secret: ?string, shop_name: string, redirect_uri: ?string}|null */
private ?array $credentials = null;
@@ -62,18 +64,20 @@ class Etsy
]);
}
public function receipts(EtsyConnection $connection): array
public function receipts(EtsyConnection $connection, bool $fresh = false): array
{
return $this->get('application/shops/'.$connection->shop_id.'/receipts', $this->accessToken($connection), [
'was_paid' => 'true', 'was_shipped' => 'false', 'limit' => 20,
]);
return $this->cache->remember('etsy.receipts.'.$connection->shop_id, 300, fn (): array => $this->get(
'application/shops/'.$connection->shop_id.'/receipts', $this->accessToken($connection), [
'was_paid' => 'true', 'was_shipped' => 'false', 'limit' => 20,
]), $fresh);
}
public function listings(EtsyConnection $connection): array
{
return $this->get('application/shops/'.$connection->shop_id.'/listings', $this->accessToken($connection), [
'state' => 'active', 'limit' => 20,
]);
return $this->cache->remember('etsy.listings.'.$connection->shop_id, 600, fn (): array => $this->get(
'application/shops/'.$connection->shop_id.'/listings', $this->accessToken($connection), [
'state' => 'active', 'limit' => 20,
]));
}
private function accessToken(EtsyConnection $connection): string