Download the PHP package delighted/delighted without Composer
On this page you can find all versions of the php package delighted/delighted. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download delighted/delighted
More information about delighted/delighted
Files in delighted/delighted
Package delighted
Short Description Delighted PHP API Client
License MIT
Homepage http://github.com/delighted/delighted-php
Informations about the package delighted
Delighted PHP API Client
Official PHP client for the Delighted API.
Requirements
- PHP 7.1 or greater
- The Composer package manager
- A Delighted API key
Installation
Install via Composer by adding this to your composer.json
:
Then install via:
This will also install the Guzzle HTTP request library that the Delighted PHP API Client depends upon.
Configuration
To get started, you need to configure the client with your secret API key. At some point in your application's initialization, before you call any other Delighted PHP API client methods, do this (replacing YOUR_API_KEY
with your actual API key, of course):
Note: Your API key is secret, and you should treat it like a password. You can find your API key in your Delighted account, under Settings > API.
Usage
Adding/updating people and scheduling surveys:
Unsubscribing people:
Listing people:
Listing unsubscribed people:
Listing bounced people:
Deleting a person and all of the data associated with them:
Deleting pending survey requests
Adding survey responses:
Retrieving a survey response:
Updating survey responses:
Listing survey responses:
Retrieving metrics:
Managing Autopilot:
Rate limits
If a request is rate limited, a \Delighted\RateLimitedException
exception is raised. You can rescue that exception to implement exponential backoff or retry strategies. The exception provides a getRetryAfter()
method to tell you how many seconds you should wait before retrying. For example:
Advanced Configuration and Testing
The various Delighted resource methods use a shared client object to make the HTTP requests to the Delighted server. To change how that shared client object works, you can pass an array of options to the \Delighted\Client::getInstance()
method (before you call any resource methods) that control its behavior.
The chief option you may want to change is baseUrl
, which defaults to https://api.delighted.com/v1/
. If you want to send Delighted API requests to a different URL (for example, a local mock server for testing), pass that URL as the value for the baseURL
array key in the options passed to \Delighted\Client::getInstance()
. For example:
You can also easily mock Delighted API requests and responses by following the pattern that the API client's test cases use:
- Use the
\Delighted\TestClient
class instead ofDelighted\Client
- Create a
\GuzzleHttp\Handler\MockHandler
to mock the requests. Because the$client
is a shared instance, you'll want to use a shared$mock_handler
, too. - Create
\GuzzleHttp\HandlerStack
and pass to the client. - Make assertions about the request and response as desired.
For example:
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Run the tests (
php -f run-tests.php
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Releasing
- Bump the version in
lib/Delighted/Version.php
. - Update the README and CHANGELOG as needed.
- Tag the commit for release.
- Push (Packagist will pick up the release from the tag).