smsapi / php-client
SMSAPI API PHP Client
Installs: 457 897
Dependents: 11
Suggesters: 0
Security: 0
Stars: 56
Watchers: 13
Forks: 33
Open Issues: 2
Requires
- php: ^7 || ^8.0
- ext-json: *
- psr/http-client: ^1
- psr/http-factory: ^1
- psr/http-message: ^1
- psr/log: ^1
Requires (Dev)
- ext-curl: *
- ext-mbstring: *
- doctrine/instantiator: 1.0.5 || ^1.4.0
- guzzlehttp/psr7: ^1
- phpdocumentor/reflection-docblock: ^4.3 || ^5.2.0
- phpdocumentor/type-resolver: ^0.5 || ^1.3.0
- phpunit/phpunit: ^6 || ^8
- symfony/yaml: ^3
Suggests
- ext-curl: To use Curl HttpClient
- guzzlehttp/psr7: To use Curl HttpClient and HTTP message factories
- dev-master
- v3.0.2
- v3.0.1
- v3.0.0
- v2.6.1
- v2.6.0
- v2.5.0
- v2.4.0
- v2.3.4
- v2.3.3
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.0
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.0
- v1.8.7
- v1.8.6
- v1.8.5
- v1.8.4
- v1.8.3
- v1.8.2
- v1.8.1
- v1.8.0
- v1.7.6
- 1.7.5
- v1.7.4
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.1
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.0
- dev-php-8
- dev-psr-18
- dev-ping
- dev-push
This package is auto-updated.
Last update: 2021-03-01 00:07:45 UTC
README
Requirements
Install package with dependencies
Execute: composer require smsapi/php-client
How to pick a service
Depending on which of SMSAPI service your account is, you should pick it calling one of a method from examples below:
PSR-17 and PSR-18
Starting from version 3, SMSAPI PHP Client supports PSR-17 and PSR-18 compliant HTTP clients. That way this library is independent of client of your choice. You have to provide HTTP client, request factory and stream factory to use our library.
For your convenience we provide an adapter for Curl. To use it you have to enable PHP curl extension and install some HTTP helpers:
composer require guzzlehttp/psr7:^1
Example below shows how to make use of that adapter (pay attention to namespace Smsapi\Client\Curl):
<?php declare(strict_types=1); use Smsapi\Client\Curl\SmsapiHttpClient; require_once 'vendor/autoload.php'; $client = new SmsapiHttpClient();
If your are not willing to use Curl as HTTP client then you have to provide your own HTTP client, request factory and stream factory, as in example below (pay attention to namespace Smsapi\Client):
<?php declare(strict_types=1); use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; use Smsapi\Client\SmsapiHttpClient; require_once 'vendor/autoload.php'; /** * @var ClientInterface $httpClient * @var RequestFactoryInterface $requestFactory * @var StreamFactoryInterface $streamFactory */ require_once 'your-own-psr18-stuff.php'; $client = new SmsapiHttpClient($httpClient, $requestFactory, $streamFactory);
All following examples consider you have client well-defined in client.php
file.
How to use SMSAPI.COM service?
<?php declare(strict_types=1); use Smsapi\Client\SmsapiClient; require_once 'vendor/autoload.php'; /** * @var SmsapiClient $client */ require_once 'client.php'; $apiToken = '0000000000000000000000000000000000000000'; $service = $client->smsapiComService($apiToken);
How to use SMSAPI.PL service?
<?php declare(strict_types=1); use Smsapi\Client\SmsapiClient; require_once 'vendor/autoload.php'; /** * @var SmsapiClient $client */ require_once 'client.php'; $apiToken = '0000000000000000000000000000000000000000'; $service = $client->smsapiPlService($apiToken);
How to use a service with custom URI?
<?php declare(strict_types=1); use Smsapi\Client\SmsapiClient; require_once 'vendor/autoload.php'; /** * @var SmsapiClient $client */ require_once 'client.php'; $apiToken = '0000000000000000000000000000000000000000'; $uri = 'http://example.com'; $service = $client->smsapiComServiceWithUri($apiToken, $uri);
How to use service business features?
All following examples consider you have an account on SMSAPI.COM and service has been setup in service.php
file.
How to use ping feature?
<?php declare(strict_types=1); use Smsapi\Client\Service\SmsapiComService; /** @var SmsapiComService $service */ require_once 'service.php'; $result = $service->pingFeature() ->ping(); if ($result->authorized) { echo 'Authorized'; } else { echo 'Not authorized'; }
How to send a SMS?
<?php declare(strict_types=1); use Smsapi\Client\Service\SmsapiComService; use Smsapi\Client\Feature\Sms\Bag\SendSmsBag; /** @var SmsapiComService $service */ require_once 'service.php'; $sms = SendSmsBag::withMessage('someone phone number', 'some message'); $service->smsFeature() ->sendSms($sms);
How to send a SMS with optional from field?
<?php declare(strict_types=1); use Smsapi\Client\Service\SmsapiComService; use Smsapi\Client\Feature\Sms\Bag\SendSmsBag; /** @var SmsapiComService $service */ require_once 'service.php'; $sms = SendSmsBag::withMessage('someone phone number', 'some message'); $sms->from = 'Test'; $service->smsFeature() ->sendSms($sms);
For more usage examples take a look at client test suite.
How to use optional request parameters?
Request parameters are represented in a form of data transfer object. DTOs can be found by searching for 'bag' postfixed classes. Each bag may contain required and optional parameters. Required parameters are that class public properties, usually accessible via some form of a setter or named constructor. Optional parameters are described by docblock's '@property' annotation.
Each parameter can be also set directly by setting bag property, as in example:
<?php declare(strict_types=1); use Smsapi\Client\Feature\Sms\Bag\SendSmsBag; $sms = SendSmsBag::withMessage('someone phone number', 'some message'); $sms->encoding = 'utf-8';
How to use additional features?
How to use proxy server?
To use proxy server you have to define it with your HTTP client.
How to log requests and responses?
Set logger to SmsapiHttpClient
instance.
<?php declare(strict_types=1); use Psr\Log\LoggerInterface; use Psr\Log\LoggerTrait; use Smsapi\Client\SmsapiClient; require_once 'vendor/autoload.php'; /** * @var SmsapiClient $client */ require_once 'client.php'; $logger = new class() implements LoggerInterface { use LoggerTrait; public function log($level, $message, array $context = []) { var_dump($level, $message, $context); } }; $client->setLogger($logger);
Test package
- Download package:
composer create-project smsapi/php-client
- Execute tests:
./vendor/bin/phpunit --configuration phpunit.dist.xml