Skip to content

Commit

Permalink
Merge pull request #32 from travello-gmbh/31-extend-skill-config
Browse files Browse the repository at this point in the history
Added more fields to SkillConfiguration and moved injection to the in…
  • Loading branch information
Ralf Eggert committed Nov 26, 2017
2 parents 62a403c + 0116c8a commit 9fda9ae
Show file tree
Hide file tree
Showing 23 changed files with 355 additions and 216 deletions.
26 changes: 8 additions & 18 deletions src/Application/AlexaApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace TravelloAlexaLibrary\Application;

use Psr\Container\ContainerInterface;
use TravelloAlexaLibrary\Configuration\SkillConfigurationInterface;
use TravelloAlexaLibrary\Intent\HelpIntent;
use TravelloAlexaLibrary\Intent\IntentInterface;
use TravelloAlexaLibrary\Request\AlexaRequestInterface;
Expand All @@ -36,27 +35,21 @@ class AlexaApplication implements AlexaApplicationInterface
/** @var ContainerInterface */
protected $intentManager;

/** @var SkillConfigurationInterface */
protected $skillConfiguration;

/**
* AlexaApplication constructor.
*
* @param AlexaRequestInterface $alexaRequest
* @param AlexaResponseInterface $alexaResponse
* @param ContainerInterface $intentManager
* @param SkillConfigurationInterface $skillConfiguration
* @param AlexaRequestInterface $alexaRequest
* @param AlexaResponseInterface $alexaResponse
* @param ContainerInterface $intentManager
*/
public function __construct(
AlexaRequestInterface $alexaRequest,
AlexaResponseInterface $alexaResponse,
ContainerInterface $intentManager,
SkillConfigurationInterface $skillConfiguration
ContainerInterface $intentManager
) {
$this->alexaRequest = $alexaRequest;
$this->alexaResponse = $alexaResponse;
$this->intentManager = $intentManager;
$this->skillConfiguration = $skillConfiguration;
$this->alexaRequest = $alexaRequest;
$this->alexaResponse = $alexaResponse;
$this->intentManager = $intentManager;
}

/**
Expand Down Expand Up @@ -96,10 +89,7 @@ protected function handleRequest(): bool
$intent = $this->intentManager->get(HelpIntent::NAME);
}

$intent->handle(
$this->skillConfiguration->getSmallImageUrl(),
$this->skillConfiguration->getLargeImageUrl()
);
$intent->handle();

return true;
}
Expand Down
76 changes: 76 additions & 0 deletions src/Configuration/SkillConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class SkillConfiguration implements SkillConfigurationInterface
/** @var string */
private $applicationId;

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

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

Expand All @@ -45,6 +48,15 @@ class SkillConfiguration implements SkillConfigurationInterface
/** @var string */
private $largeImageUrl;

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

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

/** @var array */
private $customData = [];

/**
* @param array $config
*
Expand Down Expand Up @@ -93,6 +105,22 @@ public function setApplicationId(string $applicationId)
$this->applicationId = $applicationId;
}

/**
* @return string
*/
public function getSkillTitle(): string
{
return $this->skillTitle;
}

/**
* @param string $skillTitle
*/
public function setSkillTitle(string $skillTitle)
{
$this->skillTitle = $skillTitle;
}

/**
* @return string
*/
Expand Down Expand Up @@ -204,4 +232,52 @@ public function setLargeImageUrl(string $largeImageUrl)
{
$this->largeImageUrl = $largeImageUrl;
}

/**
* @return string
*/
public function getBackgroundImageUrl(): string
{
return $this->backgroundImageUrl;
}

/**
* @param string $backgroundImageUrl
*/
public function setBackgroundImageUrl(string $backgroundImageUrl)
{
$this->backgroundImageUrl = $backgroundImageUrl;
}

/**
* @return string
*/
public function getBackgroundImageTitle(): string
{
return $this->backgroundImageTitle;
}

/**
* @param string $backgroundImageTitle
*/
public function setBackgroundImageTitle(string $backgroundImageTitle)
{
$this->backgroundImageTitle = $backgroundImageTitle;
}

