soved/laravel-ecologi

Help restore the planet using the Ecologi API

v1.1.0 2022-02-10 07:32 UTC

This package is auto-updated.

Last update: 2024-04-10 12:35:11 UTC


README

tests

Requirements

  • PHP >= 8.0
  • Laravel >= 8.0

Installation

First, install the package via the Composer package manager:

$ composer require soved/laravel-ecologi

After installing the package, you should publish the configuration file:

$ php artisan vendor:publish --tag=ecologi-config

Configuration

Create a business or impact-only account. Obtain a API token here. Add the API token to your environment variables:

ECOLOGI_TOKEN=91757e14-3772-41a1-8020-cf434805b64e

Usage

Track your impact

<?php

use Soved\Laravel\Ecologi\Contracts\EcologiContract;

$ecologi = $this->app->make(EcologiContract::class);

$impact = $ecologi->getImpact('sander');

// ['trees' => 29, 'carbonOffset' => 16.883]

$treesPlanted = $ecologi->getTrees('sander');

// 29

$carbonOffset = $ecologi->getCarbonOffset('sander');

// 16.883

🌳 Purchase trees or carbon offset

<?php

use Soved\Laravel\Ecologi\Contracts\EcologiContract;

$ecologi = $this->app->make(EcologiContract::class);

$ecologi->purchaseTrees(5);

$ecologi->purchaseCarbonOffset(1, 'Tonnes');

You could also schedule one of the following jobs: PurchaseATree, PurchaseCarbonOffset(quantity: 1000, 'KG') or PurchaseTrees(quantity: 5)

<?php

// App\Console\Kernel:

use Illuminate\Console\Scheduling\Schedule;
use Soved\Laravel\Ecologi\Jobs\PurchaseATree;

protected function schedule(Schedule $schedule)
{
    $schedule->job(new PurchaseATree)->daily();
}

Security Vulnerabilities

If you discover a security vulnerability within this project, please send an e-mail to Sander de Vos via sander@tutanota.de. All security vulnerabilities will be promptly addressed.