Skip to content

Commit

Permalink
Add ApiTemplates endpoint (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmleroux authored and Pierre Ducoudray committed Jan 17, 2018
1 parent 8ad4f29 commit 37c4f82
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 4 deletions.
32 changes: 32 additions & 0 deletions lib/Textmaster/Api/ApiTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Textmaster Api v1 client package.
*
* (c) Christian Daguerre <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Textmaster\Api;

/**
* ApiTemplates Api.
*
* @author JM Leroux <[email protected]>
*/
class ApiTemplate extends AbstractApi
{
/**
* List all API templates.
*
* @link https://fr.textmaster.com/documentation#api-templates-list-api-templates
*
* @return array
*/
public function all()
{
return $this->get('clients/api_templates');
}
}
14 changes: 14 additions & 0 deletions lib/Textmaster/Api/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ public function resume($projectId)
return $this->put($this->getPath($projectId).'/resume');
}

/**
* Finalize a project.
*
* @link https://fr.textmaster.com/documentation#projects-finalize-a-project
*
* @param string $projectId
*
* @return array
*/
public function finalize($projectId)
{
return $this->put($this->getPath($projectId).'/finalize');
}

/**
* Launch a project.
*
Expand Down
17 changes: 13 additions & 4 deletions lib/Textmaster/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
use Textmaster\Api\ApiInterface;
use Textmaster\Exception\BadMethodCallException;
use Textmaster\Exception\InvalidArgumentException;
use Textmaster\HttpClient\HttpClient;
use Textmaster\HttpClient\HttpClientInterface;

/**
* PHP Textmaster client.
*
* @method Api\Author author()
* @method Api\ApiTemplate apiTemplate()
* @method Api\Author authors()
* @method Api\Billing billing()
* @method Api\Bundle bundle()
Expand Down Expand Up @@ -80,7 +79,17 @@ public function api($name)
{
$name = Inflector::singularize($name);
$apis = [
'author', 'billing', 'bundle', 'category', 'expertise', 'language', 'locale', 'project', 'template', 'user',
'apiTemplate',
'author',
'billing',
'bundle',
'category',
'expertise',
'language',
'locale',
'project',
'template',
'user',
];

if (!in_array($name, $apis, true)) {
Expand All @@ -93,7 +102,7 @@ public function api($name)
}

/**
* @return HttpClient
* @return HttpClientInterface
*/
public function getHttpClient()
{
Expand Down
83 changes: 83 additions & 0 deletions test/Textmaster/Unit/Api/ApiTemplateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

/*
* This file is part of the Textmaster Api v1 client package.
*
* (c) Christian Daguerre <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Textmaster\Unit\Api;

use Textmaster\Api\ApiTemplate;

class ApiTemplateTest extends TestCase
{
/**
* @test
*/
public function shouldShowAllTemplates()
{
$expectedArray = [
"api_templates" => [
"id" => "3734fed3-833b-4e46-8b3b-cf36ccd79afe",
"name" => "Foo Bar 2017-09-06 12:32:02 +0200",
"description" => "[TM] Standard Translation (en-us > fr-fr)",
"level_name" => "premium",
"activity_name" => "translation",
"language_from" => "en-us",
"language_to" => "fr-fr",
"project_briefing" => "Bacon ipsum dolor amet ribeye tenderloin pancetta ground round cow turducken shankle beef ribs.",
"options" => [
"language_level" => "premium",
],
"textmasters" => [

],
"cost_per_word" => [
"currency" => "credits",
"amount" => 10,
],
"cost_per_word_in_currency" => [
"currency" => "USD",
"amount" => 0.014,
],
"same_author_must_do_entire_project" => true,
"auto_launch" => true,
"created_at" => [
"day" => 6,
"month" => 9,
"year" => 2017,
"full" => "2017-09-06 10:32:02 UTC",
],
"updated_at" => [
"day" => 6,
"month" => 9,
"year" => 2017,
"full" => "2017-09-06 10:32:02 UTC",
],
],
"total_pages" => 1,
"count" => 1,
"page" => 1,
"per_page" => 20,
"previous_page" => null,
"next_page" => null,
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('clients/api_templates')
->will($this->returnValue($expectedArray));

$this->assertSame($expectedArray, $api->all());
}

protected function getApiClass()
{
return ApiTemplate::class;
}
}

0 comments on commit 37c4f82

Please sign in to comment.