/**
* @return array
*/
public function getCustomData(): array
{
return $this->customData;
}

/**
* @param array $customData
*/
public function setCustomData(array $customData)
{
$this->customData = $customData;
}
}
40 changes: 40 additions & 0 deletions src/Configuration/SkillConfigurationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public function getApplicationId(): string;
*/
public function setApplicationId(string $applicationId);

/**
* @return string
*/
public function getSkillTitle(): string;

/**
* @param string $skillTitle
*/
public function setSkillTitle(string $skillTitle);

/**
* @return string
*/
Expand Down Expand Up @@ -114,4 +124,34 @@ public function getLargeImageUrl(): string;
* @param string $largeImageUrl
*/
public function setLargeImageUrl(string $largeImageUrl);

/**
* @return string
*/
public function getBackgroundImageUrl(): string;

/**
* @param string $backgroundImageUrl
*/
public function setBackgroundImageUrl(string $backgroundImageUrl);

/**
* @return string
*/
public function getBackgroundImageTitle(): string;

/**
* @param string $backgroundImageTitle
*/
public function setBackgroundImageTitle(string $backgroundImageTitle);

/**
* @return array
*/
public function getCustomData(): array;

/**
* @param array $customData
*/
public function setCustomData(array $customData);
}
31 changes: 27 additions & 4 deletions src/Intent/AbstractIntent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace TravelloAlexaLibrary\Intent;

use TravelloAlexaLibrary\Configuration\SkillConfigurationInterface;
use TravelloAlexaLibrary\TextHelper\TextHelperInterface;
use TravelloAlexaLibrary\Request\AlexaRequest;
use TravelloAlexaLibrary\Response\AlexaResponse;
Expand All @@ -31,21 +32,27 @@ abstract class AbstractIntent implements IntentInterface
/** @var TextHelperInterface */
private $textHelper;

/** @var SkillConfigurationInterface */
private $skillConfiguration;

/**
* AbstractIntent constructor.
*
* @param AlexaRequest $alexaRequest
* @param AlexaResponse $alexaResponse
* @param TextHelperInterface $textHelper
* @param AlexaRequest $alexaRequest
* @param AlexaResponse $alexaResponse
* @param TextHelperInterface $textHelper
* @param SkillConfigurationInterface $skillConfiguration
*/
public function __construct(
AlexaRequest $alexaRequest,
AlexaResponse $alexaResponse,
TextHelperInterface $textHelper
TextHelperInterface $textHelper,
SkillConfigurationInterface $skillConfiguration
) {
$this->setAlexaRequest($alexaRequest);
$this->setAlexaResponse($alexaResponse);
$this->setTextHelper($textHelper);
$this->setSkillConfiguration($skillConfiguration);
}

/**
Expand Down Expand Up @@ -95,4 +102,20 @@ protected function getTextHelper(): TextHelperInterface
{
return $this->textHelper;
}

/**
* @param SkillConfigurationInterface $skillConfiguration
*/
private function setSkillConfiguration(SkillConfigurationInterface $skillConfiguration)
{
$this->skillConfiguration = $skillConfiguration;
}

/**
* @return SkillConfigurationInterface
*/
protected function getSkillConfiguration(): SkillConfigurationInterface
{
return $this->skillConfiguration;
}
}
5 changes: 1 addition & 4 deletions src/Intent/AudioPlayer/PlaybackFinishedIntent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ class PlaybackFinishedIntent extends AbstractIntent
const NAME = 'AudioPlayer.PlaybackFinished';

