rickkuilman / digital-humani-php-sdk
用于DigitalHumani的RaaS(植树服务)的PHP SDK
v2.0.0
2021-10-23 14:06 UTC
Requires
- php: ^7.4|^8.0
- ext-json: *
- guzzlehttp/guzzle: ^6.3.1|^7.0
- nesbot/carbon: ^2.53
Requires (Dev)
- mockery/mockery: ^1.3.1
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-11 19:38:44 UTC
README
非官方的DigitalHumani的RaaS(植树服务)PHP SDK
安装
您可以通过composer安装此包
composer require rickkuilman/digital-humani-php-sdk
准备
基本用法
// Create new sandbox instance $digitalHumani = new DigitalHumani($apiKey, $enterpriseId); // Plant a tree $digitalHumani->plantTree('rick@example.com'); // Count trees planted $digitalHumani->treeCount();
使用DigitalHumani实例,您可以执行多个操作,并获取DigitalHumani的API提供的不同资源
管理企业
// Get current Enterprise $enterprise = $digitalHumani->enterprise(); // .. or get Enterprise by ID $enterprise = $digitalHumani->enterprise('4c6e672d'); // 🌳 Count planted trees $enterprise->treeCount(); // 🌳 Count planted trees since 2021-01-01 $enterprise->treeCount(Carbon::make('2021-01-01')); // 🌳 Count planted trees between 2021-01-01 and 2021-08-01 $enterprise->treeCount(Carbon::make('2021-01-01'), Carbon::make('2022-08-01')); // 🌳 Count planted trees for specific month $enterprise->treeCountForMonth(Carbon::make('2021-08')); // 🌳 Plant tree $enterprise->plantTree('rick@example.com')
注意带有🌳图标的行
由于企业ID在DigitalHumani实例中可用,您可以替换
$enterprise为$digitalHumani并期待相同的结果。
管理项目
// Get list of all Projects $projects = $digitalHumani->projects(); // Get second project $project = $projects[1]; // .. or get Project by ID $project = $digitalHumani->project('81818182'); // Plant a tree for this project $project->plantTree('rick@example.com', 3);
管理树木
// Plant one tree $tree = $digitalHumani->plantTree('rick@example.com'); // Plant ten trees $trees = $digitalHumani->plantTree('rick@example.com', 10); // Get UUID of tree(s) $uuid = $tree->uuid; // Get details of a planted tree (or trees) by ID $digitalHumani->tree('9f05511e-56c6-40f7-b5ca-e25567991dc1'); // Count trees for a user $digitalHumani->countTreesPlantedByUser('rick@example.com');
切换到生产环境
// Set the third parameter to "true" $digitalHumani = new DigitalHumani($apiKey, $enterpriseId, true); // ..or use a method $digitalHumani->useProductionEnvironment();
覆盖(默认)项目或企业
许多方法允许使用附加参数来覆盖(默认)项目或企业
// Create new sandbox instance, leaving out the enterpriseId $digitalHumani = new DigitalHumani($apiKey); // Plant a tree for a specific project and enterprise $digitalHumani->plantTree('rick@example.com', 1, $projectId, $enterpriseId); // Set a default enterprise afterwards, which will be used for all requests from now on $digitalHumani->setEnterprise('11111111'); // Plant a tree for a specific project using the default enterprise from above $digitalHumani->plantTree('rick@example.com', 1, $projectId); // Count trees of a specific month for a specific enterprise, overruling the default $digitalHumani->treeCountForMonth(Carbon::make('2021-10'), '99999999');
快乐的种植!🌳
变更日志
请参阅CHANGELOG了解最近更改的详细信息。
贡献
请参阅CONTRIBUTING了解详细信息。
安全
如果您发现任何与安全相关的问题,请通过电子邮件rickkuilman@gmail.com联系,而不是使用问题跟踪器。
鸣谢
许可证
MIT许可证(MIT)。请参阅许可证文件了解更多信息。
PHP包模板
此包是使用PHP包模板生成的,由Beyond Code提供。