Skip to content

Commit 0f3bf99

Browse files
authored
Add Translations as a resource name and be able to specify the apiBaseUrl (#483)
* added translation as a resource for httpClient and updated apiBasePath to accept a different value other than the hard-coded one (api/v2)
1 parent 21ed028 commit 0f3bf99

3 files changed

Lines changed: 63 additions & 2 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Zendesk\API\Resources\Core;
4+
5+
use Zendesk\API\Resources\ResourceAbstract;
6+
use Zendesk\API\Traits\Resource\FindAll;
7+
8+
/**
9+
* The Translations class finds the manifest files for localizations
10+
*/
11+
12+
class Translations extends ResourceAbstract
13+
{
14+
use FindAll;
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
protected function setUpRoutes()
19+
{
20+
$this->setRoutes([
21+
'manifest' => "{$this->resourceName}/manifest.json",
22+
]);
23+
}
24+
25+
/**
26+
* Get the manifest json file
27+
*
28+
* @param array $params
29+
*
30+
* @throws \Exception
31+
*
32+
* @return \stdClass | null
33+
*/
34+
public function manifest(array $params = [])
35+
{
36+
return $this->findAll($params, __FUNCTION__);
37+
}
38+
39+
}

src/Zendesk/API/Resources/ResourceAbstract.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ abstract class ResourceAbstract
5151
/**
5252
* @var string
5353
*/
54-
protected $apiBasePath = 'api/v2/';
54+
protected $apiBasePath;
5555

5656
/**
5757
* @param HttpClient $client
5858
*/
59-
public function __construct(HttpClient $client)
59+
public function __construct(HttpClient $client, $apiBasePath='api/v2/')
6060
{
61+
$this->apiBasePath = $apiBasePath;
6162
$this->client = $client;
6263
$this->client->setApiBasePath($this->apiBasePath);
6364

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Zendesk\API\UnitTests\Core;
4+
5+
use Zendesk\API\UnitTests\BasicTest;
6+
7+
/**
8+
* Translations test class
9+
*/
10+
class TranslationsTest extends BasicTest
11+
{
12+
/**
13+
* Test manifest method
14+
*/
15+
public function testFindManifest()
16+
{
17+
$this->assertEndpointCalled(function () {
18+
$this->client->translations()->manifest();
19+
}, 'translations/slack-auth-service/manifest.json');
20+
}
21+
}

0 commit comments

Comments
 (0)