Skip to content

Commit

Permalink
ChannelList call
Browse files Browse the repository at this point in the history
Added the channellist call for channel retrieval
  • Loading branch information
EffectConnect committed Jan 29, 2020
1 parent fc06906 commit 05a6739
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 1 deletion.
4 changes: 3 additions & 1 deletion EffectConnectSDK/Core.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace EffectConnect\PHPSdk;

use EffectConnect\PHPSdk\Core\CallType\ChannelListCall;
use EffectConnect\PHPSdk\Core\CallType\OrderCall;
use EffectConnect\PHPSdk\Core\CallType\OrderListCall;
use EffectConnect\PHPSdk\Core\CallType\ProcessCall;
Expand All @@ -20,6 +21,7 @@
*
* @method OrderCall OrderCall()
* @method OrderListCall OrderListCall()
* @method ChannelListCall ChannelListCall()
* @method ProductsCall ProductsCall()
* @method ProcessCall ProcessCall()
* @method ReportCall ReportCall()
Expand Down Expand Up @@ -79,4 +81,4 @@ final public function __call($name, $arguments)
throw new InvalidApiCallException($name);
}
}
}
}
67 changes: 67 additions & 0 deletions EffectConnectSDK/Core/CallType/ChannelListCall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
namespace EffectConnect\PHPSdk\Core\CallType;

use EffectConnect\PHPSdk\Core\Abstracts\CallType;
use EffectConnect\PHPSdk\ApiCall;
use EffectConnect\PHPSdk\Core\Exception\InvalidActionForCallTypeException;
use EffectConnect\PHPSdk\Core\Helper\Payload;
use EffectConnect\PHPSdk\Core\Interfaces\CallTypeInterface;
use EffectConnect\PHPSdk\Core\Interfaces\ResponseContainerInterface;
use EffectConnect\PHPSdk\Core\Model\Request\OrderList;
use EffectConnect\PHPSdk\Core\Model\Response\ChannelListReadResponseContainer;
use EffectConnect\PHPSdk\Core\Model\Response\OrderListReadResponseContainer;
use EffectConnect\PHPSdk\Core\Validation\ChannelListValidator;
use EffectConnect\PHPSdk\Core\Validation\OrderListValidator;

/**
* Class ChannelListCall
*
* CallType class receiving orders from the EffectConnect Api.
*
* @author Mark Thiesen
* @company Koek & Peer
* @product EffectConnect
* @package EffectConnectSDK
*
* @method ApiCall read()
*/
final class ChannelListCall extends CallType implements CallTypeInterface
{
protected $callVersion = '2.0';
protected $validatorClass = ChannelListValidator::class;

/**
* @param ApiCall $apiCall
*
* @return ApiCall
* @throws InvalidActionForCallTypeException
*/
public function _prepareCall($apiCall)
{
switch ($this->action)
{
case CallTypeInterface::ACTION_READ:
$method = 'GET';
break;
default:
throw new InvalidActionForCallTypeException();
}
$apiCall
->setUri('/channellist')
->setMethod($method)
;

return $apiCall;
}

/**
* @param $method
* @param $responsePayload
*
* @return ResponseContainerInterface
*/
public static function processResponse($method, $responsePayload)
{
return new ChannelListReadResponseContainer(Payload::extract($responsePayload, 'ChannelListReadResponseContainer'));
}
}
100 changes: 100 additions & 0 deletions EffectConnectSDK/Core/Model/Response/Channel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
namespace EffectConnect\PHPSdk\Core\Model\Response;

use EffectConnect\PHPSdk\Core\Helper\Payload;

/**
* Class Channel
*
* @author Stefan Van den Heuvel
* @company Koek & Peer
* @product EffectConnect
* @package EffectConnectSDK
*/
final class Channel
{

/**
* @var int $_id
*/
private $_id;

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

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

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

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

/**
* Channel constructor.
*
* @param $payload
*/
public function __construct($payload)
{
if ($payload === null)
{
return;
}
$this->_id = Payload::extract($payload, 'id');
$this->_type = Payload::extract($payload, 'type');
$this->_subtype = Payload::extract($payload, 'subtype');
$this->_language = Payload::extract($payload, 'language');
$this->_title = Payload::extract($payload, 'title');
}

/**
* @return int
*/
public function getId()
{
return $this->_id;
}

/**
* @return string
*/
public function getType()
{
return $this->_type;
}

/**
* @return string
*/
public function getSubtype()
{
return $this->_subtype;
}

/**
* @return string
*/
public function getLanguage()
{
return $this->_language;
}

/**
* @return string
*/
public function getTitle()
{
return $this->_title;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
namespace EffectConnect\PHPSdk\Core\Model\Response;

use EffectConnect\PHPSdk\Core\Helper\Payload;
use EffectConnect\PHPSdk\Core\Interfaces\ResponseContainerInterface;

/**
* Class ChannelListReadResponseContainer
*
* @author Stefan Van den Heuvel
* @company Koek & Peer
* @product EffectConnect
* @package EffectConnectSDK
*/
final class ChannelListReadResponseContainer implements ResponseContainerInterface
{
/**
* @var Channel[] $_orders
*/
private $_channels = [];

/**
* OrderListReadResponseContainer constructor.
*
* @param $payload
*/
public function __construct($payload)
{
if ($payload === null || $payload === '')
{
return;
}
foreach (Payload::extract($payload, 'Channels', true) as $channel)
{
$this->_channels[] = new Channel($channel);
}
}

/**
* @return Channel[]
*/
public function getChannels()
{
return $this->_channels;
}
}
35 changes: 35 additions & 0 deletions EffectConnectSDK/Core/Validation/ChannelListValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace EffectConnect\PHPSdk\Core\Validation;

use EffectConnect\PHPSdk\Core\Abstracts\Validator;
use EffectConnect\PHPSdk\Core\Exception\InvalidPayloadException;
use EffectConnect\PHPSdk\Core\Interfaces\CallTypeInterface;
use EffectConnect\PHPSdk\Core\Interfaces\CallValidatorInterface;
use EffectConnect\PHPSdk\Core\Model\Request\OrderList;

/**
* Class OrderListValidator
*
* @author Mark Thiesen
* @company Koek & Peer
* @product EffectConnect
* @package EffectConnectSDK
*
*/
final class ChannelListValidator extends Validator implements CallValidatorInterface
{
protected $validActions = [
CallTypeInterface::ACTION_READ,
];

/**
* @param $argument
*
* @return bool
* @throws InvalidPayloadException
*/
public function validateCall($argument)
{
return true;
}
}
26 changes: 26 additions & 0 deletions examples/channellist/read_channellist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
// 1. Require the SDK base file.
require_once(realpath(__DIR__.'/..').'/base.php');
/**
* @var \EffectConnect\PHPSdk\Core $effectConnectSDK
* @var \EffectConnect\PHPSdk\Core\CallType\ChannelListCall $channelListCallType
*
* 2. Get the OrderList call type.
*/
try
{
$channelListCallType = $effectConnectSDK->ChannelListCall();
} catch (Exception $exception) {
echo sprintf('Could not create call type. `%s`', $exception->getMessage());
die();
}

/**
* 4. Make the call
*/
$apiCall = $channelListCallType->read();
$apiCall->call();
/**
* 5. Handle call result
*/
require_once(realpath(__DIR__.'/..').'/result.php');

0 comments on commit 05a6739

Please sign in to comment.