PHP code example of phaldan / discourse
1. Go to this page and download the library: Download phaldan/discourse library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phaldan / discourse example snippets
$discourse = new \PhALDan\Discourse\Discourse();
$rest = $discourse->rest('https://meta.discourse.org');
$response = $rest->category()->list();
$categories = json_decode($response->getBody()->getContents());
foreach ($categories->category_list->categories as $category) {
print $category->name.PHP_EOL;
}
$discourse = new \PhALDan\Discourse\Discourse();
$rest = $discourse->restAsync('https://meta.discourse.org');
$rest->category()->list()->then(function(\Psr\Http\Message\ResponseInterface $response) {
$categories = json_decode($response->getBody()->getContents());
foreach ($categories->category_list->categories as $category) {
print $category->name.PHP_EOL;
}
}, function(\Exception $e) {
print get_class($e).PHP_EOL;
print $e->getMessage().PHP_EOL;
})->wait();
try {
$discourse = new \PhALDan\Discourse\Discourse();
$auth = new \PhALDan\Discourse\Client\ApiKeyAuth('phaldan', 'uy284kxc8ou6c38u6...');
$rest = $discourse->rest('https://meta.discourse.org', $auth);
$rest->category()->list();
} catch (\Exception $e) {
print get_class($e).PHP_EOL;
print $e->getCode().PHP_EOL;
print $e->getMessage().PHP_EOL;
}
try {
$discourse = new \PhALDan\Discourse\Discourse();
$auth = new \PhALDan\Discourse\Client\ApiKeyAuth('phaldan', 'uy284kxc8ou6c38u6...');
$rest = $discourse->restAsync('https://meta.discourse.org', $auth);
$rest->category()->list()->wait();
} catch (\Exception $e) {
print get_class($e).PHP_EOL;
print $e->getCode().PHP_EOL;
print $e->getMessage().PHP_EOL;
}