Download the PHP package dansleboby/voipms-php-client without Composer
On this page you can find all versions of the php package dansleboby/voipms-php-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package voipms-php-client
VoIP.ms PHP Client
A robust PHP client for the VoIP.ms API, built on Guzzle with PSR-3 logging.
Features
- Easy-to-use client for all VoIP.ms API methods.
- Built on the popular Guzzle HTTP client for reliable requests.
- PSR-3 compliant logging for easy integration with your existing logging setup.
- Handles API errors and network issues gracefully with custom exceptions.
- Includes retry logic for transient network errors.
Requirements
- PHP >= 8.0
- GuzzleHttp/Guzzle ^7.0
- PSR/Log ^1.1|^2.0
Installation
You can install the package via Composer:
`
Usage
First, you need to instantiate the VoipMs\Client\Service\Client. It requires a Guzzle client instance, a PSR-3 logger instance, your VoIP.ms API username, and your API password.
Making API Calls
The primary method for interacting with the VoIP.ms API is call(string $method, array $params = []): array.
$method: The name of the API method you want to call (e.g.,getDIDsInfo,sendSMS). Refer to the official VoIP.ms API documentation for a list of available methods and their required parameters.$params: An associative array of parameters to send with the API request.
The client automatically adds your api_username, api_password, sets content_type to json, and includes the specified $method in the request.
Configuration
The Client constructor accepts optional arguments for timeout and maximum retries:
$timeout: Request timeout in seconds (default: 30).$maxRetries: Maximum number of retries for failed requests due to network issues (default: 3).
Error Handling
The client uses the following custom exceptions:
VoipMs\Client\Exception\ApiException: Thrown when the VoIP.ms API returns an error status (e.g., "status" field in the response is not "success"). You can access the API's response data using$e->getResponseData().VoipMs\Client\Exception\HttpException: Thrown for HTTP-level errors (e.g., status codes other than 200). You can access the raw HTTP response body using$e->getResponseBody().VoipMs\Client\Exception\JsonException: Thrown if the API response cannot be decoded as JSON. You can access the raw, undecoded response string using$e->getRawResponse().
Network errors leading to GuzzleHttp\Exception\RequestException or GuzzleHttp\Exception\TransferException are caught internally and retried up to $maxRetries times with an exponential backoff. If retries are exhausted, an HttpException is thrown.
Development
This project uses PHP CodeSniffer for coding standards and PHPUnit for testing. GrumPHP is configured to run checks automatically on commit.
Available Composer scripts:
composer cs:check: Check for coding standards violations.composer cs:fix: Automatically fix coding standards violations.composer test: Run coding standards checks and PHPUnit tests.
The PHPCS standard is defined in phpcs.xml.dist. GrumPHP tasks are configured in grumphp.yml.
Autoloading
- PSR-4 autoloading for application code:
VoipMs\Client\Service\maps tosrc/Service/andVoipMs\Client\Exception\maps tosrc/Exception/. - PSR-4 autoloading for development (tests):
App\Tests\maps totests/.
Author
- Gilbert Paquin [email protected]
License
This project is licensed under the MIT License. See the LICENSE file for details (You would need to create this file, but the composer.json specifies "MIT").