1. Go to this page and download the library: Download laravel-enso/api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
laravel-enso / api example snippets
use LaravelEnso\Api\Contracts\Endpoint;
use LaravelEnso\Api\Enums\Method;
class FetchOffers implements Endpoint
{
private array $filters = [];
public function method(): Method
{
return Method::GET;
}
public function url(): string
{
return 'https://posf.ro/api/v1/comparator';
}
public function filters(array $filters): self
{
$this->filters = $filters;
return $this;
}
public function body(): array
{
return $this->filters;
}
}
use LaravelEnso\Api\Action;
class FetchOffersAction extends Action
{
public function __construct(private array $filters)
{
}
protected function endpoint(): Endpoint
{
return (new FetchOffers())->filters($this->filters);
}
}
$response = (new FetchOffersAction([
'request' => 'comparator-electric',
'tip_client' => 'casnic',
]))->handle();
$payload = $response->json();
use LaravelEnso\Api\Endpoints\Soap;
class SubmitInvoice extends Soap
{
public function __construct(private Invoice $invoice)
{
}
public function wsdl(): ?string
{
return config('services.invoices.wsdl');
}
public function operation(): string
{
return 'SubmitInvoice';
}
public function arguments(): array
{
return [[
'number' => $this->invoice->number,
'total' => $this->invoice->total,
]];
}
public function options(): array
{
return [
'trace' => true,
'exceptions' => true,
'connection_timeout' => 30,
];
}
}
use LaravelEnso\Api\Action;
use LaravelEnso\Api\Contracts\Endpoint;
class SubmitInvoiceAction extends Action
{
public function __construct(private Invoice $invoice)
{
}
protected function endpoint(): Endpoint
{
return new SubmitInvoice($this->invoice);
}
}
$response = (new SubmitInvoiceAction($invoice))->handle();
$result = $response->body();
use LaravelEnso\Api\Resource;
class OfferResource extends Resource
{
public function __construct(private array $offer)
{
}
public function toArray(): array
{
return [
'id' => $this->offer['id'],
'supplier' => $this->offer['supplier'],
];
}
protected function mandatoryAttributes(): array
{
return ['id', 'supplier'];
}
}
use LaravelEnso\Api\Filter;
class OfferFilters extends Filter
{
public function allowed(): array
{
return ['request', 'tip_client', 'consum_lunar'];
}
}
$filters = (new OfferFilters($input))->toArray();