davixlabs / h2i-sdk
Official PHP SDK for the Davix H2I API. Typed methods, machine-readable metadata (enums, minimum/maximum, defaults), structured exceptions and a safe generic request() -- all generated from the canonical Davix H2I contract.
Requires
- php: >=7.4
- ext-curl: *
- ext-json: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Official Davix H2I client for PHP 7.4+ (ext-curl, ext-json). Methods, enum constants and metadata are generated from the canonical Davix H2I contract.
Install
composer require davixlabs/h2i-sdk
Every app release copies this SDK, with the same version number, to the repository Davixlabs/davix-h2i-sdk-php; Packagist reads that repository.
Without Composer, download davix-h2i-php-sdk-<version>.tgz and require 'autoload.php';.
Use
require 'vendor/autoload.php'; // or require 'autoload.php'; $h2i = new \Davix\H2I\Client(['apiKey' => getenv('DAVIX_H2I_API_KEY'), 'baseUrl' => 'https://your-davix-h2i-host']); $res = $h2i->images()->resize(['images' => '/path/photo.jpg', 'width' => 800, 'resizeMode' => \Davix\H2I\Enums\ResizeFit::COVER]); echo $res->requestId;
-
Auth:
X-Api-Keyheader only. No secrets beyond the API key exist in the SDK. -
Metadata:
$h2i->schema('images.resize')(min/max/enum/default/type/required/behavior),$h2i->capabilities()(runtime),$h2i->staticCapabilities(),$h2i->accountCapabilities(),$h2i->refreshContract()for the live contract; the bundled one stays available. -
Enums: final classes with constants (
\Davix\H2I\Enums\ImageFormat::WEBP), usable on PHP 7.4 and later. -
Errors:
\Davix\H2I\Exceptions\DavixH2IExceptionsubclasses expose the public propertiesstatus,errorCode,requestId,hint,details,renewalUrl,retryable,retryAfterMsandbody. -
Retries: only retryable errors, only for safe methods or calls with an
idempotencyKeyoption; keys are never auto-invented for the caller. -
Uploads: file paths, raw strings wrapped as
['data' => …, 'filename' => …], or streams. A plain string is read from disk only for contract file fields. -
Escape hatch:
$h2i->request('GET', '/v1/usage')refuses/internal, admin and non-contract paths. -
Live slices:
$h2i->contractEndpoint($id),contractField($id, $name),contractEnum($name),contractError($code),contractCategories()and$h2i->capabilities()->section('pdfs')/->feature('pdfs', 'ocr')fetch just the piece you need.
Tests: php tests/run.php (needs node for the shared mock server).
Naming your app in the History
Every processing call takes an optional app, shown under each result in your History: $h2i->images()->resize(['images' => '/path/photo.jpg', 'width' => 800, 'app' => 'My shop importer']).