Cache integration API reads and refresh them on a schedule
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 28s
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:
co-authored by
Claude Sonnet 5.5
parent
8bee8d42c7
commit
2fe4fbd91e
+11
-7
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user