Skip to content

Commit

Permalink
Update to use new submodule structure (#52)
Browse files Browse the repository at this point in the history
* Update to use new submodule structure

* Add missing post and put  integration tests

* Fix cache tests

* revert .githhub/workflows/ci.yml

* fix cache testsuite not running

Co-authored-by: Kieran Brahney <kieran@supportpal.com>
  • Loading branch information
Gaitholabi and bytestream committed Oct 25, 2020
1 parent e3e4e1b commit 91c843f
Show file tree
Hide file tree
Showing 118 changed files with 1,605 additions and 474 deletions.
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<directory>test/E2E</directory>
</testsuite>
<testsuite name="cache">
<directory>test/cache</directory>
<directory>test/Cache</directory>
</testsuite>
</testsuites>

Expand Down
41 changes: 17 additions & 24 deletions src/Api.php → src/Api/Api.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
<?php declare(strict_types=1);

namespace SupportPal\ApiClient;
namespace SupportPal\ApiClient\Api;

use Psr\Http\Message\ResponseInterface;
use SupportPal\ApiClient\Api\CoreApis;
use SupportPal\ApiClient\Api\SelfServiceApis;
use SupportPal\ApiClient\Api\TicketApis;
use SupportPal\ApiClient\Api\UserApis;
use SupportPal\ApiClient\ApiClient;
use SupportPal\ApiClient\ApiClient\CoreApiClient;
use SupportPal\ApiClient\ApiClient\SelfServiceApiClient;
use SupportPal\ApiClient\ApiClient\TicketApiClient;
use SupportPal\ApiClient\ApiClient\UserApiClient;
use SupportPal\ApiClient\Converter\ModelToArrayConverter;
use SupportPal\ApiClient\Factory\Collection\CollectionFactory;
use SupportPal\ApiClient\Factory\ModelCollectionFactory;
use Symfony\Component\Serializer\Encoder\DecoderInterface;

class Api
abstract class Api
{
use CoreApis;
use SelfServiceApis;
use TicketApis;
use UserApis;
use ApiAware;

/** @var UserApiClient|SelfServiceApiClient|TicketApiClient|CoreApiClient|ApiClient */
protected $apiClient;

/** @var ModelToArrayConverter */
private $modelToArrayConverter;

/** @var ApiClient */
private $apiClient;

/** @var string */
private $formatType;

Expand All @@ -39,18 +37,18 @@ class Api

public function __construct(
ModelToArrayConverter $modelToArrayConverter,
ApiClient $apiClient,
ModelCollectionFactory $modelCollectionFactory,
string $formatType,
DecoderInterface $decoder,
CollectionFactory $collectionFactory
CollectionFactory $collectionFactory,
ApiClient $apiClient
) {
$this->modelToArrayConverter = $modelToArrayConverter;
$this->apiClient = $apiClient;
$this->formatType = $formatType;
$this->modelCollectionFactory = $modelCollectionFactory;
$this->decoder = $decoder;
$this->collectionFactory = $collectionFactory;
$this->apiClient = $apiClient;
}

/**
Expand All @@ -61,14 +59,6 @@ protected function getModelToArrayConverter(): ModelToArrayConverter
return $this->modelToArrayConverter;
}

/**
* @inheritDoc
*/
protected function getApiClient(): ApiClient
{
return $this->apiClient;
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -105,6 +95,9 @@ protected function decodeBody(ResponseInterface $response): array
return $body;
}

/**
* @return CollectionFactory
*/
protected function getCollectionFactory(): CollectionFactory
{
return $this->collectionFactory;
Expand Down
6 changes: 0 additions & 6 deletions src/Api/ApiAware.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace SupportPal\ApiClient\Api;

use Psr\Http\Message\ResponseInterface;
use SupportPal\ApiClient\ApiClient;
use SupportPal\ApiClient\Converter\ModelToArrayConverter;
use SupportPal\ApiClient\Factory\Collection\CollectionFactory;
use SupportPal\ApiClient\Factory\ModelCollectionFactory;
Expand All @@ -16,11 +15,6 @@
*/
trait ApiAware
{
/**
* @return ApiClient
*/
abstract protected function getApiClient(): ApiClient;

/**
* @return ModelCollectionFactory
*/
Expand Down
3 changes: 3 additions & 0 deletions src/Api/Core/BrandApis.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SupportPal\ApiClient\Api\Core;

use SupportPal\ApiClient\Api\ApiAware;
use SupportPal\ApiClient\ApiClient\CoreApiClient;
use SupportPal\ApiClient\Exception\HttpResponseException;
use SupportPal\ApiClient\Exception\InvalidArgumentException;
use SupportPal\ApiClient\Model\Collection\Collection;
Expand Down Expand Up @@ -52,4 +53,6 @@ private function createBrand(array $data): Brand

return $model;
}

abstract protected function getApiClient(): CoreApiClient;
}
7 changes: 5 additions & 2 deletions src/Api/Core/SettingsApis.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SupportPal\ApiClient\Api\Core;

use SupportPal\ApiClient\Api\ApiAware;
use SupportPal\ApiClient\ApiClient\CoreApiClient;
use SupportPal\ApiClient\Exception\HttpResponseException;
use SupportPal\ApiClient\Model\Shared\Settings;

Expand All @@ -19,12 +20,14 @@ trait SettingsApis
* @return Settings
* @throws HttpResponseException
*/
public function getCoreSettings(): Settings
public function getSettings(): Settings
{
$response = $this->getApiClient()->getCoreSettings();
$response = $this->getApiClient()->getSettings();
/** @var Settings $model */
$model = $this->getModelCollectionFactory()->create(Settings::class, $this->decodeBody($response)['data']);

return $model;
}

abstract protected function getApiClient(): CoreApiClient;
}
14 changes: 13 additions & 1 deletion src/Api/CoreApis.php → src/Api/CoreApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@

use SupportPal\ApiClient\Api\Core\BrandApis;
use SupportPal\ApiClient\Api\Core\SettingsApis;
use SupportPal\ApiClient\ApiClient\CoreApiClient;

/**
* Contains all ApiCalls pre and post processing that falls under Core Module
* Trait CoreApis
* @package SupportPal\ApiClient\Api
*/
trait CoreApis
class CoreApi extends Api
{
use BrandApis;
use SettingsApis;

/** @var CoreApiClient */
protected $apiClient;

/**
* @return CoreApiClient
*/
protected function getApiClient(): CoreApiClient
{
return $this->apiClient;
}
}
3 changes: 3 additions & 0 deletions src/Api/SelfService/ArticleApis.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SupportPal\ApiClient\Api\SelfService;

use SupportPal\ApiClient\Api\ApiAware;
use SupportPal\ApiClient\ApiClient\SelfServiceApiClient;
use SupportPal\ApiClient\Exception\HttpResponseException;
use SupportPal\ApiClient\Exception\InvalidArgumentException;
use SupportPal\ApiClient\Model\Collection\Collection;
Expand Down Expand Up @@ -92,4 +93,6 @@ private function createArticle(array $data): Article

return $model;
}

