PHP code example of t3ran13 / php-graphene-node-client
1. Go to this page and download the library: Download t3ran13/php-graphene-node-client 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/ */
t3ran13 / php-graphene-node-client example snippets
use GrapheneNodeClient\Commands\CommandQueryData;
use GrapheneNodeClient\Commands\Commands;
use GrapheneNodeClient\Commands\Single\GetDiscussionsByCreatedCommand;
use GrapheneNodeClient\Connectors\WebSocket\GolosWSConnector;
use GrapheneNodeClient\Connectors\WebSocket\SteemitWSConnector;
//Set params for query
$commandQuery = new CommandQueryData();
$data = [
[
'limit' => $limit,
'select_tags' => ['golos'], // for GOLOS
'tag' => 'steemit', // for STEEMIT
]
];
$commandQuery->setParams($data);
//OR
$commandQuery = new CommandQueryData();
$commandQuery->setParamByKey('0:limit', $limit);
$commandQuery->setParamByKey('0:select_tags', [$tag]);
$commandQuery->setParamByKey('0:tag', $tag);
//and use single command
$command = new GetDiscussionsByCreatedCommand(new GolosWSConnector());
$golosPosts = $command->execute(
$commandQuery
);
//or commands aggregator class
$commands = new Commands(new GolosWSConnector());
$golosPosts = $commands->get_discussions_by_created()
->execute(
$commandQuery
);
// will return
// [
// "id" => 1,
// "result" => [
// [
// "id": 466628,
// "author": "piranya",
// "permlink": "devyatyi-krug",
// ...
// ],
// ...
// ]
// ]
//single command
$command = new GetDiscussionsByCreatedCommand(new SteemitWSConnector());
$steemitPosts = $command->execute(
$commandQuery,
'result',
SteemitWSConnector::ANSWER_FORMAT_ARRAY // or SteemitWSConnector::ANSWER_FORMAT_OBJECT
);
//or commands aggregator class
$commands = new Commands(new GolosWSConnector());
$golosPosts = $commands->get_discussions_by_created()
->execute(
$commandQuery,
'result',
SteemitWSConnector::ANSWER_FORMAT_ARRAY // or SteemitWSConnector::ANSWER_FORMAT_OBJECT
);
// will return
// [
// [
// "id": 466628,
// "author": "piranya",
// "permlink": "devyatyi-krug",
// ...
// ],
// ...
// ]
use GrapheneNodeClient\Tools\ChainOperations\OpVote;
use GrapheneNodeClient\Connectors\Http\SteemitHttpConnector;
use GrapheneNodeClient\Connectors\WebSocket\GolosWSConnector;
$connector = new SteemitHttpConnector();
//$connector = new GolosWSConnector();
//$connector = new VizWSConnector();
$answer = OpVote::doSynchronous(
$connector,
'guest123',
'5JRaypasxMx1L97ZUX7YuC5Psb5EAbF821kkAGtBj7xCJFQcbLg',
'firepower',
'steemit-veni-vidi-vici-steemfest-2016-together-we-made-it-happen-thank-you-steemians',
10000
);
// example of answer
//Array
//(
// [id] => 5
// [result] => Array
// (
// [id] => a2c52988ea870e446480782ff046994de2666e0d
// [block_num] => 17852337
// [trx_num] => 1
// [expired] =>
// )
//
//)
use GrapheneNodeClient\Commands\CommandQueryData;
use GrapheneNodeClient\Commands\Single\GetContentCommand;
use GrapheneNodeClient\Connectors\InitConnector;
$command = new GetContentCommand(InitConnector::getConnector(InitConnector::PLATFORM_STEEMIT));
$commandQuery = new CommandQueryData();
$commandQuery->setParamByKey('0', 'author');
$commandQuery->setParamByKey('1', 'permlink');
//OR
$commandQuery = new CommandQueryData();
$commandQuery->setParams(
[
0 => "author",
1 => "permlink"
]
);
$content = $command->execute(
$commandQuery
);
// will return
// [
// "id" => 1,
// "result" => [
// ...
// ]
// ]
namespace My\App\Connectors;
use GrapheneNodeClient\Connectors\ConnectorInterface;
class MyConnector implements ConnectorInterface
{
public function setConnectionTimeoutSeconds($timeoutSeconds) {
// TODO: Implement setConnectionTimeoutSeconds() method.
}
public function setMaxNumberOfTriesToReconnect($triesN) {
// TODO: Implement setMaxNumberOfTriesToReconnect() method.
}
/**
* platform name for witch connector is. steemit or golos.
*/
public function getPlatform() {
// TODO: Implement getPlatform() method.
}
/**
* @param string $apiName calling api name - follow_api, database_api and ect.
* @param array $data options and data for request
* @param string $answerFormat
*
* @return array|object return answer data
*/
public function doRequest($apiName, array $data, $answerFormat = self::ANSWER_FORMAT_ARRAY) {
// TODO: Implement doRequest() method.
}
}
namespace My\App\Commands;
use GrapheneNodeClient\Commands\Single\CommandAbstract;
use GrapheneNodeClient\Connectors\ConnectorInterface;
class GolosWSConnector extends WSConnectorAbstract
{
/**
* @var string
*/
protected $platform = self::PLATFORM_GOLOS;
/**
* waiting answer from Node during $wsTimeoutSeconds seconds
*
* @var int
*/
protected $wsTimeoutSeconds = 5;
/**
* max number of tries to get answer from the node
*
* @var int
*/
protected $maxNumberOfTriesToCallApi = 3;
/**
* wss or ws servers, can be list. First node is default, other are reserve.
* After $maxNumberOfTriesToCallApi tries connects to default it is connected to reserve node.
*
* @var string|array
*/
protected $nodeURL = ['wss://ws.golos.io', 'wss://api.golos.cf'];
}