2017 © Pedro Peláez
 

library php-client

Library for communicating with provider

image

smsapi/php-client

Library for communicating with provider

  • Wednesday, January 3, 2018
  • by smsapi
  • Repository
  • 10 Watchers
  • 34 Stars
  • 100,459 Installations
  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 25 Forks
  • 3 Open issues
  • 34 Versions
  • 17 % Grown

The README.md

SMSAPI PHP Client

Build Status Packagist - latest version Packagist - downloads Packagist - license, (*1)

Version 1.8.7 available here, (*2)

SMSAPI.COM API documentation, (*3)

SMSAPI.PL API documentation, (*4)

Requirements

Install package with dependencies

Execute: composer require smsapi/php-client, (*5)

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:, (*6)

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., (*7)

For your convenience we provide an adapter for Curl. To use it you have to enable PHP curl extension and install some HTTP helpers:, (*8)

composer require guzzlehttp/psr7:^1

Example below shows how to make use of that adapter (pay attention to namespace Smsapi\Client\Curl):, (*9)

<?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):, (*10)

<?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., (*11)

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 SMSAPI.SE or SMSAPI.BG services?

<?php

declare(strict_types=1);

use Smsapi\Client\SmsapiClient;

require_once 'vendor/autoload.php';

/**
 * @var SmsapiClient $client
 */
require_once 'client.php';

$apiToken = '0000000000000000000000000000000000000000';
$uri = 'https://smsapi.io/';

$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., (*12)

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 use 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., (*13)

Required parameters

Required parameters are that class public properties, usually accessible via some form of a setter or named constructor. Each parameter can be also set directly by setting bag property, as in example:, (*14)

How to change SMS encoding?
<?php

declare(strict_types=1);

use Smsapi\Client\Feature\Sms\Bag\SendSmsBag;

$sms = SendSmsBag::withMessage('someone phone number', 'some message');
$sms->encoding = 'utf-8';

Optional parameters

Some of request's optional parameters have been described by docblock's '@property' annotation. You can always add any not documented here optional parameter by setting dynamic property to 'bag'. Camel case property names are being converted to snake case on the fly., (*15)

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., (*16)

How to use additional features?

How to use proxy server?

To use proxy server you have to define it with your HTTP client., (*17)

How to log requests and responses?

Set logger to SmsapiHttpClient instance., (*18)

<?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);

How to test package

Copy phpunit.dist.xml to phpunit.xml. You may adjust it to your needs then., (*19)

Copy tests-resources/config/config.dist.yml to tests-resources/config/config.yml. Fill in SMSAPI service connection data., (*20)

How to run unit tests

Unit tests are included into package build process and run against its current version on every commit (see workflow Tests). You can run those tests locally with ease using provided Docker configuration, simply run:, (*21)

make test-suite SUITE="unit"

How to run integration tests

Note that integration test works within an account you have configured in tests-resources/config/config.yml. Although those test have been written to self-cleanup on exit, in case of failure some trash data may stay. Use it with caution., (*22)

make test-suite SUITE="integration"

How to run feature tests

Feature test groups are defined in phpunit.dist.xml. To run tests execute:, (*23)

make test-suite SUITE="feature-contacts"

How to run tests against PHP8

To run any of mentioned above against PHP8 use make targets with php8 suffix. See Makefile.php8., (*24)

Docs & Infos

The Versions

03/01 2018

dev-master

9999999-dev http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

03/01 2018

v1.8.7

1.8.7.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

11/12 2017

v1.8.6

1.8.6.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

07/06 2017

v1.8.5

1.8.5.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

29/05 2017

v1.8.4

1.8.4.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

09/01 2017

v1.8.3

1.8.3.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

03/11 2016

v1.8.2

1.8.2.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

02/11 2016

v1.8.1

1.8.1.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

02/11 2016

v1.8.0

1.8.0.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

31/10 2016

v1.7.6

1.7.6.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

28/10 2016

1.7.5

1.7.5.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

11/10 2016

v1.7.4

1.7.4.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

20/05 2016

1.7.3

1.7.3.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

16/05 2016

1.7.2

1.7.2.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

27/04 2016

1.7.1

1.7.1.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

21/04 2016

1.7.0

1.7.0.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

03/08 2015

1.6.1

1.6.1.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

24/07 2015

1.6.0

1.6.0.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

23/07 2015

1.5.1

1.5.1.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

23/07 2015

1.5.0

1.5.0.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

22/07 2015

1.4.1

1.4.1.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

21/07 2015

1.4.0

1.4.0.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

20/07 2015

1.4.0.x-dev

1.4.0.9999999-dev http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

01/07 2015

1.3.5

1.3.5.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

13/05 2015

1.3.4

1.3.4.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

21/04 2015

1.3.3

1.3.3.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

02/04 2015

2.0.0.x-dev

2.0.0.9999999-dev http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

02/04 2015

1.3.2

1.3.2.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

01/04 2015

1.3.1

1.3.1.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

31/03 2015

1.3.0

1.3.0.0 http://smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

25/03 2015

1.2.1

1.2.1.0 http://www.smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

03/12 2014

1.2.0

1.2.0.0 http://www.smsapi.pl

Library for communicating with provider

  Sources   Download

Apache-2.0

The Development Requires

sms mms vms

23/04 2014

1.1.0

1.1.0.0 http://www.smsapi.pl

Library for communicating with provider

  Sources   Download

sms mms vms

07/03 2014

1.0.0

1.0.0.0 http://www.smsapi.pl

Library for communicating with provider

  Sources   Download

sms mms vms