### Install Composer Dependencies Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Install project dependencies using Composer. ```shell make install ``` -------------------------------- ### Install Vetmanager REST API with Composer Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Use this command to install the library via Composer. ```bash composer require otis22/vetmanager-rest-api ``` -------------------------------- ### Install Composer Dependencies (No Dev) Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Install project dependencies using Composer, excluding development dependencies. ```shell make install-no-dev ``` -------------------------------- ### PHP: Query Builder for Paginated Records Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Utilize the Builder class with paginate(limit, offset) for custom pagination, allowing control over the number of records and their starting point. ```php $paginate = (new Builder()) ->where('client_id', 'in', [1, 2]) ->orderBy('id', 'desc') ->paginate(10, 20); ``` -------------------------------- ### PHP: Get All Records with Pagination Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Retrieve all records using PagedQuery::forGettingAll. This method requires sorting and iteratively fetches data until all records are collected. ```php $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']); ``` -------------------------------- ### PHP: Get Top N Records Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Fetch a specific number of top records using PagedQuery::forGettingTop. This method also requires sorting. ```php $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 ); ``` -------------------------------- ### Get Latest Invoice for Specific Clients Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md This snippet demonstrates how to fetch the latest invoice for clients with IDs 1 or 2, sorted by invoice date in descending order. It requires the 'otis22/vetmanager-url' package for URL construction. ```php use GuzzleHttp\Client; use function Otis22\VetmanagerUrl\url; use function Otis22\VetmanagerRestApi\uri; use function Otis22\VetmanagerRestApi\byApiKey; use Otis22\VetmanagerRestApi\Query\Builder; $client = new Client([ 'base_uri' => url("myclinic")->asString() ]); $top = (new Builder()) ->where('client_id', 'in', [1, 2]) ->orderBy('invoice_date', 'desc') ->top(1); $response = $client->request( 'GET', uri("invoice")->asString(), [ 'headers' => byApiKey("myapikey")->asKeyValue(), 'query' => $top->asKeyValue() ] ); ``` -------------------------------- ### Connect to Terminal Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Connect to the project's terminal environment. ```shell make exec ``` -------------------------------- ### Run Unit Tests Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Execute the unit tests for the project. ```shell make unit ``` -------------------------------- ### Run Integration Tests Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Execute integration tests. Requires the .env file to be configured. ```shell make integration ``` -------------------------------- ### Run Static Analysis Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Execute static analysis tools to check for potential code issues. ```shell make static-analyze ``` -------------------------------- ### Run All Tests Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Execute all tests in the project. The default PHP version is 8.1. ```shell make all ``` -------------------------------- ### Create URI for a Model Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Shows how to construct a URI for a specific model, like 'invoice'. This is used for basic resource retrieval. ```php use Otis22\VetmanagerRestApi\URI; use Otis22\VetmanagerRestApi\Model; $uri = new URI\OnlyModel( new Model('invoice') ); $client = new GuzzleHttp\Client(['base_uri' => 'http://some.vetmanager.ru']); // request to /rest/api/invoice $client->request('GET', $uri->asString()); ``` ```php $uriString = \Otis22\VetmanagerRestApi\uri('invoice')->asString(); ``` -------------------------------- ### Perform Security Check Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Run security checks on the project dependencies. ```shell make security ``` -------------------------------- ### Check Code Style Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Check the code style of the project. ```shell make style ``` -------------------------------- ### Run Tests with Multiple PHP Versions Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Run tests concurrently for both PHP 8.0 and PHP 8.1. ```shell make all PHP_VERSION=8.0 && make all PHP_VERSION=8.1 ``` -------------------------------- ### Run All Tests with Specific PHP Version Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Execute all tests using a specified PHP version. Only versions 8.0 and 8.1 are currently available. ```shell make all PHP_VERSION=8.0 ``` -------------------------------- ### Create URI for a Model with a Specific ID Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Demonstrates creating a URI for a specific resource instance by providing both the model and its ID. Used for accessing individual records. ```php use Otis22\VetmanagerRestApi\URI; use Otis22\VetmanagerRestApi\Model; $uri = new URI\WithId( new Model('invoice'), 5 ); $client = new GuzzleHttp\Client(['base_uri' => 'http://some.vetmanager.ru']); // request to /rest/api/invoice/5 $client->request('GET', $uri->asString()); ``` ```php $uriString = \Otis22\VetmanagerRestApi\uri('invoice', 5)->asString(); ``` -------------------------------- ### Service API Key Authentication Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Illustrates authentication using a service API key, typically for system-to-system integrations. Requires both a service name and an API key. ```php use Otis22\VetmanagerRestApi\Headers; use Otis22\VetmanagerRestApi\Headers\Auth\ServiceName; use Otis22\VetmanagerRestApi\Headers\Auth\ApiKey; $authHeaders = new Headers\WithAuth( new Headers\Auth\ByServiceApiKey( new ServiceName('name') new ApiKey('key') ) ); $client = new GuzzleHttp\Client(['base_uri' => 'http://some.vetmanager.ru']); $client->request( 'GET', '/rest/api/user/1', ['headers' => $authHeaders->asKeyValue()] ); ``` ```php $authHeaders = Otis22\VetmanagerRestApi\byServiceApiKey('service', 'api key'); # use this after ['headers' => $authHeaders->asKeyValue()] ``` -------------------------------- ### API Key Authentication Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Demonstrates how to authenticate API requests using an API key. This method is suitable for direct API access. ```php use Otis22\VetmanagerRestApi\Headers; use Otis22\VetmanagerRestApi\Headers\Auth\ApiKey; $client = new GuzzleHttp\Client(['base_uri' => 'http://some.vetmanager.ru']); $authHeaders = new Headers\WithAuth( new Headers\Auth\ByApiKey( new ApiKey('test-key') ) ); $client->request( 'GET', '/rest/api/user/1', ['headers' => $authHeaders->asKeyValue()] ); ``` ```php $authHeaders = Otis22\VetmanagerRestApi\byApiKey('test-key'); # use this after ['headers' => $authHeaders->asKeyValue()] ``` -------------------------------- ### PHP: Query Builder for Top N Records Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Use the Builder class to construct queries for fetching top N records. Supports chaining methods for filtering and sorting. ```php $top = (new Builder()) ->where('client_id', 'in', [1, 2]) ->orderBy('id', 'desc') ->top(1); ``` -------------------------------- ### Check Test Coverage Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Generate and check the test coverage report. ```shell make coverage ``` -------------------------------- ### API Key Authentication with Custom Timezone Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Shows how to set a custom timezone header along with API key authentication. Useful for requests requiring specific time context. ```php use Otis22\VetmanagerRestApi\Headers; use Otis22\VetmanagerRestApi\Headers\Auth\ApiKey; $myHeaders = [ 'X-REST-TIME-ZONE' => '+02:00' ]; $allHeaders = new Headers\WithAuthAndParams( new Headers\Auth\ByApiKey( new ApiKey('test-key') ), $myHeaders ); $client = new GuzzleHttp\Client(['base_uri' => 'http://some.vetmanager.ru']); $client->request( 'GET', '/rest/api/user/1', ['headers' => $allHeaders->asKeyValue()] ); ``` -------------------------------- ### PHP: Query Builder for All Records Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Employ the Builder class with paginateAll() to create queries for retrieving all records based on specified filters and sort orders. ```php $paginateAll = (new Builder()) ->where('client_id', 'in', [1, 2]) ->orderBy('id', 'desc') ->paginateAll(); ``` -------------------------------- ### PHP: Combine Filters and Sorts Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Construct a Query object to combine both filters and sorts for complex API requests. Ensure all necessary components are included. ```php use Otis22\VetmanagerRestApi\Query\Query; ... $query = new Query( new Filters(...), new Sorts(...) ); $client = new GuzzleHttp Client(['base_uri' => 'http://some.vetmanager.ru']); $client->request( 'GET', '/rest/api/user/1', [ 'headers' => $authHeaders->asKeyValue(), 'query' => $query->asKeyValue() ] ); ``` -------------------------------- ### Token Authentication Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Demonstrates token-based authentication for API requests. This method is used when authenticating with application credentials. ```php use Otis22\VetmanagerRestApi\Headers; use Otis22\VetmanagerToken; $authHeaders = new Headers\WithAuth( new Headers\Auth\ByToken( new Credentials\AppName("myapp"), new Token\Concrete("mytoken") ) ); $client = new GuzzleHttp\Client(['base_uri' => 'http://some.vetmanager.ru']); $client->request( 'GET', '/rest/api/user/1', ['headers' => $authHeaders->asKeyValue()] ); ``` ```php $authHeaders = Otis22\VetmanagerRestApi\byToken('myapp', 'mytoken'); # use this after ['headers' => $authHeaders->asKeyValue()] ``` -------------------------------- ### PHP: Query Builder with Filter Classes Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Construct queries using specific filter classes from the API for more precise filtering conditions. This allows for advanced filtering logic. ```php use Otis22\VetmanagerRestApi\Query\Filter; (new Builder()) ->where('client_id', Filter\InArray::class, [1, 2]) ->where('pet_id', Filter\NotEqualTo::class, 5) ``` -------------------------------- ### PHP: Sort API Records Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Utilize the Sorts class to define sorting parameters for API requests. Supports both ascending and descending order. ```php use Otis22\VetmanagerRestApi\Query\Sorts; use Otis22\VetmanagerRestApi\Query\Sort\AscBy; use Otis22\VetmanagerRestApi\Query\Sort\DescBy; use Otis22\VetmanagerRestApi\Model\Property; $sorts = new Sorts( new AscBy( new Property('propertyName') ), new DescBy( new Property('property2Name') ) ); $client = new GuzzleHttp Client(['base_uri' => 'http://some.vetmanager.ru']); $client->request( 'GET', '/rest/api/user/1', [ 'headers' => $authHeaders->asKeyValue(), 'query' => $sorts->asKeyValue() ] ); ``` -------------------------------- ### PHP: Filter API Records Source: https://github.com/otis22/vetmanager-rest-api/blob/main/README.md Use the Filters class to construct filter criteria for API requests. Ensure correct property names and values are used. ```php use Otis22\VetmanagerRestApi\Query\Filters; use Otis22\VetmanagerRestApi\Query\Filter\EqualTo; use Otis22\VetmanagerRestApi\Model\Property; use Otis22\VetmanagerRestApi\Query\Filter\Value\StringValue; $filters = new Filters( new EqualTo( new Property('propertyName'), new StringValue('propertyValue') ) # ... we can use mach more filters new Filters($filterOne, $filterTwo, ... ); ); $client = new GuzzleHttp Client(['base_uri' => 'http://some.vetmanager.ru']); $client->request( 'GET', '/rest/api/user/1', [ 'headers' => $authHeaders->asKeyValue(), 'query' => $filters->asKeyValue() ] ); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.