imamnc/efihub-client

Laravel client for EFIHUB Integration Service

Installs: 230

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/imamnc/efihub-client

v1.2.1 2025-10-29 14:32 UTC

This package is auto-updated.

Last update: 2025-10-29 14:43:18 UTC


README

EFIHUB

EFIHUB PHP/Laravel Client

A modern SDK to integrate with the EFIHUB platform using the OAuth 2.0 Client Credentials flow.

packagist version license author

Introduction

EFIHUB client for Laravel/PHP that authenticates using OAuth 2.0 Client Credentials and exposes:

  • A lightweight HTTP client (GET/POST/PUT/DELETE) with automatic token caching and retry on 401
  • Storage module to upload files and get public URLs
  • Websocket module to dispatch real-time events to channels

Designed for server-side apps only—do not expose your client secret to browsers.

Installation

  1. Install the package
composer require imamnc/efihub-client
  1. Publish config (optional; auto-discovery is enabled)
php artisan vendor:publish --provider="Efihub\EfihubServiceProvider" --tag=config
  1. Configure environment
EFIHUB_CLIENT_ID=your_client_id
EFIHUB_CLIENT_SECRET=your_client_secret
EFIHUB_TOKEN_URL=https://efihub.morefurniture.id/oauth/token
EFIHUB_API_URL=https://efihub.morefurniture.id/api

Authentication

  • Uses OAuth 2.0 Client Credentials to obtain an access token from EFIHUB_TOKEN_URL
  • Token is cached ~55 minutes; on 401, the client clears the cache and retries once
  • Config file: config/efihub.php (keys: client_id, client_secret, token_url, api_base_url)

Http client module

Use the Facade for simple calls or inject Efihub\EfihubClient.

use Efihub\Facades\Efihub;

// GET with query params
$res = Efihub::get('/user', ['page' => 1]);

// POST JSON
$res = Efihub::post('/orders', ['sku' => 'ABC', 'qty' => 2]);

// PUT
$res = Efihub::put('/orders/123', ['qty' => 3]);

// DELETE
$res = Efihub::delete('/orders/123');

if ($res->successful()) {
    $data = $res->json();
}

Dependency Injection example:

use Efihub\EfihubClient;

class UserService
{
    public function __construct(private EfihubClient $efihub) {}

    public function list(): array
    {
        $res = $this->efihub->get('/user');
        return $res->successful() ? $res->json() : [];
    }
}

Storage module

Common Laravel use case: upload an UploadedFile and get its public URL.

use Illuminate\Http\Request;
use Efihub\Facades\Efihub;

class MediaController
{
    public function store(Request $request)
    {
        $request->validate([
            'file' => ['required', 'file', 'max:10240'], // 10MB
        ]);

        $uploadedFile = $request->file('file'); // Illuminate\Http\UploadedFile

        // Upload to a folder; end with '/' to auto-generate a filename on server
        $url = Efihub::storage()->upload($uploadedFile, 'uploads/'.date('Y/m/d').'/');

        if ($url === false) {
            return back()->withErrors('Upload failed');
        }

        return back()->with('url', $url);
    }
}

Other helpers:

Efihub::storage()->exists('uploads/photo.jpg'); // bool
Efihub::storage()->size('uploads/photo.jpg');   // int|null (bytes)
Efihub::storage()->delete('uploads/photo.jpg'); // bool

Notes:

  • upload() accepts Laravel/Symfony UploadedFile, string path, or raw contents
  • Endpoints used: GET /storage/url|size|exists, POST /storage/upload, DELETE /storage/delete

Websocket module

Dispatch real-time events to channels (e.g. from a listener or job):

use Efihub\Facades\Efihub;

$ok = Efihub::socket()->dispatch(
    channel: 'orders:updates',
    event: 'OrderUpdated',
    data: ['order_id' => 123, 'status' => 'updated']
);

if (!$ok) {
    // handle failure (log, retry, etc.)
}

Endpoint used: POST /api/websocket/dispatch with JSON { channel, event, data }.

License & Author

MIT © Imam Nurcholis. See LICENSE.