GithubHelp home page GithubHelp logo

aeneria / enedis-data-connect Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 89 KB

[Gitlab mirror] A small library to use a part of Enedis Data Connect API with PHP : https://datahub-enedis.fr/data-connect

Home Page: https://gitlab.com/aeneria/enedis-data-connect/

License: MIT License

PHP 100.00%
php linky enedis

enedis-data-connect's Introduction

Enedis Data Connect API: a small library to use a part of Enedis Data Connect API with PHP

Firstly developped to be used in aeneria, this small library let you use easily Enedis Data Connect API.

Requirements

PHP 8.1 or higher

Getting started

First of all, you will need a ClientID and a ClientSecret to use Enedis Data Connect API. Visit https://datahub-enedis.fr/data-connect, to know how to get ones. During your registration you will also give a redirect URL, you will need it touse this library.

Now that you have those, install the library with composer:

composer require aeneria/enedis-data-connect

If you are using a framework such as Symfony, you can declare the library as a service and use it with dependency injection:

# config/services.yaml

services:
    Aeneria\EnedisDataConnectApi\Service\DataConnectService:
        class: Aeneria\EnedisDataConnectApi\Service\DataConnectService
        arguments:
            $httpClient: "@http_client"
            $authEndpoint: "https://mon-compte-particulier.enedis.fr"
            $tokenEndpoint: "https://gw.prd.api.enedis.fr "
            $dataEndpoint: "https://gw.prd.api.enedis.fr"
            $clientId: "YOUR_CLIENT_ID"
            $clientSecret: "YOUR_CLIENT_SECRET"
            $redirectUri: "YOUR_REDIRECT_URI"

Or you can declare it in your code this way:

<?php

use Aeneria\EnedisDataConnectApi\Service\DataConnectService;

//...

$dataConnect = new DataConnectService(
    HttpClient::create(),
    "https://mon-compte-particulier.enedis.fr",
    "https://gw.prd.api.enedis.fr "
    "https://gw.prd.api.enedis.fr",
    "YOUR_CLIENT_ID",
    "YOUR_CLIENT_SECRET",
    "YOUR_REDIRECT_URI
);

//...

Then you can use the API:

<?php

// Getting consent page URL
$dataConnect->getAuthorizeV1Service()->getConsentPageUrl('P6M', $state);

// Getting Tokens form Code
$token = $dataConnect->getAuthorizeV1Service()->requestAuthorizationToken();

// Getting consumption data
$meteringData = $dataConnect->getMeteringDataV5Service()->requestDailyConsumption(
    $token->getAccessToken(),
    $token->getUsagePointsId(),
    new \DateTimeImmutable('8 days ago'),
    new \DateTimeImmutable('yesterday')
);
$meteringData = $dataConnect->getMeteringDataV5Service()->requestConsumptionLoadCurve(
    $token->getAccessToken(),
    $token->getUsagePointsId(),
    new \DateTimeImmutable('2 days ago'),
    new \DateTimeImmutable('yesterday')
);

// Getting customer data
$address = $dataConnect->getCustomersV5Service()->requestUsagePointAdresse(
    $token->getAccessToken(),
    $token->getUsagePointsId()
);

Support

Feel free to open an issue!

enedis-data-connect's People

Contributors

simonmellerin avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

tomours

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.