abstract protected function getApiClient(): SelfServiceApiClient;
}
3 changes: 3 additions & 0 deletions src/Api/SelfService/CategoryApis.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SupportPal\ApiClient\Api\SelfService;

use SupportPal\ApiClient\Api\ApiAware;
use SupportPal\ApiClient\ApiClient\SelfServiceApiClient;
use SupportPal\ApiClient\Exception\HttpResponseException;
use SupportPal\ApiClient\Exception\InvalidArgumentException;
use SupportPal\ApiClient\Model\Collection\Collection;
Expand Down Expand Up @@ -56,4 +57,6 @@ private function createCategory(array $data): Category

return $model;
}

abstract protected function getApiClient(): SelfServiceApiClient;
}
5 changes: 4 additions & 1 deletion src/Api/SelfService/CommentApis.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SupportPal\ApiClient\Api\SelfService;

use SupportPal\ApiClient\Api\ApiAware;
use SupportPal\ApiClient\ApiClient\SelfServiceApiClient;
use SupportPal\ApiClient\Exception\HttpResponseException;
use SupportPal\ApiClient\Exception\InvalidArgumentException;
use SupportPal\ApiClient\Model\Collection\Collection;
Expand Down Expand Up @@ -37,7 +38,7 @@ public function postComment(Comment $comment): Comment
);
}

$response = $this->getApiClient()->postSelfServiceComment($commentArray);
$response = $this->getApiClient()->postComment($commentArray);

return $this->createComment($this->decodeBody($response)['data']);
}
Expand Down Expand Up @@ -80,4 +81,6 @@ private function createComment(array $data): Comment

return $model;
}

abstract protected function getApiClient(): SelfServiceApiClient;
}
7 changes: 5 additions & 2 deletions src/Api/SelfService/SettingsApis.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SupportPal\ApiClient\Api\SelfService;

use SupportPal\ApiClient\Api\ApiAware;
use SupportPal\ApiClient\ApiClient\SelfServiceApiClient;
use SupportPal\ApiClient\Exception\HttpResponseException;
use SupportPal\ApiClient\Model\Shared\Settings;

Expand All @@ -18,12 +19,14 @@ trait SettingsApis
* @return Settings
* @throws HttpResponseException
*/
public function getSelfServiceSettings(): Settings
public function getSettings(): Settings
{
$response = $this->getApiClient()->getSelfServiceSettings();
$response = $this->getApiClient()->getSettings();
/** @var Settings $model */
$model = $this->getModelCollectionFactory()->create(Settings::class, $this->decodeBody($response)['data']);

return $model;
}

