lennord / floriday-sdk
This is a sdk for floriday
Requires
- php: ^8.4
- illuminate/contracts: ^11.0||^12.0||^13.0
- saloonphp/saloon: 4.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.8
- orchestra/testbench: ^11.0.0||^10.0.0||^9.0.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpunit/phpunit: ^12.0
- spatie/laravel-ray: ^1.35
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A Saloon-powered SDK for integrating with the Floriday platform from Laravel/PHP. It provides a small Saloon Connector plus Resources for common Floriday API endpoints (Token, Trade Items, Identities, Warehouses, Batches). The connector takes care of base URL, default headers, bearer auth, and consistent error handling.
What is Saloon? Saloon is a modern, type-safe PHP HTTP client. This package builds on Saloon 4 and follows its Connector/Request/Resource patterns so you can use the SDK exactly like any other Saloon integration.
Requirements
- PHP ^8.4
- Laravel 11/12/13 (package is compatible with Illuminate Contracts)
Installation
Install via Composer:
composer require lennord/floriday-sdk
Publish the config file (optional, but recommended):
php artisan vendor:publish --tag="floriday-sdk-config"
Configuration
This package reads its settings from config/floriday-sdk.php, which in turn can be fed by environment variables:
return [ 'base_url' => env('FLORIDAY_API_URL', ''), 'oauth_url' => env('FLORIDAY_API_OAUTH_URL', ''), 'client' => env('FLORIDAY_API_CLIENT_ID', ''), 'secret' => env('FLORIDAY_API_CLIENT_SECRET', ''), 'scope' => env('FLORIDAY_API_SCOPE', ''), ];
Set these in your .env:
FLORIDAY_API_URL=https://api.floriday.io
FLORIDAY_API_OAUTH_URL=https://login.floriday.io/oauth/token
FLORIDAY_API_CLIENT_ID=your-client-id
FLORIDAY_API_CLIENT_SECRET=your-client-secret
FLORIDAY_API_SCOPE=your-scope
Using the SDK with Saloon
The main entry point is the Saloon Connector Lennord\FloridaySdk\FloridayConnector. It exposes Resources for each endpoint:
- token():
Lennord\FloridaySdk\Resources\TokenResource - identity():
Lennord\FloridaySdk\Resources\IdentitiesResource - trade():
Lennord\FloridaySdk\Resources\TradeItemResource - warehouse():
Lennord\FloridaySdk\Resources\WarehouseResource - batch():
Lennord\FloridaySdk\Resources\BatchResource
Authentication:
- The connector ships with a trait
HasAuthTokenwhich will automatically fetch an access token using the Token endpoint and cache it in Laravel Cache. To send an authenticated request, callwithAuthorization()on the connector beforesend()is executed. The resources in this SDK do that for you under the hood. - Floriday also requires an
X-Api-Keyheader for some endpoints. You can set it viawithApiKey('your-api-key')on any resource before calling the method.
Resolve the connector (Laravel container)
use Lennord\FloridaySdk\FloridayConnector; $floriday = app(FloridayConnector::class);
Or use the provided Facade:
use Lennord\FloridaySdk\Facades\Floriday as FloridayFacade; // Example: FloridayFacade::identity()->get()->json();
Get an OAuth token (Saloon Response)
use Lennord\FloridaySdk\FloridayConnector; $floriday = app(FloridayConnector::class); $response = $floriday->token()->get(); $token = $response->json('access_token');
Identities
$identity = $floriday->identity()->get()->json();
Trade items
$items = $floriday->trade()->index()->json();
Warehouses (optionally exclude external)
$warehouses = $floriday->warehouse()->index(excludeExternal: true)->json();
Batches (create)
$payload = [ // ... batch fields ... ]; $batch = $floriday->batch()->withApiKey('your-api-key')->create($payload)->json();
Notes on headers & auth:
- Default headers include
Accept: application/jsonandContent-Type: application/json. withAuthorization()is applied within each resource method so you generally don’t need to call it yourself.- If you need to set the
X-Api-Keyheader globally for a workflow, you can callwithApiKey()once on any resource before making multiple calls; it adds the header to the underlying connector for subsequent requests in the same instance.
Error handling (Saloon)
This connector uses Saloon’s AlwaysThrowOnErrors plugin, which throws exceptions for 4xx/5xx responses. Catch Saloon’s request exceptions when needed, for example:
use Saloon\Exceptions\Request\RequestException; try { $items = $floriday->trade()->index()->json(); } catch (RequestException $e) { // Inspect $e->getResponse() if needed }
Testing
This project uses PHPUnit.
- Run tests:
composer test
- Run with coverage (requires Xdebug or PCOV):
composer test-coverage
If you see “No code coverage driver is available”, enable Xdebug (xdebug.mode=coverage) or PCOV in your PHP CLI.
Changelog
Please see CHANGELOG for recent changes.
Security
If you discover any security related issues, please open an issue or contact the maintainer directly.
License
The MIT License (MIT). Please see LICENSE.md for details.