Skip to content

Commit

Permalink
Add Translations as a resource name and be able to specify the apiB…
Browse files Browse the repository at this point in the history
…aseUrl (#483)

* added translation as a resource for httpClient and updated apiBasePath to accept a different value other than the hard-coded one (api/v2)
  • Loading branch information
willshen8 authored Feb 1, 2022
1 parent 21ed028 commit 0f3bf99
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
39 changes: 39 additions & 0 deletions src/Zendesk/API/Resources/Core/Translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Zendesk\API\Resources\Core;

use Zendesk\API\Resources\ResourceAbstract;
use Zendesk\API\Traits\Resource\FindAll;

/**
* The Translations class finds the manifest files for localizations
*/

class Translations extends ResourceAbstract
{
use FindAll;
/**
* {@inheritdoc}
*/
protected function setUpRoutes()
{
$this->setRoutes([
'manifest' => "{$this->resourceName}/manifest.json",
]);
}

/**
* Get the manifest json file
*
* @param array $params
*
* @throws \Exception
*
* @return \stdClass | null
*/
public function manifest(array $params = [])
{
return $this->findAll($params, __FUNCTION__);
}

}
5 changes: 3 additions & 2 deletions src/Zendesk/API/Resources/ResourceAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ abstract class ResourceAbstract
/**
* @var string
*/
protected $apiBasePath = 'api/v2/';
protected $apiBasePath;

/**
* @param HttpClient $client
*/
public function __construct(HttpClient $client)
public function __construct(HttpClient $client, $apiBasePath='api/v2/')
{
$this->apiBasePath = $apiBasePath;
$this->client = $client;
$this->client->setApiBasePath($this->apiBasePath);

Expand Down
21 changes: 21 additions & 0 deletions tests/Zendesk/API/UnitTests/Core/TranslationsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Zendesk\API\UnitTests\Core;

use Zendesk\API\UnitTests\BasicTest;

/**
* Translations test class
*/
class TranslationsTest extends BasicTest
{
/**
* Test manifest method
*/
public function testFindManifest()
{
$this->assertEndpointCalled(function () {
$this->client->translations()->manifest();
}, 'translations/slack-auth-service/manifest.json');
}
}

0 comments on commit 0f3bf99

Please sign in to comment.