engeni / api-client-2
Engeni - API client V2
Requires
- php: ^8.3
- guzzlehttp/guzzle: ^7
- illuminate/contracts: ^9
- illuminate/pagination: ^9
- illuminate/support: ^9
- symfony/http-kernel: ^6.4
- symfony/var-dumper: ^6.4
Requires (Dev)
- laravel/pint: ^1.13
- orchestra/testbench: ^7
- phpunit/phpunit: ^9
- dev-master
- v8.1.0.x-dev
- v8.1.0
- v8.0.0
- v7.9.1
- v7.9.0
- v7.8.1
- v7.8.0
- v7.7.8
- v7.7.7
- v7.7.6
- v7.7.5
- v7.7.4
- v7.7.3
- v7.7.2
- v7.7.1
- v7.7.0
- v7.6.0
- v7.5.4
- v7.5.3
- v7.5.2
- v7.5.1
- v7.5.0
- v7.4.0
- v7.3.2
- v7.3.1
- v7.3.0
- v7.2.4
- v7.2.3
- v7.2.2
- v7.2.1
- v7.2.0
- v7.1.3
- v7.1.2
- v7.1.1
- v7.1.0
- V7.0.8
- v7.0.7
- v7.0.6
- v7.0.5
- v7.0.4
- v7.0.3
- v7.0.2
- v7.0.1
- v7.0.0
- V6.5.11
- V6.5.10
- v6.5.9
- v6.5.8
- V6.5.7
- v6.5.6
- v6.5.5
- v6.5.4
- v6.5.3
- v6.5.2
- v6.5.1
- v6.5
- v6.4.11
- v6.4.10
- v6.4.9
- v6.4.8
- v6.4.7
- v6.4.6
- v6.4.5
- v6.4.4
- v6.4.3
- v6.4.2
- v6.4.1
- v6.4.0
- v6.3.23
- v6.3.22
- v6.3.21
- v6.3.20
- v6.3.19
- v6.3.18
- v6.3.17
- v6.3.16
- v6.3.15
- v6.3.14
- v6.3.13
- v6.3.12
- v6.3.11
- v6.3.10
- v6.3.9
- v6.3.8
- v6.3.7
- v6.3.6
- v6.3.5
- v6.3.4
- v6.3.3
- v6.3.2
- v6.3.1
- v6.3.0
- v6.2.5
- v6.2.4
- v6.2.3
- v6.2.2
- v6.2.1
- v6.2.0
- v6.1.0
- v6.0.3
- v6.0.2
- v6.0.1
- v6.0.0
- v5.13.0
- v5.13.00
- v5.12.0
- v5.11.9
- v5.11.8
- v5.11.7
- v5.11.6
- v5.11.5
- v5.11.4
- v5.11.3
- v5.11.2
- v5.11.1
- v5.11.0
- v5.10.18
- v5.10.17
- v5.10.16
- v5.10.15
- v5.10.14
- v5.10.13
- v5.10.12
- v5.10.11
- v5.10.10
- v5.10.9
- v5.10.8
- v5.10.7
- v5.10.6
- v5.10.5
- v5.10.4
- v5.10.3
- v5.10.2
- v5.10.0
- v5.9.6
- v5.8.9
- v5.7.5
- v5.7.0
- dev-new-root
- dev-master2
- dev-temp
- dev-release/v5.10
- dev-release/v5.7
This package is auto-updated.
Last update: 2025-11-12 23:25:47 UTC
README
This refactor delivers a brand-new, SOLID-oriented Engeni API client that mirrors Laravel Eloquent's read/query and write behavior while remaining purely HTTP-driven. The legacy implementation now lives under old/, letting the package evolve without backward-compatibility constraints.
Highlights
- Complete CRUD support: Fluent, Eloquent-style operations for reading (
first,firstOrFail,find,findOrFail,get,paginate,simplePaginate,pluck,value,count,exists,doesntExist,cursor,chunk) and writing (create,save,update,delete,destroy,upsert). - Mass assignment protection: Laravel-style
$fillableand$guardedproperties for secure attribute handling. - Change tracking: Full support for
isDirty(),wasChanged(),getChanges(),getOriginal(), andgetPrevious()methods. - Dependency inversion throughout: a swappable
HttpClientInterfacekeeps the runtime and tests fully mockable. - Lightweight resource models that hydrate from Engeni's REST responses while offering familiar Eloquent ergonomics.
- Laravel-first integration with automatic service-provider discovery; once installed, the client is resolved from the container without manual wiring.
- Requires PHP 8.3+, letting us lean on modern language features such as typed class constants for safer configuration.
- Comprehensive PHPUnit + Orchestra Testbench suite, plus Bitbucket Pipelines that run
pint --testandphpuniton pull requests and master merges. - Observability helpers such as
Engeni\ApiClient2\Http\TracingHttpClientlet you capture the exact URL, method, and query parameters generated by the client without enabling verbose debug output.
Requirements
- PHP 8.3 or newer
- Guzzle 7+
- Laravel support components (pulled in automatically)
Installation
composer require engeni/api-client
Quick Start
use Engeni\ApiClient2\Resources\LaGuiaOnline\Business;
// Configure credentials via .env (see config/engeni.php).
// Reading data
$popularBusinesses = Business::query()
->where('country_id', 54)
->orderBy('name')
->paginate(25);
// Creating records
$business = Business::create([
'name' => 'Acme Corp',
'country_id' => 54,
'category_id' => 123,
]);
// Updating records
$business->name = 'Updated Corp Name';
$business->save();
// Deleting records
$business->delete();
Configuration
- The package ships with
config/engeni.php(publish viaphp artisan vendor:publish --tag=engeni-api-client-config). - By default it reads the following environment variables (with sensible fallbacks):
ENGENI_API_CLIENT_BASE_URI(falls back toENGENI_SERVICE_BASE_URI)ENGENI_API_CLIENT_TOKEN(falls back toENGENI_SERVICE_API_TOKEN)ENGENI_API_CLIENT_TIMEOUTENGENI_API_CLIENT_DEBUGENGENI_API_CLIENT_HTTP_DEBUG
ENGENI_SERVICE_ID(used for the defaultUser-Agent)- The service provider binds both
Client::classandHttpClientInterface::classas singletons and shares the instance with everyResourceModel, so you can call any resource class without manual bootstrapping. - Need custom transport? Bind your own implementation of
Engeni\ApiClient2\Contracts\Http\HttpClientInterfaceor tweak the published config.
Tracing Requests
Need to inspect the exact HTTP request being dispatched without enabling verbose dumps? Wrap any existing HTTP transport in the TracingHttpClient decorator. It records every call, exposing helper methods that you can assert against in tests or print in diagnostic scripts.
use Engeni\ApiClient2\Client;
use Engeni\ApiClient2\Http\GuzzleHttpClient;
use Engeni\ApiClient2\Http\TracingHttpClient;
use Engeni\ApiClient2\Resources\LaGuiaOnline\Country;
use GuzzleHttp\Client as GuzzleClient;
$http = new TracingHttpClient(
new GuzzleHttpClient(new GuzzleClient([
'base_uri' => config('services.engeni.base_uri'),
'headers' => ['Authorization' => 'Bearer '.config('services.engeni.token')],
]))
);
$client = new Client(
http: $http,
baseUri: config('services.engeni.base_uri'),
);
Country::setClient($client);
Country::query()->with('states')->limit(3)->get();
dump($http->lastRequest());
// [
// 'method' => 'GET',
// 'uri' => 'https://api.engeni.com/lgo/countries',
// 'options' => [
// 'query' => [
// 'embed' => 'states',
// 'limit' => 3,
// ],
// ],
// ]
$http->clear(); // reset the log once you have asserted what you need
Because TracingHttpClient implements the same contract as the production transport you can drop it into integration tests, CLI tools, or debugging sessions. The examples/countries.php playground ships with the tracer enabled so you can see every generated URL after each scenario.
Architecture at a Glance
- Client – Holds the base URI, default headers, and exposes
newQuery()for every resource definition. - HttpClientInterface – Abstraction over the transport layer (default
GuzzleHttpClient, but anything PSR-18/HTTP-capable can be wrapped). - Query\Builder – Fluent query object that translates Eloquent-style calls into Engeni-friendly query strings.
- ResourceModel – Minimal model layer that hydrates responses, offers attribute access, collections, and paginator interop.
- Support utilities – Helpers for pagination, response parsing, and tests (see
tests/Support).
Documentation
See context/guide.md for an extensive reference covering:
- Contract diagram, dependency injection guidelines, and how to provide your own HTTP transport.
- Every query builder method with signatures, behaviour notes, and examples.
- Pagination semantics (mapping Engeni
meta/linksinto Laravel paginators). - Testing recipes (mocking
HttpClientInterface, using Orchestra, asserting request shapes). - Pipelines, coding standards, and the roadmap for introducing write operations.
Quality Gates
composer install
composer lint # runs Pint in --test mode
composer test # runs PHPUnit + Orchestra suite
composer test:coverage # runs tests with HTML and text coverage reports
composer test:coverage:clover # runs tests with Clover XML coverage report
After running composer test:coverage, open coverage/html/index.html in your browser to view the detailed coverage report.
bitbucket-pipelines.yml executes the same commands on pull requests and on merges to master, ensuring styling and tests stay green before code lands.
Contributing
- Keep contributions read-only until write operations are designed.
- Prefer new contracts over deep inheritance; the package leans on dependency injection to ease mocking.
- Update docs and tests whenever you add behaviour.
License
GNU GPLv3 © Engeni International LLC.