About the package
The package is not finished yet however will be maintained and developed continuously as our primary project which requires this extension will.
Naming conventions
At some point the official Unas naming convention is not that good or does not exist at all. However the package is not trying to introduce custom naming conventions it will use the official property and attribute names as they are described in the documentation.
The following table contains the related API endpoints. All the endpoints will be supported soon.
Endpoint | Support |
---|---|
getProduct | ✔️ |
setProduct | ❌ |
getOrder | ❌ |
setOrder | ❌ |
getStock | ❌ |
setStock | ❌ |
getCategory | ❌ |
setCategory | ❌ |
getNewsletter | ❌ |
setNewsletter | ❌ |
Will fire an event each time an endpoint is being exhausted based on the given configuration.
- php >= 7.2
- ext-xmlwriter
- ext-simplexml
composer require szunisoft/laravel-unas
>= 5.5
Export the configuration
php artisan vendor:publish --provider="SzuniSoft/Unas/Laravel/UnasServiceProvider" --tag=config
Two authentication drivers are supported.
You must set the driver to legacy.
For legacy authentication you will need the following credentials:
- username
- password
- shop_id
- auth_code
You must set the driver to key.
In case of key authentication you will need to generate an API key inside the Unas portal.
Some kind of exceptions can be turned into events rather than throwing them. This is just a code architectural decision how a particular circumstance should be handled.
For instance we create a multi-tenancy project which will handle tons of different clients traffic behind the scenes. It is more wise to consume and intercept errors as events since we'll be able to use multiple listeners on it and we can send notification to the tenant also.
In the other hand if you'll need a very specific and custom application for a single tenant then it would be more appropriate to intercept errors as exceptions because it is probably the core component of the entire application.
By default all events are disabled and going to raise.
To adjust your needs your can freely add or remove events declared in the configuration file.
<?php
return [
// ....
'events' => [
// Add or remove events here.
SzuniSoft\Unas\Laravel\Events\EndpointBlacklisted::class
]
];
The following errors can be turned into events.
Exception | Event |
---|---|
EndpointBlacklistedException | EndpointBlacklisted |
InvalidConfigurationException | InvalidConfiguration |
AuthenticationException | Unauthenticated |
PremiumAuthenticationException | Unauthenticated |
Thrown when an endpoint is being exhausted for a single client. You can access the client and the until Carbon instance.
Thrown in case of bad client configuration.
This exception will be thrown when legacy or key credentials are invalid. You can access the field which was invalid.
Thrown when the desired authentication way is API key but related tenant has no Premium package. In this case tenant should use the legacy approach.
Thrown when an endpoint does not allow the amount of given results per page.
Sometimes you wish to have multiple clients. If you want clients to be remembered you can turn on this feature in the configuration. Remembering client will avoid creating multiple clients for the same authentication credentials.
There are multiple ways to create clients.
This method will use the credentials given in the configuration.
<?php
function anyFunction (SzuniSoft\Unas\Internal\Client $client) {
}
This method will use the credentials given in the configuration.
<?php
$client = app(SzuniSoft\Unas\Internal\Client::class);
$client = app('unas.client');
Sometimes you want to customize the client by yourself. For these kind of desires you can use the client Builder and client Factory.
<?php
$builder = app(SzuniSoft\Unas\Laravel\Support\ClientBuilder::class);
$builder = app('unas.client.builder');
$client = $builder
// Apply premium authentication API key manually.
->withPremium('SomeApiKey')
// Apply legacy authentication credentials manually.
->withLegacy('Username', 'Password', 'ShopID', 'AuthCode')
// Override default base path to access Unas.
// You should never set base url manually except when url changed.
->basePath('http://new.domain')
// Set events that should be fired instead throwing as exception.
->allowedEvents(...)
// Set events that should not be fired. Instead exception should be thrown.
->disallowedEvents(...)
// Finally retrieve the client.
->build();
<?php
$factory = app(SzuniSoft\Unas\Laravel\Support\ClientFactory::class);
$factory = app('unas.client.factory');
$config = [
// Custom client configurations..
];
$client = $factory->create($config);
<?php
/** @var SzuniSoft\Unas\Internal\Client $client */
$client->getProducts()
->statusBase(...)
->parent(...)
->id(...)
->sku(...)
->timeStart(...)
->timeEnd(...)
->dateStart(...)
->dateEnd(...)
->contentType(...)
->contentParam(...)
->chunk(function (Illuminate\Support\Collection $products) {
$products->each(function (SzuniSoft\Unas\Model\Product $product) {
// Process product.
});
}, $perPage = 50);
Accessing page #1 with 50 products per page.
<?php
/** @var SzuniSoft\Unas\Internal\Client $client */
$client->getProducts()
->paginate(50)
->page(1);