View source
<?php
namespace Smartling\ProgressTracker;
use GuzzleHttp\ClientInterface;
use Psr\Log\LoggerInterface;
use Smartling\AuthApi\AuthApiInterface;
use Smartling\BaseApiAbstract;
use Smartling\ProgressTracker\Params\RecordParameters;
class ProgressTrackerApi extends BaseApiAbstract {
const ENDPOINT_URL = 'https://api.smartling.com/progress-tracker-api/v2';
public function __construct($projectId, ClientInterface $client, $logger = null, $service_url = null) {
parent::__construct($projectId, $client, $logger, $service_url);
$this
->setBaseUrl(rtrim($service_url, '/'));
}
public static function create(AuthApiInterface $authProvider, $projectId, $logger = null) {
$client = static::initializeHttpClient(self::ENDPOINT_URL);
$instance = new self($projectId, $client, $logger, self::ENDPOINT_URL);
$instance
->setAuth($authProvider);
return $instance;
}
public function getToken($accountUid) {
$requestData = $this
->getDefaultRequestData('query', []);
$endpoint = vsprintf('accounts/%s/token', [
$accountUid,
]);
return $this
->sendRequest($endpoint, $requestData, static::HTTP_METHOD_GET);
}
public function createRecord($spaceId, $objectId, RecordParameters $parameters) {
$requestData = $this
->getDefaultRequestData('json', $parameters
->exportToArray());
$endpoint = vsprintf('projects/%s/spaces/%s/objects/%s/records', [
$this
->getProjectId(),
$spaceId,
$objectId,
]);
return $this
->sendRequest($endpoint, $requestData, static::HTTP_METHOD_POST);
}
public function deleteRecord($spaceId, $objectId, $recordId) {
$requestData = $this
->getDefaultRequestData('query', []);
$endpoint = vsprintf('projects/%s/spaces/%s/objects/%s/records/%s', [
$this
->getProjectId(),
$spaceId,
$objectId,
$recordId,
]);
return $this
->sendRequest($endpoint, $requestData, static::HTTP_METHOD_DELETE);
}
public function updateRecord($spaceId, $objectId, $recordId, RecordParameters $parameters) {
$requestData = $this
->getDefaultRequestData('json', $parameters
->exportToArray());
$endpoint = vsprintf('projects/%s/spaces/%s/objects/%s/records/%s', [
$this
->getProjectId(),
$spaceId,
$objectId,
$recordId,
]);
return $this
->sendRequest($endpoint, $requestData, static::HTTP_METHOD_PUT);
}
}