Announcement new php client [php-graphene-node-client v2.2.2]

in #opensource7 years ago (edited)

php-graphene-node-client

PHP client for connection to STEEM/GOLOS node

Install Via Composer

composer require t3ran13/php-graphene-node-client

Basic Usage

<?php

use GrapheneNodeClient\Commands\CommandQueryData;
use GrapheneNodeClient\Commands\DataBase\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);

$command = new GetDiscussionsByCreatedCommand(new GolosWSConnector());
$golosPosts = $command->execute(
    $commandQuery
);
// will return
// [
//      "id" => 1,
//      "result" => [
//            [
//                "id": 466628,
//                "author": "piranya",
//                "permlink": "devyatyi-krug",
//                ...
//            ],
//            ...
//      ]
// ]
  
$command = new GetDiscussionsByCreatedCommand(new SteemitWSConnector());
$steemitPosts = $command->execute(
    $commandQuery,
    'result',
    SteemitWSConnector::ANSWER_FORMAT_ARRAY // or SteemitWSConnector::ANSWER_FORMAT_OBJECT
);
// will return
// [
//      [
//          "id": 466628,
//          "author": "piranya",
//          "permlink": "devyatyi-krug",
//          ...
//      ],
//      ...
// ]


Implemented Commands List

namespace:

  • GrapheneNodeClient\Commands\Broadcast;
  • GrapheneNodeClient\Commands\DataBase;
  • GrapheneNodeClient\Commands\Follow;
  • GrapheneNodeClient\Commands\Login;

database_api

  • GetDynamicGlobalPropertiesCommand
  • GetBlockCommand
  • GetBlockHeaderCommand
  • GetWitnessesByVoteCommand
  • GetActiveWitnessesCommand
  • GetAccountCommand
  • GetAccountCountCommand
  • GetAccountHistoryCommand
  • GetAccountVotesCommand
  • GetContentCommand
  • GetDiscussionsByAuthorBeforeDateCommand
  • GetDiscussionsByBlogCommand
  • GetDiscussionsByCreatedCommand
  • GetDiscussionsByFeedCommand
  • GetDiscussionsByTrendingCommand
  • GetTrendingCategoriesCommand

login_api

  • GetApiByNameCommand
  • GetVersionCommand
  • LoginCommand

follow_api

  • GetFollowersCommand

broadcast_api

  • BroadcastTransactionCommand
  • BroadcastTransactionSynchronousCommand

Implemented Connectors List

namespace: GrapheneNodeClient\Connectors\WebSocket;

  • GolosWSConnector (wss://ws.golos.io)
  • SteemitWSConnector (wss://ws.steemit.com)

switch between connectors

<?php

use GrapheneNodeClient\Commands\CommandQueryData;
use GrapheneNodeClient\Commands\DataBase\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" => [
//            ...
//      ]
// ]


Creating Own Connector

<?php

namespace My\App\Connectors;

use GrapheneNodeClient\Connectors\ConnectorInterface;

class MyConnector implements ConnectorInterface 
{
    /**
    * 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.
    }

}


Creating Own Command

<?php

namespace My\App\Commands;

use GrapheneNodeClient\Commands\DataBase\CommandAbstract;
use GrapheneNodeClient\Connectors\ConnectorInterface;

class MyCommand extends CommandAbstract 
{
    protected $method            = 'method_name';
    //protected $apiName         = 'login_api'; in CommandAbstract have to be set correct $apiName
    
    //If different for platforms
    protected $queryDataMap = [
        ConnectorInterface::PLATFORM_GOLOS   => [
            //on the left is array keys and on the right is validators
            //validators for ani list element have to be have '*'  
            '*:limit'            => ['integer'], //the discussions return amount top limit
            '*:select_tags:*'    => ['nullOrString'], //list of tags to include, posts without these tags are filtered
            '*:select_authors:*' => ['nullOrString'], //list of authors to select
            '*:truncate_body'    => ['nullOrInteger'], //the amount of bytes of the post body to return, 0 for all
            '*:start_author'     => ['nullOrString'], //the author of discussion to start searching from
            '*:start_permlink'   => ['nullOrString'], //the permlink of discussion to start searching from
            '*:parent_author'    => ['nullOrString'], //the author of parent discussion
            '*:parent_permlink'  => ['nullOrString'] //the permlink of parent discussion
        ],
        ConnectorInterface::PLATFORM_STEEMIT => [
            //for list params
            '*:tag'            => ['nullOrString'], //'author',
            '*:limit'          => ['integer'], //'limit'
            '*:start_author'   => ['nullOrString'], //'start_author' for pagination,
            '*:start_permlink' => ['nullOrString'] //'start_permlink' for pagination,
        ]
    ];
    
    
    //If the same for platforms
    //protected $queryDataMap = [
    // route example: 'key:123:array' => $_SESSION['key'][123]['array']
    //    'some_array_key:some_other_key' => ['integer'],   // available validators are 'required', 'array', 'string',
                                                            // 'integer', 'nullOrArray', 'nullOrString', 'nullOrInteger'.
    //];
}


Tools

Transliterator

<?php

use GrapheneNodeClient\Tools\Transliterator;


//Encode tags
$tag = Transliterator::encode('пол', Transliterator::LANG_RU); // return 'pol';


//Decode tags
$tag = Transliterator::encode('ru--pol', Transliterator::LANG_RU); // return 'пол';

Reputation viewer

<?php

use GrapheneNodeClient\Tools\Reputation;

$rep = Reputation::calculate($account['reputation']);


Github or packagist with MIT license. Author @t3ran13. Active helper @semaspring

It is better with each commit

@transisto add it to steemtools.com please

Sort:  

Thanks informasinya...

Congratulations @php-node-client! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You published your First Post
You got a First Vote

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Could you suggest me specifically what to write on steemtools listing?

DM me on Steemit.chat

it is the same to steemphp

Coin Marketplace

STEEM 0.19
TRX 0.19
JST 0.033
BTC 89248.16
ETH 3020.22
USDT 1.00
SBD 2.81