xvilo / greenchoice
Greenchoice API client
0.4.0
2020-06-30 07:43 UTC
Requires
- php: ^7.4
- php-http/cache-plugin: ^1.4
- php-http/client-common: ^1.6 || ^2.0
- php-http/client-implementation: ^1.0
- php-http/discovery: ^1.0
- php-http/httplug: ^1.1 || ^2.0
- psr/cache: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- cache/array-adapter: ^0.4
- friendsofphp/php-cs-fixer: ^2.16
- guzzlehttp/psr7: ^1.2
- php-http/guzzle6-adapter: ^1.0 || ^2.0
- php-http/mock-client: ^1.2
- phpunit/phpunit: ^7.0 || ^8.0
This package is auto-updated.
Last update: 2025-05-29 01:25:43 UTC
README
A Greenchoice API Wrapper, please note that there is currently no official public API. However, this API client has been made by inspecting network traffic from their app.
Installation
You can install this package through composer, the easiest way is to:
composer require xvilo/greenchoice
Usage
Somme usage examples:
<?php declare(strict_types=1); use Greenchoice\HttpClient\Plugin\Authentication\GrantType\Password; require_once 'vendor/autoload.php'; $client = new Greenchoice\Client(); $clientToken = $client->authentication->requestToken( 'MobileApp', 'A6E60EBF73521F57', 'xxxxx-xxx-xxx-xxxx-xxxxxxxxxx', new Password(), 'you@example.com', 'S0mes3c#password' ); // Authenticate $client->authenticate($clientToken['access_token']); // Get contracts $contracts = $client->customer->getContracts(); if (count($contracts) === 0) { die('No contracts found for this customer'); } $contractId = $contracts[0]['Id']; $customerId = $contracts[0]['Klantnummer']; echo sprintf("Using contract[ID=%s] for customer[ID=%s]", $contractId, $customerId) . PHP_EOL; // Get approved contract $approvedContract = $client->contracts->getApproved($contractId); echo sprintf("Contract[ID=%s] has %s approved contract(s)", $contractId, count($approvedContract)) . PHP_EOL; // Get contract features $contractFeatures = $client->features->getByContractId($contractId); echo sprintf("Contract[ID=%s] has %s contract feature(s)", $contractId, count($contractFeatures)) . PHP_EOL; // Get contract counters $contractCounters = $client->readings->getCounters($contractId); echo sprintf("For contract[ID=%s] there is %s registered meter(s)", $contractId, count($contractCounters)) . PHP_EOL; // get contract readings $contractReadings = $client->readings->getCounterData($contractId); echo sprintf("Last known meter readings since: \n\n - %s:\n - high: %s\n - low: %s", $contractReadings[0]['DatumInvoer'], $contractReadings[0]['MeterstandenOutput'][0]['Hoog'], $contractReadings[0]['MeterstandenOutput'][0]['Laag']) . PHP_EOL;
Will output:
Using contract[ID=1234567] for customer[ID=67890] Contract[ID=1234567] has 0 approved contract(s) Contract[ID=1234567] has 4 contract feature(s) For contract[ID=1234567] there is 1 registered meter(s) Last known meter readings since: - 2020-06-15T00:00:00: - high: 123456 - low: 1234