Tegme is pretty simple in use and lightweight client for api.telegra.ph.
Original API description you can find here.
$ composer require tegme/tegme
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.
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).
Mazur Alexandr - [email protected] - https://t.me/alexandrmazur96
Tegme is licensed under the GNU General Public License - see the LICENSE file for details.