Search by

kelcode / tooley

gizzmoshifu

Official PHP SDK for the Tooley commercial API

v0.1.0 2026-12-03 11:10 UTC

This package is auto-updated.

Last update: 2026-12-03 11:15:10 UTC


README

Official synchronous PHP SDK for Tooley's commercial API. Requires 64-bit PHP 8.3 or later and the cURL and JSON extensions. No third-party Composer runtime dependencies; framework-neutral PSR-4 autoloading under Kelcode\Tooley.

Install a published stable release from Packagist:

composer require kelcode/tooley
use Kelcode\Tooley\TooleyClient;

$client = new TooleyClient(apiToken: getenv('TOOLEY_API_TOKEN') ?: null);
$tools = $client->listTools()['tools'];

Use Composer's autoloader. Pass credentials explicitly from your secret management system. Public catalogue and purchase operations do not send the token. The default origin is https://api.tooley.work; baseUrl must be a trusted HTTPS origin. Native cURL verifies TLS, disables redirects and ignores proxy environment variables. A custom Transport is trusted and intended for tests. Requests use fresh cURL handles with a total timeout (default 60 seconds). Never expose the SDK or token through browser code.

Operations

listTools, getTool, submitJob, getJob, cancelJob, waitForJob, run, listOutputs, downloadOutput, getBalance, listTransactions, listCreditPacks, startCheckout, getPurchase, redeemRetrieval.

Use the live catalogue to discover parameters, accepted file counts, limits and tariffs. Parameter-only submissions send a flat JSON object; pass an associative PHP array, using stdClass for nested empty JSON objects and arrays for JSON lists. For file tools, pass files: [new Upload('example.txt', $bytes, 'text/plain')]. Upload accepts bytes or an open readable, blocking binary stream; the caller owns the stream and must rewind it before any deliberate replay. Multipart uses repeated files fields and one JSON params field. The SDK prepares multipart bodies in an automatically cleaned temporary file to avoid buffering all files in RAM.

run submits once and polls until a terminal job. Inspect the returned state and error; failed and cancelled jobs are returned rather than automatically resubmitted. Polling uses a monotonic deadline (default 300 seconds) and honours HTTP 429 Retry-After. Timeout does not cancel remote work. No automatic chargeable submission or one-time redemption retries. For ambiguous submissions, persist and reuse the same caller-provided idempotency key with identical parameters and file contents (1–200 printable non-space ASCII characters). SDK submission errors retain the key; polling errors retain the known job ID. A new key may reserve credits again.

downloadOutput transfers the response into a temporary disk-backed file before returning a Download object. Iterate chunks() and close the object if not fully consumed; the object also cleans up on destruction. This is bounded-memory, synchronous download, not a live network stream. The caller owns the final output path and must not trust suggested filenames. HTTP 410 indicates expired outputs. Configure a trusted, private temporary directory with sufficient space for uploads and downloads; the SDK does not enforce a disk quota or securely erase temporary files. JSON responses have a 16 MiB limit and error responses are bounded.

TooleyApiError provides status, errorCode and optional retryAfter (seconds). The exception message is deliberately generic, not the raw server response. Transport, protocol and timeout errors use fixed messages. Do not log exceptions with recovery properties, request data, response data, retrieval secrets or credentials. Types are generated PHPStan-compatible array-shape annotations, not full runtime schema validation. The API remains authoritative for money, tools and retention. Checkout acknowledgement must be supplied exactly as shown on the website; the SDK never invents it.

Development and security

The authoritative source repository contains the tests, generators and integration tooling. The distribution repository mirrors validated release files only. Submit contributions and issues to the source repository; follow its security reporting policy for vulnerabilities.

From packages/php (Composer, PHPUnit extensions, ZipArchive, Python 3 and OpenSSL are required for development checks):

composer install --no-plugins --no-scripts
composer validate --strict
composer audit
composer test
bash scripts/test-transport.sh
composer test:package

Commit composer.lock after the first successful dependency resolution. The manifest selects PHP 8.3 as the dependency-resolution platform so the same development lockfile can be tested on the complete runtime matrix. composer generate regenerates the wire type annotations from the shared contract. The native transport test runs against a loopback TLS fixture using an ephemeral test certificate. php tests/run.php executes the same mock scenarios without Composer for local diagnosis; it does not replace the PHPUnit, native transport or consumer packaging gates. Production integration is separate and opt-in.