coreto/coreto-rcs-sdk
Composer 安装命令:
composer require coreto/coreto-rcs-sdk
包简介
An SDK used for the collection and validation of the KPIs used in the Coreto DRS
README 文档
README
An SDK used for the collection and validation of the KPIs used in the Coreto DRS
Dependencies
- PHP >=7.4
Installation via Composer
To install simply run:
composer require coreto/coreto-rcs-sdk
Or add it to composer.json manually:
{
"require": {
"coreto/coreto-rcs-sdk": "~1"
}
}
Direct usage
use Coreto\CoretoRCSSDK\Client; $reputationCollectionClient = new Client( [ 'react' => null, // Key-value pairs of allowed action and allowed fluctuation for that action 'comment' => 2, 'opinion' => 4 ] ); $reputationCollectionClient->validate([ 'account_did' => 'did:example:example1', // The account DID 'action_date' => 1669121362000, // The unix timestamp in ms of the action 'action_type' => 'react', // The action type (must be one of the allowed types) 'trust' => 1, // The trust value (must be less than the score fluctuation if one is set) 'performance' => 0.3, // The performance value (must be less than the score fluctuation if one is set) 'identifier' => 123 // The identifier of the action (can be used if actions are first cached and then sent to the ledger in order to validate the sync) ]);
Errors
// Initialization exception try { $reputationCollectionClient = new Client( [] ); } catch (Exception $e) { // Action whitelist cannot be empty } // Score fluctuation error $reputationCollectionClient = new Client( [ 'react' => 1 ] ); try { $reputationCollectionClient->validate([ 'account_did' => 'did:example:example1', 'action_date' => 1669121362000, 'action_type' => 'react', 'trust' => 5, 'performance' => 0.3, 'identifier' => 123 ]); } catch (Coreto\Coreto\CoretoReputationCollectionSDK\InvalidScoreChangeException $e) { // Scores cannot fluctuate more than the amount set on initialization } // Invalid action type error $reputationCollectionClient = new Client( [ 'react' => null, 'comment' => 2, 'opinion' => 4 ] ); try { $reputationCollectionClient->validate([ 'account_did' => 'did:example:example1', 'action_date' => 1669121362000, 'action_type' => 'create', 'trust' => 0, 'performance' => 0.3, 'identifier' => 123 ]); } catch (Coreto\Coreto\CoretoReputationCollectionSDK\InvalidActionException $e) { // Action type is not in the whitelist } // Invalid action schema error try { $reputationCollectionClient->validate([ // 'account_did' => 'did:example:example1', 'action_date' => 1669121362000, 'action_type' => 'react', 'trust' => 0, 'performance' => 0.3, 'identifier' => 123 ]); } catch (Coreto\Coreto\CoretoReputationCollectionSDK\InvalidActionSchemaException $e) { // Action type is not in the whitelist }
Todo
- Add unit and integration tests
- Update documentation
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-14