Use BamBuddy's trailing-slash printers endpoint and tolerate /api/v1 in the saved URL
Deploy HickLab3D Dashboard / Deploy to production (push) Failing after 12s
Deploy HickLab3D Dashboard / Deploy to production (push) Failing after 12s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
b11538944f
commit
6b3f529a33
@@ -51,34 +51,24 @@ class Bambuddy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @param array<string, mixed> $query */
|
/** @param array<string, mixed> $query */
|
||||||
private function get(string $path, array $query = []): array
|
private function get(string $path, array $query = [], int $timeout = 8): array
|
||||||
{
|
{
|
||||||
if (! $this->configured()) {
|
if (! $this->configured()) {
|
||||||
throw new RuntimeException('BamBuddy API key is not configured.');
|
throw new RuntimeException('BamBuddy API key is not configured.');
|
||||||
}
|
}
|
||||||
|
$base = preg_replace('#/api(/v1)?$#', '', rtrim(trim($this->url()), '/'));
|
||||||
|
|
||||||
return Http::withHeaders(['X-API-Key' => $this->settings->for('bambuddy')['api_key']])
|
return Http::withHeaders(['X-API-Key' => trim((string) $this->settings->for('bambuddy')['api_key'])])
|
||||||
->acceptJson()->connectTimeout(3)->timeout(8)
|
->acceptJson()->connectTimeout(3)->timeout($timeout)
|
||||||
->get(rtrim($this->url(), '/').'/api/v1/'.ltrim($path, '/'), $query)->throw()->json() ?? [];
|
->get($base.'/api/v1/'.ltrim($path, '/'), $query)->throw()->json() ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function fetchPrinters(): array
|
private function fetchPrinters(): array
|
||||||
{
|
{
|
||||||
$url = rtrim($this->url(), '/').'/api/v1/printers';
|
return collect($this->get('printers/'))->filter(fn ($printer) => is_array($printer) && isset($printer['id']))
|
||||||
$apiKey = $this->settings->for('bambuddy')['api_key'];
|
->take(20)->map(function (array $printer): array {
|
||||||
|
|
||||||
$printers = Http::withHeaders(['X-API-Key' => $apiKey])
|
|
||||||
->acceptJson()->connectTimeout(3)->timeout(8)->get($url)->throw()->json() ?? [];
|
|
||||||
|
|
||||||
return collect($printers)->filter(fn ($printer) => is_array($printer) && isset($printer['id']))
|
|
||||||
->take(20)->map(function (array $printer) use ($apiKey): array {
|
|
||||||
try {
|
try {
|
||||||
$status = Http::withHeaders(['X-API-Key' => $apiKey])
|
return $printer + ['live' => $this->get('printers/'.(int) $printer['id'].'/status', timeout: 5)];
|
||||||
->acceptJson()->connectTimeout(3)->timeout(5)
|
|
||||||
->get(rtrim($this->url(), '/').'/api/v1/printers/'.(int) $printer['id'].'/status')
|
|
||||||
->throw()->json() ?? [];
|
|
||||||
|
|
||||||
return $printer + ['live' => $status];
|
|
||||||
} catch (Throwable $exception) {
|
} catch (Throwable $exception) {
|
||||||
report($exception);
|
report($exception);
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class BambuddyPageTest extends TestCase
|
|||||||
['id' => 1, 'tray_color' => null, 'tray_type' => null, 'remain' => 0, 'exists' => false],
|
['id' => 1, 'tray_color' => null, 'tray_type' => null, 'remain' => 0, 'exists' => false],
|
||||||
]]],
|
]]],
|
||||||
]),
|
]),
|
||||||
'https://3d.example.test/api/v1/printers' => Http::response([['id' => 1, 'name' => 'Printy Boii 2', 'model' => 'X1C']]),
|
'https://3d.example.test/api/v1/printers/' => Http::response([['id' => 1, 'name' => 'Printy Boii 2', 'model' => 'X1C']]),
|
||||||
'https://3d.example.test/api/v1/queue/' => Http::response([
|
'https://3d.example.test/api/v1/queue/' => Http::response([
|
||||||
['id' => 5, 'status' => 'pending', 'position' => 1, 'archive_name' => 'Queued_Bracket', 'completed_at' => null],
|
['id' => 5, 'status' => 'pending', 'position' => 1, 'archive_name' => 'Queued_Bracket', 'completed_at' => null],
|
||||||
['id' => 4, 'status' => 'completed', 'position' => 0, 'archive_name' => 'Old_Job', 'completed_at' => '2026-10-01T10:00:00'],
|
['id' => 4, 'status' => 'completed', 'position' => 0, 'archive_name' => 'Old_Job', 'completed_at' => '2026-10-01T10:00:00'],
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class DashboardAccessTest extends TestCase
|
|||||||
['receipt_id' => 77, 'name' => 'Buyer One', 'create_timestamp' => now()->timestamp],
|
['receipt_id' => 77, 'name' => 'Buyer One', 'create_timestamp' => now()->timestamp],
|
||||||
]]),
|
]]),
|
||||||
'https://api.etsy.com/v3/application/shops/42/listings*' => Http::response(['count' => 12, 'results' => []]),
|
'https://api.etsy.com/v3/application/shops/42/listings*' => Http::response(['count' => 12, 'results' => []]),
|
||||||
'https://3d.example.test/api/v1/printers' => Http::response([['id' => 1, 'name' => 'X1 Carbon']]),
|
'https://3d.example.test/api/v1/printers/' => Http::response([['id' => 1, 'name' => 'X1 Carbon']]),
|
||||||
'https://3d.example.test/api/v1/printers/1/status' => Http::response(['connected' => true, 'state' => 'RUNNING', 'progress' => 45]),
|
'https://3d.example.test/api/v1/printers/1/status' => Http::response(['connected' => true, 'state' => 'RUNNING', 'progress' => 45]),
|
||||||
'https://auth.example.test/token' => Http::response(['access_token' => 'shipping-token']),
|
'https://auth.example.test/token' => Http::response(['access_token' => 'shipping-token']),
|
||||||
'https://shipping.example.test/api/me/orders/detail' => Http::response(['Orders' => [
|
'https://shipping.example.test/api/me/orders/detail' => Http::response(['Orders' => [
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class IntegrationsTest extends TestCase
|
|||||||
{
|
{
|
||||||
Http::preventStrayRequests();
|
Http::preventStrayRequests();
|
||||||
Http::fake([
|
Http::fake([
|
||||||
'https://3d.example.test/api/v1/printers' => Http::response([['id' => 1, 'name' => 'X1 Carbon', 'status' => 'printing']]),
|
'https://3d.example.test/api/v1/printers/' => Http::response([['id' => 1, 'name' => 'X1 Carbon', 'status' => 'printing']]),
|
||||||
'https://3d.example.test/api/v1/printers/1/status' => Http::response(['connected' => true, 'state' => 'RUNNING', 'progress' => 45, 'temperatures' => ['nozzle' => 220, 'bed' => 60]]),
|
'https://3d.example.test/api/v1/printers/1/status' => Http::response(['connected' => true, 'state' => 'RUNNING', 'progress' => 45, 'temperatures' => ['nozzle' => 220, 'bed' => 60]]),
|
||||||
]);
|
]);
|
||||||
config()->set('services.bambuddy', ['url' => 'https://3d.example.test', 'api_key' => 'read-key']);
|
config()->set('services.bambuddy', ['url' => 'https://3d.example.test', 'api_key' => 'read-key']);
|
||||||
|
|||||||
Reference in New Issue
Block a user