pervozdanniy / translation-client
Client for translation API
2.1.1
2020-11-23 10:35 UTC
Requires
- php: ^7.2
- guzzlehttp/guzzle: ^6.0|^7.0
- psr/simple-cache: ^1.0
Requires (Dev)
README
Translate API is a PSR-compatible PHP HTTP client for working with translate API.
Installation
The recommended way to install Translate API client is through Composer.
# Install Composer curl -sS https://getcomposer.org/installer | php
Next, run the Composer command to install the latest stable version of Guzzle:
composer require pervozdanniy/translation-client
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
You can then later update Guzzle using composer:
composer update
Usage
$options = [ 'login' => '<YOUR_LOGIN>', 'password' => '<YOUR_PASSWORD>', ]; // you can pass any storage you want that implements \Psr\SimpleCache\CacheInterface $client = new \Translate\ApiClient($options, new \Translate\Storage\ArrayStorage); $response = $client->request('GET', 'users'); echo $response->getStatusCode(); # 200 echo $response->getHeaderLine('content-type'); # 'application/json; charset=utf8' echo $response->getBody(); # '{"items": [{"uuid": ...}'
Aliases
Client also resolves aliases, received from login request:
$response = $client->request('GET', 'users/{userUuid}/projects');
For authenticated user 2 aliases are available by default:
userUuid
and authToken
You can add your own aliases using:
$client->setAlias('projectUuid', '<PROJECT_UUID>'); // use user-defined alias $response = $client->request('GET', 'projects/{projectUuid}/languages');