markmorgan / octopus-energy
Octopus Energy PHP SDK
0.9.0
2022-02-08 13:14 UTC
Requires
- php: >=7.1
- guzzlehttp/guzzle: ^6.5
Requires (Dev)
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2024-09-08 20:07:45 UTC
README
这些PHP绑定提供了对Octopus Energy Restful API的方便访问,适用于PHP应用程序。
注意:由于账户和报价端点仅对合作伙伴组织可用,因此在此SDK中未实现这些端点。
需求
- Octopus Energy账户API密钥(https://octopus.energy/dashboard/developer/)
- PHP >= 7.1
安装
使用composer安装
composer require markmorgan/octopus-energy
用法
初始化
在请求数据之前,您需要设置访问凭证。这是通过初始化OctopusEnergy客户端来完成的。
$apiKey = 'my-octopus-apikey'; $client = new \OctopusEnergy\Client($apiKey);
服务
SDK为Product
、Meter
和Industry
功能提供服务。查找所有可用的函数的最佳位置是在服务本身内部。
产品
获取所有产品(提供额外的产品过滤器,请参阅函数签名)
$productsSearch = $client->products->all();
根据产品代码获取特定产品
$productCode = 'VAR-21-09-29'; $product = $client->products->get($productCode);
电表
获取特定电表的信息
$mpan = 'YOUR MPAN NUMBER'; $meter = $client->meters->getElectricityMeter($mpan);
获取电表消耗
$mpan = 'YOUR MPAN NUMBER'; $serialNumber = 'YOUR METER SERIAL NUMBER'; $consumptionSearch = $client->meters->getElectricityMeterConsumption( $mpan, $serialNumber );
筛选特定日期之间的消耗
$fromDate = new \DateTime(); $fromDate->setTimestamp(1640995201); // Jan 1st 2022 $toDate = new \DateTime(); $toDate->setTimestamp(1643673601); // Feb 1st 2022 $pageNumber = 1; $consumptionSearch = $client->meters->getElectricityMeterConsumption( $mpan, $serialNumber, $pageNumber, $fromDate, $toDate );
行业
获取关于电网供应点的信息
// fetch all grid supply point info $gspSearch = $client->industry->getGridSupplyPoints(); // fetch grid supply point info for a postcode $postcode = 'cf104uw'; $gspSearch = $client->industry->getGridSupplyPoints($postcode);
测试
您可以通过运行composer install然后运行phpunit来运行PHPUnit对库进行测试。在此之前,您需要将example.phpunit.xml复制到phpunit.xml,并更改API和电表详情的环境变量。