From f0b6ea9d20285b986b6807d618eafc444ab4efc6 Mon Sep 17 00:00:00 2001 From: t3ran13 Date: Sat, 31 Mar 2018 16:34:03 +0300 Subject: [PATCH] upd commands partly commands was partly updated for new api and moved to Single Folder --- Commands/Commands.php | 35 +++--- Commands/DataBase/CommandInterface.php | 20 ---- .../DataBase/GetAccountHistoryCommand.php | 18 --- Commands/DataBase/GetAccountVotesCommand.php | 16 --- Commands/DataBase/GetActiveVotesCommand.php | 17 --- Commands/DataBase/GetBlockCommand.php | 16 --- Commands/DataBase/GetBlockHeaderCommand.php | 16 --- Commands/DataBase/GetContentCommand.php | 17 --- .../DataBase/GetContentRepliesCommand.php | 17 --- ...etDiscussionsByAuthorBeforeDateCommand.php | 16 --- .../DataBase/GetDiscussionsByBlogCommand.php | 30 ----- .../DataBase/GetDiscussionsByFeedCommand.php | 30 ----- .../GetDiscussionsByTrendingCommand.php | 30 ----- Commands/DataBase/GetOpsInBlock.php | 16 --- .../DataBase/GetTrendingCategoriesCommand.php | 14 --- .../DataBase/GetWitnessesByVoteCommand.php | 14 --- Commands/Login/CommandAbstract.php | 108 ------------------ Commands/Login/CommandInterface.php | 20 ---- Commands/Login/GetApiByNameCommand.php | 13 --- .../GetAccountCountCommand.php | 5 +- Commands/Single/GetAccountHistoryCommand.php | 11 ++ Commands/Single/GetAccountVotesCommand.php | 11 ++ Commands/Single/GetActiveVotesCommand.php | 11 ++ .../GetActiveWitnessesCommand.php | 2 +- Commands/Single/GetApiByNameCommand.php | 12 ++ Commands/Single/GetBlockCommand.php | 11 ++ Commands/Single/GetBlockHeaderCommand.php | 11 ++ Commands/Single/GetContentCommand.php | 11 ++ Commands/Single/GetContentRepliesCommand.php | 11 ++ .../GetCurrentMedianHistoryPriceCommand.php | 5 +- ...etDiscussionsByAuthorBeforeDateCommand.php | 10 ++ .../Single/GetDiscussionsByBlogCommand.php | 10 ++ .../Single/GetDiscussionsByFeedCommand.php | 10 ++ .../GetDiscussionsByTrendingCommand.php | 10 ++ .../GetDynamicGlobalPropertiesCommand.php | 5 +- Commands/Single/GetOpsInBlock.php | 10 ++ .../Single/GetTrendingCategoriesCommand.php | 10 ++ .../{Login => Single}/GetVersionCommand.php | 2 +- Commands/Single/GetWitnessesByVoteCommand.php | 10 ++ Commands/{Login => Single}/LoginCommand.php | 11 +- README.md | 12 +- 41 files changed, 192 insertions(+), 472 deletions(-) delete mode 100644 Commands/DataBase/CommandInterface.php delete mode 100644 Commands/DataBase/GetAccountHistoryCommand.php delete mode 100644 Commands/DataBase/GetAccountVotesCommand.php delete mode 100644 Commands/DataBase/GetActiveVotesCommand.php delete mode 100644 Commands/DataBase/GetBlockCommand.php delete mode 100644 Commands/DataBase/GetBlockHeaderCommand.php delete mode 100644 Commands/DataBase/GetContentCommand.php delete mode 100644 Commands/DataBase/GetContentRepliesCommand.php delete mode 100644 Commands/DataBase/GetDiscussionsByAuthorBeforeDateCommand.php delete mode 100644 Commands/DataBase/GetDiscussionsByBlogCommand.php delete mode 100644 Commands/DataBase/GetDiscussionsByFeedCommand.php delete mode 100644 Commands/DataBase/GetDiscussionsByTrendingCommand.php delete mode 100644 Commands/DataBase/GetOpsInBlock.php delete mode 100644 Commands/DataBase/GetTrendingCategoriesCommand.php delete mode 100644 Commands/DataBase/GetWitnessesByVoteCommand.php delete mode 100644 Commands/Login/CommandAbstract.php delete mode 100644 Commands/Login/CommandInterface.php delete mode 100644 Commands/Login/GetApiByNameCommand.php rename Commands/{DataBase => Single}/GetAccountCountCommand.php (56%) create mode 100644 Commands/Single/GetAccountHistoryCommand.php create mode 100644 Commands/Single/GetAccountVotesCommand.php create mode 100644 Commands/Single/GetActiveVotesCommand.php rename Commands/{DataBase => Single}/GetActiveWitnessesCommand.php (72%) create mode 100644 Commands/Single/GetApiByNameCommand.php create mode 100644 Commands/Single/GetBlockCommand.php create mode 100644 Commands/Single/GetBlockHeaderCommand.php create mode 100644 Commands/Single/GetContentCommand.php create mode 100644 Commands/Single/GetContentRepliesCommand.php rename Commands/{DataBase => Single}/GetCurrentMedianHistoryPriceCommand.php (60%) create mode 100644 Commands/Single/GetDiscussionsByAuthorBeforeDateCommand.php create mode 100644 Commands/Single/GetDiscussionsByBlogCommand.php create mode 100644 Commands/Single/GetDiscussionsByFeedCommand.php create mode 100644 Commands/Single/GetDiscussionsByTrendingCommand.php rename Commands/{DataBase => Single}/GetDynamicGlobalPropertiesCommand.php (59%) create mode 100644 Commands/Single/GetOpsInBlock.php create mode 100644 Commands/Single/GetTrendingCategoriesCommand.php rename Commands/{Login => Single}/GetVersionCommand.php (69%) create mode 100644 Commands/Single/GetWitnessesByVoteCommand.php rename Commands/{Login => Single}/LoginCommand.php (53%) diff --git a/Commands/Commands.php b/Commands/Commands.php index 521d6a2..7c39c9c 100644 --- a/Commands/Commands.php +++ b/Commands/Commands.php @@ -7,9 +7,29 @@ use GrapheneNodeClient\Connectors\ConnectorInterface; /** - * @method Commands get_block() * @method Commands get_accounts() + * @method Commands get_account_count() + * @method Commands get_account_history() + * @method Commands get_account_votes() + * @method Commands get_active_votes() + * @method Commands get_active_witnesses() + * @method Commands get_api_by_name() ONLY for STEEM + * @method Commands get_block() + * @method Commands get_block_header() + * @method Commands get_content() + * @method Commands get_content_replies() + * @method Commands get_current_median_history_price() + * @method Commands get_discussions_by_author_before_date() + * @method Commands get_discussions_by_blog() * @method Commands get_discussions_by_created() + * @method Commands get_discussions_by_feed() + * @method Commands get_discussions_by_trending() + * @method Commands get_dynamic_global_properties() + * @method Commands get_ops_in_block() + * @method Commands get_trending_categories() + * @method Commands get_version() + * @method Commands get_witnesses_by_vote() + * @method Commands login() ONLY for STEEM */ class Commands implements CommandInterface { @@ -378,24 +398,11 @@ class Commands implements CommandInterface '3' => ['integer'], //limit ] ], - 'login' => [ - 'apiName' => 'login_api', - 'fields' => [ - 0 => ['string'], - 1 => ['string'] - ] - ], 'get_version' => [ 'apiName' => 'login_api', 'fields' => [ ] ], - 'get_api_by_name' => [ - 'apiName' => 'login_api', - 'fields' => [ - '0' => ['string'], //'api_name',for example follow_api, database_api, login_api and ect. - ] - ], 'broadcast_transaction' => [ 'apiName' => 'network_broadcast_api', 'fields' => [ diff --git a/Commands/DataBase/CommandInterface.php b/Commands/DataBase/CommandInterface.php deleted file mode 100644 index b8a1060..0000000 --- a/Commands/DataBase/CommandInterface.php +++ /dev/null @@ -1,20 +0,0 @@ - ['string'], //authors - '1' => ['integer'], //from - '2' => ['integer'], //limit max 2000 - ]; -} \ No newline at end of file diff --git a/Commands/DataBase/GetAccountVotesCommand.php b/Commands/DataBase/GetAccountVotesCommand.php deleted file mode 100644 index 2fe5324..0000000 --- a/Commands/DataBase/GetAccountVotesCommand.php +++ /dev/null @@ -1,16 +0,0 @@ - ['string'], //account name - ]; -} \ No newline at end of file diff --git a/Commands/DataBase/GetActiveVotesCommand.php b/Commands/DataBase/GetActiveVotesCommand.php deleted file mode 100644 index f63761e..0000000 --- a/Commands/DataBase/GetActiveVotesCommand.php +++ /dev/null @@ -1,17 +0,0 @@ - ['string'], //author - '1' => ['string'], //permlink - ]; -} \ No newline at end of file diff --git a/Commands/DataBase/GetBlockCommand.php b/Commands/DataBase/GetBlockCommand.php deleted file mode 100644 index 4ff0fbb..0000000 --- a/Commands/DataBase/GetBlockCommand.php +++ /dev/null @@ -1,16 +0,0 @@ - ['integer'], //block_id - ]; -} \ No newline at end of file diff --git a/Commands/DataBase/GetBlockHeaderCommand.php b/Commands/DataBase/GetBlockHeaderCommand.php deleted file mode 100644 index cf613b5..0000000 --- a/Commands/DataBase/GetBlockHeaderCommand.php +++ /dev/null @@ -1,16 +0,0 @@ - ['integer'], //block_id - ]; -} \ No newline at end of file diff --git a/Commands/DataBase/GetContentCommand.php b/Commands/DataBase/GetContentCommand.php deleted file mode 100644 index fdb0711..0000000 --- a/Commands/DataBase/GetContentCommand.php +++ /dev/null @@ -1,17 +0,0 @@ - ['string'], //author - '1' => ['string'], //permlink - ]; -} \ No newline at end of file diff --git a/Commands/DataBase/GetContentRepliesCommand.php b/Commands/DataBase/GetContentRepliesCommand.php deleted file mode 100644 index ebb0c8f..0000000 --- a/Commands/DataBase/GetContentRepliesCommand.php +++ /dev/null @@ -1,17 +0,0 @@ - ['string'], //author - '1' => ['string'], //permlink - ]; -} \ No newline at end of file diff --git a/Commands/DataBase/GetDiscussionsByAuthorBeforeDateCommand.php b/Commands/DataBase/GetDiscussionsByAuthorBeforeDateCommand.php deleted file mode 100644 index 295c4ce..0000000 --- a/Commands/DataBase/GetDiscussionsByAuthorBeforeDateCommand.php +++ /dev/null @@ -1,16 +0,0 @@ - ['string'], //'author', - '1' => ['string'], //'start_permlink' for pagination, - '2' => ['string'], //'before_date' - '3' => ['integer'], //'limit' - ]; -} \ No newline at end of file diff --git a/Commands/DataBase/GetDiscussionsByBlogCommand.php b/Commands/DataBase/GetDiscussionsByBlogCommand.php deleted file mode 100644 index 4301493..0000000 --- a/Commands/DataBase/GetDiscussionsByBlogCommand.php +++ /dev/null @@ -1,30 +0,0 @@ - [ - '*: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 => [ - '*:tag' => ['string'], //'author', - '*:limit' => ['integer'], //'limit' - '*:start_author' => ['nullOrString'], //'start_author' for pagination, - '*:start_permlink' => ['nullOrString'] //'start_permlink' for pagination, - ] - ]; -} \ No newline at end of file diff --git a/Commands/DataBase/GetDiscussionsByFeedCommand.php b/Commands/DataBase/GetDiscussionsByFeedCommand.php deleted file mode 100644 index 94b8593..0000000 --- a/Commands/DataBase/GetDiscussionsByFeedCommand.php +++ /dev/null @@ -1,30 +0,0 @@ - [ - '*: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 => [ - '*:tag' => ['string'], //'author', - '*:limit' => ['integer'], //'limit' - '*:start_author' => ['nullOrString'], //'start_author' for pagination, - '*:start_permlink' => ['nullOrString'] //'start_permlink' for pagination, - ] - ]; -} \ No newline at end of file diff --git a/Commands/DataBase/GetDiscussionsByTrendingCommand.php b/Commands/DataBase/GetDiscussionsByTrendingCommand.php deleted file mode 100644 index a72b666..0000000 --- a/Commands/DataBase/GetDiscussionsByTrendingCommand.php +++ /dev/null @@ -1,30 +0,0 @@ - [ - '*: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 => [ - '*:tag' => ['nullOrString'], //'author', - '*:limit' => ['integer'], //'limit' - '*:start_author' => ['nullOrString'], //'start_author' for pagination, - '*:start_permlink' => ['nullOrString'] //'start_permlink' for pagination, - ] - ]; -} \ No newline at end of file diff --git a/Commands/DataBase/GetOpsInBlock.php b/Commands/DataBase/GetOpsInBlock.php deleted file mode 100644 index 3417802..0000000 --- a/Commands/DataBase/GetOpsInBlock.php +++ /dev/null @@ -1,16 +0,0 @@ - ['integer'], //blockNum - '1' => ['bool'], //onlyVirtual - ]; -} \ No newline at end of file diff --git a/Commands/DataBase/GetTrendingCategoriesCommand.php b/Commands/DataBase/GetTrendingCategoriesCommand.php deleted file mode 100644 index d94f75d..0000000 --- a/Commands/DataBase/GetTrendingCategoriesCommand.php +++ /dev/null @@ -1,14 +0,0 @@ - ['nullOrString'], //after - '1' => ['integer'], //permlink - ]; -} \ No newline at end of file diff --git a/Commands/DataBase/GetWitnessesByVoteCommand.php b/Commands/DataBase/GetWitnessesByVoteCommand.php deleted file mode 100644 index 74eefd9..0000000 --- a/Commands/DataBase/GetWitnessesByVoteCommand.php +++ /dev/null @@ -1,14 +0,0 @@ - ['string'], //from accountName, can be empty string '' - '1' => ['integer'] //limit - ]; -} \ No newline at end of file diff --git a/Commands/Login/CommandAbstract.php b/Commands/Login/CommandAbstract.php deleted file mode 100644 index 0e81432..0000000 --- a/Commands/Login/CommandAbstract.php +++ /dev/null @@ -1,108 +0,0 @@ -connector = $connector; - } - - /** - * @param CommandQueryDataInterface $commandQueryData - * @param string $answerFormat - * @param string $getElementWithKey If you want to get only certain element from answer. - * Example: 'key:123:qwe' => $array['key']['123']['qwe'] or $object->key->123->qwe - * @return array|object - */ - public function execute(CommandQueryDataInterface $commandQueryData, $getElementWithKey = null, $answerFormat = ConnectorInterface::ANSWER_FORMAT_ARRAY) - { - /** @var CommandQueryData $commandQueryData */ - $params = $commandQueryData->prepareData($this->getQueryDataMap()); - - $answer = $this->doRequest($params, $answerFormat); - - $defaultValue = $answerFormat === ConnectorInterface::ANSWER_FORMAT_ARRAY ? [] : ((object)[]); - - return $this->getElementByKey($answer, $getElementWithKey, $defaultValue); - } - - - /** - * @return array|mixed - */ - public function getQueryDataMap() - { - return isset($this->queryDataMap[$this->connector->getPlatform()]) - ? $this->queryDataMap[$this->connector->getPlatform()] - : $this->queryDataMap; - } - - /** - * @param array $params - * @param string $answerFormat - * @return array|object - */ - protected function doRequest($params, $answerFormat = ConnectorInterface::ANSWER_FORMAT_ARRAY) - { - $data = [ - 'method' => $this->method, - 'params' => $params - ]; - - return $this->connector->doRequest($this->apiName, $data, $answerFormat); - } - - - /** - * get all values or vulue by key - * - * Example: 'key:123:qwe' => $array['key']['123']['qwe'] or $object->key->123->qwe - * - * @param null|string $getKey - * @param null|mixed $default - * @param array|object $array - * - * @return mixed - */ - protected function getElementByKey($array, $getKey = null, $default = null) - { - $data = $array; - if ($getKey) { - $keyParts = explode(':', $getKey); - foreach ($keyParts as $key) { - if (is_array($data) && isset($data[$key])) { - $data = $data[$key]; - } elseif (is_object($data) && isset($data->$key)) { - $data = $data->$key; - } else { - $data = null; - break; - } - } - } - - if ($data === null) { - $data = $default; - } - - return $data; - } -} \ No newline at end of file diff --git a/Commands/Login/CommandInterface.php b/Commands/Login/CommandInterface.php deleted file mode 100644 index 3f96cf0..0000000 --- a/Commands/Login/CommandInterface.php +++ /dev/null @@ -1,20 +0,0 @@ - ['string'], //'api_name',for example follow_api, database_api, login_api and ect. - ]; -} \ No newline at end of file diff --git a/Commands/DataBase/GetAccountCountCommand.php b/Commands/Single/GetAccountCountCommand.php similarity index 56% rename from Commands/DataBase/GetAccountCountCommand.php rename to Commands/Single/GetAccountCountCommand.php index 9100b69..db3126e 100644 --- a/Commands/DataBase/GetAccountCountCommand.php +++ b/Commands/Single/GetAccountCountCommand.php @@ -1,14 +1,11 @@ ['string'], - 1 => ['string'] - ]; } \ No newline at end of file diff --git a/README.md b/README.md index d9974ce..f2b1011 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ install extensions execute( namespace: - GrapheneNodeClient\Commands\Broadcast; -- GrapheneNodeClient\Commands\DataBase; +- GrapheneNodeClient\Commands\Single; - GrapheneNodeClient\Commands\Follow; - GrapheneNodeClient\Commands\Login; @@ -115,9 +115,7 @@ namespace: - GetTrendingCategoriesCommand ### login_api -- GetApiByNameCommand - GetVersionCommand -- LoginCommand ### follow_api @@ -180,7 +178,7 @@ switch between connectors