digitalcz / gosms
Provides communication with https://www.gosms.cz/api/ in PHP via PSR-18 http client
Installs: 16 808
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 4
Forks: 1
Open Issues: 7
Requires
- php: ^7.2 || ^8.0
- ext-json: *
- php-http/discovery: ^1.7
- psr/http-client: ^1.0
- psr/http-message: ^1.0.1
- psr/simple-cache: ^1.0
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^0.7
- nyholm/psr7: ^1.3
- php-http/httplug: ^2.1
- php-http/mock-client: ^1.3
- phpstan/phpstan: ^0.12.77
- phpunit/phpunit: ^8.5
- slevomat/coding-standard: ^6.3
- squizlabs/php_codesniffer: ^3.5.8
- symfony/cache: ^5.2
- symfony/http-client: ^5.2
- symfony/var-dumper: ^5.2
Suggests
- v1.1.0
- dev-master / 1.0.x-dev
- v1.0.1
- v1.0.0
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- dev-dependabot/github_actions/actions/cache-3.2.3
- dev-dependabot/github_actions/actions/checkout-3.1.0
- dev-dependabot/github_actions/codecov/codecov-action-3.1.1
- dev-dependabot/composer/slevomat/coding-standard-tw-6.3or-tw-8.0
- dev-dependabot/composer/phpstan/phpstan-tw-0.12.77or-tw-1.0.0
- dev-dependabot/composer/psr/simple-cache-tw-1.0or-tw-3.0
- dev-dependabot/composer/phpunit/phpunit-tw-8.5or-tw-9.0
- dev-improve-parsing-exception
This package is auto-updated.
Last update: 2024-04-09 09:33:10 UTC
README
Provides communication with GoSMS.cz (see https://doc.gosms.cz/) in PHP via PSR-18 http client. Implemented standards PSR18 http client, PSR17 Discovery and PSR16 cache.
Install
Via Composer
$ composer require digitalcz/gosms
Configuration
Example configuration in Symfony
#gosms.yaml for example parameters: goSmsChannelId: '%env(int:GO_SMS_CHANNEL)%' services: _defaults: autowire: true autoconfigure: true gosms_cache_provider: class: Symfony\Component\Cache\Psr16Cache arguments: ['@cache.app'] DigitalCz\GoSms\Auth\AccessTokenProvider: arguments: - '@gosms_cache_provider' DigitalCz\GoSms\Auth\AccessTokenProviderInterface: '@DigitalCz\GoSms\Auth\AccessTokenProvider' DigitalCz\GoSms\GoSms: arguments: $clientId: '%env(GO_SMS_CLIENT_ID)%' $clientSecret: '%env(GO_SMS_CLIENT_SECRET)%'
Usage
You can use DigitalCz\GoSms\Auth\AccessTokenProvider which use PSR6 CachingInterface (see https://www.php-fig.org/psr/psr-6/) for automatically store token. Or you can implement your own by DigitalCz\GoSms\Auth\AccessTokenProviderInterface
Client used value objects for Requests and Responses. If you want working with your own objects, you can implement DigitalCz\GoSms\Response\ResponseResolverInterface
// access token provider via Symfony $psr6Cache = new Symfony\Component\Cache\Adapter\FilesystemAdapter(); $psr16Cache = new Symfony\Component\Cache\Psr16Cache($psr6Cache); $accessTokenProvider = new DigitalCz\GoSms\Auth\AccessTokenProvider( $psr16Cache ); // GoSMS service $goSmsService = new DigitalCz\GoSms\GoSms( 'your_gosms_client_id', 'your_gosms_secret_client_id', $accessTokenProvider ); //return detail about organization DigitalCz\GoSms\ValueObject\DetailOrganization $organizationDetail = $goSmsService->getDetailOrganization(); //send message via DigitalCz\GoSms\ValueObject\SendMessage $message = new DigitalCz\GoSms\ValueObject\SendMessage('Hello Hans!', ['+420775300500'], 1); //return DigitalCz\GoSms\ValueObject\SentMessage $sentMessage = $goSmsService->sendMessage($message); $smsId = $sentMessage->getMessageId(); //return detail about message DigitalCz\GoSms\ValueObject\DetailMessage $messageDetail = $goSmsService->detailMessage($smsId); //return replies of message DigitalCz\GoSms\ValueObject\RepliesMessage $messageReplies = $goSmsService->repliesMessage($smsId); //delete message $goSmsService->deleteMessage($smsId);
Using your own http client
You can provide PSR18 http client (and PSR17 factories) when creating instance of classes, if no arguments are provided Psr18ClientDiscovery and Psr17FactoryDiscovery will be used (see https://php-http.readthedocs.io/en/latest/discovery.html).
.... // example Symfony Psr18Client for RequestFactory $symfonyHttpClient = Symfony\Component\HttpClient\Psr18Client(); $requestFactory = new DigitalCz\GoSms\Request\RequestFactory( $symfonyHttpClient, $symfonyHttpClient // symfony PSR18 client is also PSR17 factory ); ....
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer tests $ composer phpstan $ composer cs # codesniffer $ composer csfix # code beautifier
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email devs@digital.cz instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.