abstract protected function getApiClient(): SelfServiceApiClient;
}
3 changes: 3 additions & 0 deletions src/Api/SelfService/TagApis.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SupportPal\ApiClient\Api\SelfService;

use SupportPal\ApiClient\Api\ApiAware;
use SupportPal\ApiClient\ApiClient\SelfServiceApiClient;
use SupportPal\ApiClient\Exception\HttpResponseException;
use SupportPal\ApiClient\Exception\InvalidArgumentException;
use SupportPal\ApiClient\Model\Collection\Collection;
Expand Down Expand Up @@ -55,4 +56,6 @@ private function createTag(array $data): SelfServiceTagAlias

return $model;
}

abstract protected function getApiClient(): SelfServiceApiClient;
}
3 changes: 3 additions & 0 deletions src/Api/SelfService/TypeApis.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SupportPal\ApiClient\Api\SelfService;

use SupportPal\ApiClient\Api\ApiAware;
use SupportPal\ApiClient\ApiClient\SelfServiceApiClient;
use SupportPal\ApiClient\Exception\HttpResponseException;
use SupportPal\ApiClient\Exception\InvalidArgumentException;
use SupportPal\ApiClient\Model\Collection\Collection;
Expand Down Expand Up @@ -56,4 +57,6 @@ private function createType(array $data): Type

return $model;
}

abstract protected function getApiClient(): SelfServiceApiClient;
}
14 changes: 13 additions & 1 deletion src/Api/SelfServiceApis.php → src/Api/SelfServiceApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,30 @@
use SupportPal\ApiClient\Api\SelfService\SettingsApis;
use SupportPal\ApiClient\Api\SelfService\TagApis;
use SupportPal\ApiClient\Api\SelfService\TypeApis;
use SupportPal\ApiClient\ApiClient\SelfServiceApiClient;

/**
* Contains all ApiCalls pre and post processing that falls under SelfService Module
* Trait SelfServiceApis
* @package SupportPal\ApiClient\Api
*/
trait SelfServiceApis
class SelfServiceApi extends Api
{
use ArticleApis;
use CategoryApis;
use CommentApis;
use SettingsApis;
use TagApis;
use TypeApis;

/** @var SelfServiceApiClient */
protected $apiClient;

/**
* @return SelfServiceApiClient
*/
protected function getApiClient(): SelfServiceApiClient
{
return $this->apiClient;
}
}
11 changes: 7 additions & 4 deletions src/Api/Ticket/AttachmentApis.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SupportPal\ApiClient\Api\Ticket;

use SupportPal\ApiClient\Api\ApiAware;
use SupportPal\ApiClient\ApiClient\TicketApiClient;
use SupportPal\ApiClient\Exception\HttpResponseException;
use SupportPal\ApiClient\Exception\InvalidArgumentException;
use SupportPal\ApiClient\Model\Collection\Collection;
Expand All @@ -20,9 +21,9 @@ trait AttachmentApis
* @throws HttpResponseException
* @throws InvalidArgumentException
*/
public function getTicketAttachments(array $queryParameters = []): Collection
public function getAttachments(array $queryParameters = []): Collection
{
$response = $this->getApiClient()->getTicketAttachments($queryParameters);
$response = $this->getApiClient()->getAttachments($queryParameters);
$body = $this->decodeBody($response);
$models = array_map([$this, 'createAttachment'], $body['data']);

Expand All @@ -34,9 +35,9 @@ public function getTicketAttachments(array $queryParameters = []): Collection
* @return Attachment
* @throws HttpResponseException
*/
public function getTicketAttachment(int $attachmentId): Attachment
public function getAttachment(int $attachmentId): Attachment
{
$response = $this->getApiClient()->getTicketAttachment($attachmentId);
$response = $this->getApiClient()->getAttachment($attachmentId);

return $this->createAttachment($this->decodeBody($response)['data']);
}
Expand All @@ -52,4 +53,6 @@ private function createAttachment(array $data): Attachment

return $model;
}

abstract protected function getApiClient(): TicketApiClient;
}
3 changes: 3 additions & 0 deletions src/Api/Ticket/ChannelSettingsApis.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SupportPal\ApiClient\Api\Ticket;

use SupportPal\ApiClient\Api\ApiAware;
use SupportPal\ApiClient\ApiClient\TicketApiClient;
use SupportPal\ApiClient\Exception\HttpResponseException;
use SupportPal\ApiClient\Model\Ticket\ChannelSettings;

Expand All @@ -29,4 +30,6 @@ public function getChannelSettings(string $channel): ChannelSettings

return $model;
}

abstract protected function getApiClient(): TicketApiClient;
}

0 comments on commit 91c843f

Please sign in to comment.