PHPackages                             conservationafrica/darwin-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. conservationafrica/darwin-client

AbandonedArchivedProject

conservationafrica/darwin-client
================================

1.0.0(2y ago)03[3 PRs](https://github.com/conservationafrica/darwin-client/pulls)MITPHPPHP ~8.2 || ~8.3CI passing

Since Nov 29Pushed 1y ago1 watchersCompare

[ Source](https://github.com/conservationafrica/darwin-client)[ Packagist](https://packagist.org/packages/conservationafrica/darwin-client)[ RSS](/packages/conservationafrica-darwin-client/feed)WikiDiscussions 1.1.x Synced 1mo ago

READMEChangelog (1)Dependencies (17)Versions (6)Used By (0)

Darwin HTTP Client
==================

[](#darwin-http-client)

This is an HTTP client to interact with the Darwin "REST API". Darwin is a tour operator SAAS product developed by

There are some rudimentary docs available at:

Things to watch out for:

- Every request will return a "200 OK" response, except for a 404 - this is probably because each API endpoint is a PHP file. Anyway, you have to inspect the response payload to see if the request was successful or not. This client takes care of inspecting the payload and converts request failures to exceptions with descriptive error messages.
- All requests must provide a body. The Auth Payload is sent as part of the request body.
- It appears as though only POST requests are accepted, so if a method is documented as a GET request, it probably isn't.
- Field names are case-sensitive. This tripped me up initially because fields were documented with incorrect casing.
- The docs are frequently incorrect or incomplete.
- Most of the response payloads are `array` - `null` array members are generally empty strings, `int` array members and generally numeric strings etc, so a lot of type coercions are required. This is not a hard and fast rule, generally typing in response payloads is inconsistent.
- The remote app stores unknown dates as int zero, which means that an unknown date is returned in payloads as 1970-01-01. This effectively means that specific date is equal to "unknown" and you have to hope that none of your clients were actually born on that day.

Requirements &amp; Installation
-------------------------------

[](#requirements--installation)

Because this lib makes use of [azjezz/psl](https://github.com/azjezz/psl), the `bcmath` extension is required. [composer.json](./composer.json) lists all you need to know about dependency requirements.

Installation via composer is the only supported installation method:

```
composer require conservationafrica/darwin-client
```

Usage
-----

[](#usage)

Generally speaking, you should type hint on the `\Darwin\Client` interface so that you can stub out the client in tests.

Type inference is pretty good, not 100% but near enough. You should use Psalm or PHPStan. It will help you!

All exceptions implement a common marker interface `\Darwin\DarwinError`. Wrap all calls to the client with something like:

```
use Darwin\Client;
use Darwin\DarwinError;

assert($client instanceof Client);

try {
    $customer = $client->findClientByEmailAddress('me@example.com');
} catch (DarwinError) {
    // Handle exception appropriately
}

printf('Hi %s 👋', $customer->firstName);
```

### Concrete Client Construction

[](#concrete-client-construction)

You'll need to construct the [concrete client](./src/HttpClient.php) with your DIC, there are several constructor dependencies:

```
