Vetmanager - CRM for veterinary with REST API. vetmanager-rest-api is library will help work with them.
vetmanager REST API in Postman
- Full url only by domain name (host might to change)
- Model name validation in uri()
- Simplify apiKey and token authorization
- Sorting, Filtering and others
- Get all sorted and filtered records from model
use GuzzleHttp\Client;
use function Otis22\VetmanagerUrl\url;
use function Otis22\VetmanagerRestApi\uri;
use function Otis22\VetmanagerRestApi\byApiKey;
$client = new Client(['base_uri' => url("myclinic")->asString()]);
$request = $client->request(
'GET',
uri("invoice")->asString(),
['headers' => byApiKey("myapikey")->asKeyValue()]
);
Warning! function url
requires "otis22/vetmanager-url" package.
composer require otis22/vetmanager-rest-api
- For auth
- For create valid URI
- For filtering and sorting data
- How to get all records
- How to get top n records
$client = new GuzzleHttp\Client(['base_uri' => 'http://some.vetmanager.ru']);
$authHeaders = new Otis22\VetmanagerRestApi\Headers\WithAuth(
new \Otis22\VetmanagerRestApi\Headers\Auth\ByApiKey(
new \Otis22\VetmanagerRestApi\Headers\Auth\ApiKey('test-key')
)
);
$client->request(
'GET',
'/rest/api/user/1',
['headers' => $authHeaders->asKeyValue()]
);
or with function
$authHeaders = Otis22\VetmanagerRestApi\byApiKey('test-key');
# use this after ['headers' => $authHeaders->asKeyValue()]
$client = new GuzzleHttp\Client(['base_uri' => 'http://some.vetmanager.ru']);
$myHeaders = [
'X-REST-TIME-ZONE' => '+02:00'
];
$allHeaders = new Otis22\VetmanagerRestApi\Headers\WithAuthAndParams(
new \Otis22\VetmanagerRestApi\Headers\Auth\ByApiKey(
new \Otis22\VetmanagerRestApi\Headers\Auth\ApiKey('test-key')
),
$myHeaders
);
$client->request(
'GET',
'/rest/api/user/1',
['headers' => $allHeaders->asKeyValue()]
);
$client = new GuzzleHttp\Client(['base_uri' => 'http://some.vetmanager.ru']);
$authHeaders = new Otis22\VetmanagerRestApi\Headers\WithAuth(
new \Otis22\VetmanagerRestApi\Headers\Auth\ByToken(
new \Otis22\VetmanagerToken\Credentials\AppName("myapp"),
new \Otis22\VetmanagerToken\Token\Concrete("mytoken")
)
);
$client->request(
'GET',
'/rest/api/user/1',
['headers' => $authHeaders->asKeyValue()]
);
or with function
$authHeaders = Otis22\VetmanagerRestApi\byToken('myapp', 'mytoken');
# use this after ['headers' => $authHeaders->asKeyValue()]
$client = new GuzzleHttp\Client(['base_uri' => 'http://some.vetmanager.ru']);
$uri = new \Otis22\VetmanagerRestApi\URI\OnlyModel(
new \Otis22\VetmanagerRestApi\Model('invoice')
);
// request to /rest/api/invoice
$client->request('GET', $uri->asString());
or with function
$uriString = \Otis22\VetmanagerRestApi\uri('invoice')->asString();
$client = new GuzzleHttp\Client(['base_uri' => 'http://some.vetmanager.ru']);
$uri = new \Otis22\VetmanagerRestApi\URI\WithId(
new \Otis22\VetmanagerRestApi\Model('invoice'),
5
);
// request to /rest/api/invoice/5
$client->request('GET', $uri->asString());
or with function
$uriString = \Otis22\VetmanagerRestApi\uri('invoice', 5)->asString();
$client = new GuzzleHttp\Client(['base_uri' => 'http://some.vetmanager.ru']);
$filters = new \Otis22\VetmanagerRestApi\Query\Filters(
new \Otis22\VetmanagerRestApi\Query\Filter\EqualTo(
new \Otis22\VetmanagerRestApi\Model\Property('propertyName'),
new \Otis22\VetmanagerRestApi\Query\Filter\Value\StringValue('propertyValue')
)
# ... we can use mach more filters new Filters($filterOne, $filterTwo, ... );
);
$client->request(
'GET',
'/rest/api/user/1',
[
'headers' => $authHeaders->asKeyValue(),
'query' => $filters->asKeyValue()
]
);
- Otis22\VetmanagerRestApi\Query\Filter\EqualTo - where property is equal to value
- Otis22\VetmanagerRestApi\Query\Filter\InArray - where property is in list
- Otis22\VetmanagerRestApi\Query\Filter\LessOrEqualThan - where property is less or equal than value
- Otis22\VetmanagerRestApi\Query\Filter\LessThan - where property is less than value
- Otis22\VetmanagerRestApi\Query\Filter\Like - where property is like value(for using MySQL LIKE)
- Otis22\VetmanagerRestApi\Query\Filter\MoreOrEqualThan - where property is more or equal than value
- Otis22\VetmanagerRestApi\Query\Filter\MoreThan - where property more than value
- Otis22\VetmanagerRestApi\Query\Filter\NotEqualTo - where propery is not equal to value
- Otis22\VetmanagerRestApi\Query\Filter\NotInArray - where property is not in list
$client = new GuzzleHttp\Client(['base_uri' => 'http://some.vetmanager.ru']);
$sorts = new \Otis22\VetmanagerRestApi\Query\Sorts(
new \Otis22\VetmanagerRestApi\Query\Sort\AscBy(
new \Otis22\VetmanagerRestApi\Model\Property('propertyName')
),
new \Otis22\VetmanagerRestApi\Query\Sort\DescBy(
new \Otis22\VetmanagerRestApi\Model\Property('property2Name')
)
);
$client->request(
'GET',
'/rest/api/user/1',
[
'headers' => $authHeaders->asKeyValue(),
'query' => $sorts->asKeyValue()
]
);
$client = new GuzzleHttp\Client(['base_uri' => 'http://some.vetmanager.ru']);
$query = new \Otis22\VetmanagerRestApi\Query\Query(
new \Otis22\VetmanagerRestApi\Query\Filters(),
new \Otis22\VetmanagerRestApi\Query\Sorts()
);
$client->request(
'GET',
'/rest/api/user/1',
[
'headers' => $authHeaders->asKeyValue(),
'query' => $query->asKeyValue()
]
);
$paged = PagedQuery::forGettingAll(
new Query(
// Sorts Required!
)
);
$result = [];
do {
$response = json_decode(
strval(
$client->request(
'GET',
uri('invoice')->asString(),
[
'headers' => $headers->asKeyValue(),
'query' => $paged->asKeyValue()
]
)->getBody()
),
true
);
$paged = $paged->next();
$result = array_merge(
$response['data']['invoice'],
$result
);
} while (count($result) < $response['data']['totalCount']);
$top1 = PagedQuery::forGettingTop(
new Query(
// Sorts Required!
),
1
);
$response = json_decode(
strval(
$client->request(
'GET',
uri('invoice')->asString(),
[
'headers' => $headers->asKeyValue(),
'query' => $top1->asKeyValue()
]
)->getBody()
),
true
);
For run all tests
make all
or connect to terminal
make exec
Dafault php version is 7.4. Use PHP_VERSION= for using custom version.
make all PHP_VERSION=8.0
# run both
make all PHP_VERSION=7.4 && make all PHP_VERSION=8.0
For integration tests copy .env.example to .env and fill with yours values
all commands
# security check
make security
# composer install
make install
# composer install with --no-dev
make install-no-dev
# check code style
make style
# run static analyze tools
make static-analyze
# run unit tests
make unit
# check coverage
make coverage
# check integration, .env required
make integration