onesend-gmbh/onesend-php-sdk

PHP SDK for OneSend messaging service

1.0.2 2024-04-18 14:16 UTC

This package is auto-updated.

Last update: 2024-10-18 15:16:55 UTC


README

Requirements

To use the OneSend PHP SDK the following things are required:

Installation

Using Composer

The best way to install the OneSend PHP SDK is by using Composer. You can require it with the following command:

composer require onesend-gmbh/onesend-php-sdk

Usage

Initialise the SDK by passing the Api Key from your Project Dashboard.

$oneSend = new \OnesendGmbh\OnesendPhpSdk\OneSendApi('YOUR KEY HERE');

Optionally you can also pass a PSR-18 compliant Client as second argument if you want to modify timeouts/retry behavior or for Testing.

Using the SDK you can now access the following endpoints:

You can find our full documentation here.

Short Messages

Sending Short Messages (SMS)

Create Short Message reference

$shortMessage = $oneSend->shortMessages->send([
    'to' => '+4915730955123',
    'from' => 'TEST',
    'message' => 'THIS IS A TEST',
]);

This will create a ShortMessage Resource with a message ID $shortMessage->getId() you can and some other information about the sent short message.

Testing

By default, the SDK will set the Symfony Http Client as HTTP Client on initialisation, meaning should you not Mock calls to the SDK, it WILL send request to our service and your tests will most likely fail.
If you don't want to (or can't) mock the calls to the SDK you can also replace the HTTP Client with a Mock Client (PHP HTTP Mock Client for example) by passing it as the second constructor argument:

$mockClient = new Http\Mock\Client();
$oneSend = new \OnesendGmbh\OnesendPhpSdk\OneSendApi('I am a Test', $mockClient);

This will replace the default Http Client and will enable you to intercept and validate requests made by the SDK as well as mock responses with the desired outcome.
To see the expected responses please consult our API docs.