tegme / tegme
Lightweight telegra.ph/api client.
Requires
- php: >=5.6
- ext-curl: *
- ext-json: *
- ext-mbstring: *
Requires (Dev)
- phpunit/phpunit: 6.5.*
This package is auto-updated.
Last update: 2025-03-14 09:53:25 UTC
README
Tegme is pretty simple in use and lightweight client for api.telegra.ph.
Original API description you can find here.
Contents
Installation
$ composer require tegme/tegme
Requirements
All extension dependencies defined in composer.json:
- cURL - we need it for making requests to telegra.ph API;
- JSON - we need it for create requests data for querying telegra.ph API;
- mbstring - we need it for interaction with multi-byte strings;
- PHP >= 5.6 - code of this library compatible with PHP since 5.6.
Usage
First of all - you should create a client object:
use Tegme\Telegraph; $telegraphClient = new Telegraph();
Then - you should create one of the request object, defined in Tegme\Types\Requests\*
, e.g.:
use Tegme\Types\Requests\CreateAccount; $createAccountRequest = new CreateAccount( 'Example Short Name', 'Author Name', 'https://t.me/author_url' );
Note, that some of requests objects will validate in constructor and may throw exception (Tegme\Exceptions\InvalidRequestsInfoException
).
See the exception message about detailed information.
Next step - let's call api.telegra.ph:
/** * @var TelegraphResponse $response */ $response = $telegraphClient->call($createAccountRequest);
Tegme\Types\TelegraphResponse
- is simple wrapper for raw response.
You can get one of the Telegraph type (Tegme\Types\Response\*
) via:
/** @var mixed $resultObj */ $resultObj = $response->getResult();
or raw response in array format:
/** @var array $rawResponse */ $rawResponse = $response->getRawResponse();
Note that telegraph client may throw exceptions (Tegme\Exceptions\{TelegraphApiException, CurlException}
) while querying on api.telegra.ph
See exceptions messages about detailed information.
You can find all possible client usage here (example folder).
Author
Mazur Alexandr - alexandrmazur96@gmail.com - https://t.me/alexandrmazur96
License
Tegme is licensed under the GNU General Public License - see the LICENSE file for details.