/**
* @param string $smallImageUrl
* @param string $largeImageUrl
*
* @return AlexaResponse
*/
public function handle(string $smallImageUrl, string $largeImageUrl): AlexaResponse
public function handle(): AlexaResponse
{
$this->getAlexaResponse()->endSession();

Expand Down
5 changes: 1 addition & 4 deletions src/Intent/AudioPlayer/PlaybackNearlyFinishedIntent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ class PlaybackNearlyFinishedIntent extends AbstractIntent
const NAME = 'AudioPlayer.PlaybackNearlyFinished';

/**
* @param string $smallImageUrl
* @param string $largeImageUrl
*
* @return AlexaResponse
*/
public function handle(string $smallImageUrl, string $largeImageUrl): AlexaResponse
public function handle(): AlexaResponse
{
$this->getAlexaResponse()->endSession();

Expand Down
5 changes: 1 addition & 4 deletions src/Intent/AudioPlayer/PlaybackStartedIntent.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ class PlaybackStartedIntent extends AbstractIntent
const NAME = 'AudioPlayer.PlaybackStarted';

/**
* @param string $smallImageUrl
* @param string $largeImageUrl
*
* @return AlexaResponse
*/
public function handle(string $smallImageUrl, string $largeImageUrl): AlexaResponse
public function handle(): AlexaResponse
{
$this->getAlexaResponse()->addDirective(
new ClearQueue(ClearQueue::CLEAR_BEHAVIOR_CLEAR_ENQUEUED)
Expand Down
5 changes: 1 addition & 4 deletions src/Intent/AudioPlayer/PlaybackStoppedIntent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ class PlaybackStoppedIntent extends AbstractIntent
const NAME = 'AudioPlayer.PlaybackStopped';

/**
* @param string $smallImageUrl
* @param string $largeImageUrl
*
* @return AlexaResponse
*/
public function handle(string $smallImageUrl, string $largeImageUrl): AlexaResponse
public function handle(): AlexaResponse
{
$this->getAlexaResponse()->endSession();

Expand Down
8 changes: 4 additions & 4 deletions src/Intent/CancelIntent.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class CancelIntent extends AbstractIntent
const NAME = 'AMAZON.CancelIntent';

/**
* @param string $smallImageUrl
* @param string $largeImageUrl
*
* @return AlexaResponse
*/
public function handle(string $smallImageUrl, string $largeImageUrl): AlexaResponse
public function handle(): AlexaResponse
{
$smallImageUrl = $this->getSkillConfiguration()->getSmallImageUrl();
$largeImageUrl = $this->getSkillConfiguration()->getLargeImageUrl();

$title = $this->getTextHelper()->getCancelTitle();
$message = $this->getTextHelper()->getCancelMessage();

Expand Down
8 changes: 4 additions & 4 deletions src/Intent/HelpIntent.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class HelpIntent extends AbstractIntent
const NAME = 'AMAZON.HelpIntent';

/**
* @param string $smallImageUrl
* @param string $largeImageUrl
*
* @return AlexaResponse
*/
public function handle(string $smallImageUrl, string $largeImageUrl): AlexaResponse
public function handle(): AlexaResponse
{
$smallImageUrl = $this->getSkillConfiguration()->getSmallImageUrl();
$largeImageUrl = $this->getSkillConfiguration()->getLargeImageUrl();

$title = $this->getTextHelper()->getHelpTitle();
$message = $this->getTextHelper()->getHelpMessage();

Expand Down
5 changes: 1 addition & 4 deletions src/Intent/IntentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
interface IntentInterface
{
/**
* @param string $smallImageUrl
* @param string $largeImageUrl
*
* @return AlexaResponse
*/
public function handle(string $smallImageUrl, string $largeImageUrl): AlexaResponse;
public function handle(): AlexaResponse;
}
8 changes: 4 additions & 4 deletions src/Intent/LaunchIntent.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class LaunchIntent extends AbstractIntent
const NAME = 'AMAZON.LaunchIntent';

/**
* @param string $smallImageUrl
* @param string $largeImageUrl
*
* @return AlexaResponse
*/
public function handle(string $smallImageUrl, string $largeImageUrl): AlexaResponse
public function handle(): AlexaResponse
{
$smallImageUrl = $this->getSkillConfiguration()->getSmallImageUrl();
$largeImageUrl = $this->getSkillConfiguration()->getLargeImageUrl();

$title = $this->getTextHelper()->getLaunchTitle();
$message = $this->getTextHelper()->getLaunchMessage();

Expand Down
Loading

0 comments on commit 9fda9ae

Please sign in to comment.