insidesuki / solapimanager
delSOl ApiClient
Requires
- php: >=8.1
- ext-json: *
- insidesuki/apiclient: 1.8.4
- insidesuki/ddd-utils: ^2.1.1
- insidesuki/entitymapping: ^0.1.4
- phpunit/phpunit: >=8
- symfony/css-selector: 5.4.*
- symfony/dom-crawler: 5.4.*
- symfony/framework-bundle: 5.4.*
Requires (Dev)
- symfony/dotenv: 5.4.*
- dev-master
- 2.2.5
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2
- 2.1.11
- 2.1.10
- 2.1.9
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1
- 2.0
- 1.7.4
- 1.7.3
- 1.7.2
- 1.7.1
- 1.6.3
- 1.6.2
- 1.6.1
- 1.6
- 1.5
- 1.4.6
- 1.4.5
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4
- 1.3.9
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3
- 1.2
- 1.1
- 0.1.1
- 0.0.10
- 0.0.2
- 0.0.1
- dev-dr/feature/190922/embedeble-mapping
- dev-feature/mapping
- dev-dr/refactor/delsolapimanager
- dev-dr/refactor-delsolapimanager
This package is auto-updated.
Last update: 2025-03-11 10:14:38 UTC
README
Provides an abstract repository to your symfony 5.4 project or standalone project, to make query requests to the ContaSol API
Features
- Support for multiple credentials via $_ENV files and a Class to represent the credentials.
- Simple Key Value for query Conditions (findOneBy,insert and update)
// example for findOneBy condition
$condition = ['codcli'=>1]
// example for insert petition
$insert = [
'codcli' => '9989'
'nomcli' => 'faraday'
];
REPOSITORY APIS
- findOneBy(array $condition): null|array: performs LeerRegistro petition https://api.sdelsol.com/admin/LeerRegistro
- findByQuery(string $query): null|array: performs LanzarConsulta petition https://api.sdelsol.com/admin/LanzarConsulta
- findByFilter(string $filter): array: performs CargaTabla petition https://api.sdelsol.com/admin/CargaTabla
- insert(array $data):bool: performs EscribirRegistro petition https://api.sdelsol.com/admin/EscribirRegistro
- update(array $data):bool performs ActualizarRegistro petition https://api.sdelsol.com/admin/ActualizarRegistro
- delete(array $condition):bool: performs BorrarRegistros petition https://api.sdelsol.com/admin/BorrarRegistros/:ejercicio/:tabla/:filtro
- getInfo(string $field): array: performs LeerConfiguracion petition https://api.sdelsol.com/admin/LeerConfiguracion/2021/F_CLI
Installation
composer require insidesuki/solapimanager
FirstSteps
1- Add to yout .env file
###> DELSOL API CREDENTIAL
### Namespace to use as credentials folder
DELSOL_API_CREDENTIALS="YourProjectNamespace\\ToUse\\AS\\CredentialFolderStore\\"
APIDELSOL_BASE_URL=https://api.sdelsol.com
APIDELSOL_AUTH_URL=https://api.sdelsol.com/login/Autenticar
APIDELSOL_TOKEN_RESPONSE=resultado
APIDELSOL_TOKEN_EXPIRES=60;
## CREDENTIALS1, use as key name the one you want
API1_NAME=delSol1
API1_CODIGO_FABRICANTE=***
API1_CODIGO_CLIENTE=*****
API1_DB=****
API1_SECRET=******
## CREDENTIALS1
API2_NAME=delSol1
API2_CODIGO_FABRICANTE=***
API2_CODIGO_CLIENTE=*****
API2_DB=****
API2_SECRET=******
###< delsolApiClient ###
2- Creating Credentials Class
Go to DELSOL_API_CREDENTIALS path and create a credential for each API defined in your $_ENV file. Must be extends from AbstractDelSolCredential
namespace F2admin\Application\Contabilidad\Infrastructure\Storage\DelSolApi\Credentials; use Insidesuki\ApiClient\Authentification\Contracts\ApiBearerCredentialInterface;
class DefaultSolCredential extends AbstractDelSolCredential implements ApiBearerCredentialInterface {
public function getApiName(): string
{
return $_ENV['API1_NAME'];
}
public function getBodyAuth(): array
{
return [
'codigoFabricante' => $_ENV['API1_CODIGO_FABRICANTE'],
'codigoCliente' => $_ENV['API1_CODIGO_CLIENTE'],
'baseDatosCliente' => $_ENV['API1_DB'],
'password' => $_ENV['API1_SECRET']
];
}
}
3- Creating a Repository
Create a repository that extends from AbstractDelSolRepository, define the table,credential, etc
namespace YourProject\Namespace\Repository; use Symfony\Contracts\HttpClient\HttpClientInterface; class ClientExampleRepository extends AbstractDelSolRepository { public function __construct(HttpClientInterface $httpClient) { parent::__construct($httpClient); } // define the delSol tablename public function tableName(): string { return 'f_cli'; } public function findById(int $idClient) { return $this->delSolManager->findOne(['codcli' => $idClient]); } }
Without Symfony
- Perform all the above steps
- Creates a file like:
require __DIR__ . '/vendor/autoload.php';
use YourProject\Namespace\Repository\ClientExampleRepository;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpClient\NativeHttpClient;
try {
$dotEnv = new Dotenv();
$dotEnv->load(__DIR__ . '/../config/.env.local');
$clientRepository = new ClientExampleRepository(
new NativeHttpClient()
);
// set the credential to use
$clientRepository->setManager('DelSolCredentialA');
$client = $clientRepository->findById(1);
}
catch (Exception $e) {
dd($e->getMessage());
}
dd($client);