Skip to content

Commit

Permalink
Fixed Issue kontent-ai#117
Browse files Browse the repository at this point in the history
  • Loading branch information
omkolte17 committed Sep 3, 2023
1 parent e6b22f4 commit b45d0b1
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 36 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ require __DIR__ . '/vendor/autoload.php';

The `DeliveryClient` class is the main class of the SDK. Using this class, you can retrieve content from your Kontent.ai projects.

To create an instance of the class, you need to provide a [project ID](https://kontent.ai/learn/tutorials/develop-apps/get-content/get-content-items#a-1-find-your-project-id).
To create an instance of the class, you need to provide a [environment ID](https://kontent.ai/learn/tutorials/develop-apps/get-content/get-content-items#a-1-find-your-project-id).

```php
use Kontent\Ai\Delivery\DeliveryClient;
Expand Down Expand Up @@ -127,12 +127,12 @@ $response = $client->getTaxonomy('persona');

## Previewing unpublished content

To retrieve unpublished content, you need to create a `DeliveryClient` with both Project ID and Preview API key. Each Kontent.ai project has its own Preview API key.
To retrieve unpublished content, you need to create a `DeliveryClient` with both Environment ID and Preview API key. Each Kontent.ai project has its own Preview API key.

```php
// Note: Within a single project, we recommend that you work with only
// either the production or preview Delivery API, not both.
$client = new DeliveryClient('YOUR_PROJECT_ID', 'YOUR_PREVIEW_API_KEY');
$client = new DeliveryClient('YOUR_ENVIRONMENT_ID', 'YOUR_PREVIEW_API_KEY');
```

For more details, see [Previewing unpublished content using the Delivery API](https://kontent.ai/learn/tutorials/develop-apps/build-strong-foundation/set-up-preview#a-get-the-latest-version-of-everything).
Expand Down
6 changes: 3 additions & 3 deletions src/Kontent/Ai/Delivery/DeliveryClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ class DeliveryClient
/**
* Creates a new instance of DeliveryClient.
*
* @param string $projectId Kontent.ai Delivery API Project ID
* @param string $environmentId Kontent.ai Delivery API Environment ID
* @param string $previewApiKey Kontent.ai Delivery API Preview API key
* @param string $securedProductionApiKey Kontent.ai Delivery API Secured production API key
* @param bool $waitForLoadingNewContent Gets whether you want to wait for updated content. (Useful for webhooks.)
* @param bool $debugRequests Switches the HTTP client to debug mode
* @param int $retryAttempts Number of times the client will retry to connect to the Kontent.ai API on failures per request
*/
public function __construct(string $projectId, string $previewApiKey = null, string $securedProductionApiKey = null, bool $waitForLoadingNewContent = null, bool $debugRequests = null, int $retryAttempts = null)
public function __construct(string $environmentId, string $previewApiKey = null, string $securedProductionApiKey = null, bool $waitForLoadingNewContent = null, bool $debugRequests = null, int $retryAttempts = null)
{
$this->previewApiKey = $previewApiKey;
$this->previewMode = !is_null($previewApiKey);
$this->urlBuilder = new UrlBuilder($projectId, $this->previewMode);
$this->urlBuilder = new UrlBuilder($environmentId, $this->previewMode);
$this->securedProductionApiKey = $securedProductionApiKey;
$this->securedMode = !is_null($securedProductionApiKey);
$this->waitForLoadingNewContent = $waitForLoadingNewContent ?? $this->waitForLoadingNewContent;
Expand Down
12 changes: 6 additions & 6 deletions src/Kontent/Ai/Delivery/UrlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
class UrlBuilder
{
/**
* Gets or sets the Project identifier.
* Gets or sets the Environment identifier.
*
* @var string
*/
public $projectID = null;
public $environmentID = null;
/**
* Gets or sets whether the Preview API should be used. If TRUE, <see cref="PreviewApiKey"/> needs to be set as well.
*
Expand All @@ -37,12 +37,12 @@ class UrlBuilder
/**
* UrlBuilder constructor.
*
* @param $projectID
* @param $environmentID
* @param false $usePreviewApi
*/
public function __construct(string $projectID, bool $usePreviewApi = null)
public function __construct(string $environmentID, bool $usePreviewApi = null)
{
$this->projectID = $projectID;
$this->environmentID = $environmentID;
$this->usePreviewApi = $usePreviewApi ?? $this->usePreviewApi;
}

Expand Down Expand Up @@ -156,7 +156,7 @@ private function buildUrl($endpoint, $query = null)
{
$segments = array(
trim($this->usePreviewApi ? self::PREVIEW_ENDPOINT : self::PRODUCTION_ENDPOINT, '/'),
trim($this->projectID, '/'),
trim($this->environmentID, '/'),
trim($endpoint, '/'),
);
$url = implode('/', $segments);
Expand Down
6 changes: 3 additions & 3 deletions tests/E2E/ContentTypeFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class ContentTypeFactoryTest extends TestCase
{
public function getClient($previewApiKey = null)
{
$projectId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$environmentId = '975bf280-fd91-488c-994c-2f04416e5ee3';
if (is_null($previewApiKey)) {
return new DeliveryClient($projectId);
return new DeliveryClient($environmentId);
} else {
return new DeliveryClient($projectId, $previewApiKey);
return new DeliveryClient($environmentId, $previewApiKey);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/E2E/ModelBindingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class ModelBindingTest extends TestCase
{
public function getClient()
{
$projectId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$client = new DeliveryClient($projectId);
$environmentId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$client = new DeliveryClient($environmentId);
$client->typeMapper = new TestMapper();
$client->contentLinkUrlResolver = new CustomContentLinkUrlResolver();

Expand Down
6 changes: 3 additions & 3 deletions tests/E2E/TaxonomyFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class TaxonomyFactoryTest extends TestCase
{
public function getClient($previewApiKey = null)
{
$projectId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$environmentId = '975bf280-fd91-488c-994c-2f04416e5ee3';
if (is_null($previewApiKey)) {
return new DeliveryClient($projectId);
return new DeliveryClient($environmentId);
} else {
return new DeliveryClient($projectId, $previewApiKey);
return new DeliveryClient($environmentId, $previewApiKey);
}
}

Expand Down
32 changes: 16 additions & 16 deletions tests/Unit/UrlBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,40 @@ class UrlBuilderTest extends TestCase
{
public function testGetElement()
{
$projectId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$builder = new UrlBuilder($projectId);
$environmentId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$builder = new UrlBuilder($environmentId);
$url = $builder->getContentElementUrl('article', 'author');
$this->assertEquals('https://deliver.kontent.ai/975bf280-fd91-488c-994c-2f04416e5ee3/types/article/elements/author', $url);
}

public function testGetPreviewApi()
{
$projectId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$builder = new UrlBuilder($projectId, true);
$environmentId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$builder = new UrlBuilder($environmentId, true);
$url = $builder->getContentElementUrl('article', 'author');
$this->assertStringStartsWith('https://preview-deliver.kontent.ai', $url);
}

public function testGetTypes()
{
$projectId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$builder = new UrlBuilder($projectId);
$environmentId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$builder = new UrlBuilder($environmentId);
$url = $builder->getTypesUrl();
$this->assertEquals('https://deliver.kontent.ai/975bf280-fd91-488c-994c-2f04416e5ee3/types', $url);
}

public function testGetType()
{
$projectId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$builder = new UrlBuilder($projectId);
$environmentId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$builder = new UrlBuilder($environmentId);
$url = $builder->getTypeUrl('article');
$this->assertEquals('https://deliver.kontent.ai/975bf280-fd91-488c-994c-2f04416e5ee3/types/article', $url);
}

public function testGetItemsQuery()
{
$projectId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$builder = new UrlBuilder($projectId);
$environmentId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$builder = new UrlBuilder($environmentId);

$params = (new QueryParams())
->skip(2)
Expand Down Expand Up @@ -95,24 +95,24 @@ public function testGetItemsQuery()

public function testGetTaxonomy()
{
$projectId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$builder = new UrlBuilder($projectId);
$environmentId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$builder = new UrlBuilder($environmentId);
$url = $builder->getTaxonomyUrl('persona');
$this->assertEquals('https://deliver.kontent.ai/975bf280-fd91-488c-994c-2f04416e5ee3/taxonomies/persona', $url);
}

public function testGetTaxonomies()
{
$projectId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$builder = new UrlBuilder($projectId);
$environmentId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$builder = new UrlBuilder($environmentId);
$url = $builder->getTaxonomiesUrl();
$this->assertEquals('https://deliver.kontent.ai/975bf280-fd91-488c-994c-2f04416e5ee3/taxonomies', $url);
}

public function testGetLanguages()
{
$projectId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$builder = new UrlBuilder($projectId);
$environmentId = '975bf280-fd91-488c-994c-2f04416e5ee3';
$builder = new UrlBuilder($environmentId);
$url = $builder->getLanguagesUrl();
$this->assertEquals('https://deliver.kontent.ai/975bf280-fd91-488c-994c-2f04416e5ee3/languages', $url);
}
Expand Down

0 comments on commit b45d0b1

Please sign in to comment.