keinos / mastodon-streaming-api-listener
Listens to the server-sent messages of Mastodon Streaming API and returns the events in JSON.
1.0.1
2020-12-17 02:50 UTC
Requires
- php: ^8.0 || ^7.1
- ext-mbstring: *
- keinos/mastodon-streaming-api-config: ^1.0
- keinos/mastodon-streaming-api-parser: ^1.0
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.3
- drenso/phan-extensions: ^3.2
- phan/phan: ^3.0 || ^2.5
- php-coveralls/php-coveralls: ^2.2
- phpbench/phpbench: @dev
- phpmd/phpmd: @stable
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^0.12.10
- phpunit/phpunit: ^9.0 || ^8.0 || ^7.0 || ^6.5
- psalm/phar: ^3.9
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2024-10-23 13:32:33 UTC
README
Simple Mastodon Streaming API Listener
This is a PHP class that listens to the Mastodon Streaming API's server-sent messages.
Install
composer require keinos/mastodon-streaming-api-listener
Usage
<?php require_once __DIR__ . '/../vendor/autoload.php'; $conf = [ // Your Mastodon server URL 'url_host' => 'https://qiitadon.com/', ]; $listener = new \KEINOS\MSTDN_TOOLS\Listener\Listener($conf); /** * $listener ............ The iterator. * $event_name ........ Event name. ("update" or "delete") * $data_payload ...... Data of the event in JSON string. */ foreach($listener as $event_name => $data_payload) { echo 'Event name: ' . $event_name . PHP_EOL; echo 'Data: '. PHP_EOL; print_r(json_decode($data_payload)); }
<?php require_once __DIR__ . '/../vendor/autoload.php'; // Alias \KEINOS\MSTDN_TOOLS\Listener\Listener as Listener use KEINOS\MSTDN_TOOLS\Listener\Listener; $conf = [ 'url_host' => 'https://qiitadon.com/', // If the server is in "whitelist-mode" then you'll need an access token. 'access_token' => 'YOUR_ACCESS_TOKEN', ]; $listener = new Listener($conf); foreach($listener as $event_name => $data_payload) { echo 'Event name: ' . $event_name . PHP_EOL; echo 'Data: '. PHP_EOL; print_r(json_decode($data_payload)); }
<?php require_once __DIR__ . '/../vendor/autoload.php'; use KEINOS\MSTDN_TOOLS\Listener\Listener; $conf = [ 'url_host' => 'https://qiitadon.com/', // To listen the local time line stream set 'local'. 'public' is the default. 'type_stream' => 'local', ]; $listener = new Listener($conf); foreach($listener as $event_name => $data_payload) { echo 'Event name: ' . $event_name . PHP_EOL; echo 'Data: '. PHP_EOL; print_r(json_decode($data_payload)); }