Skip to content

Commit

Permalink
Merge pull request #10 from fabeat/master
Browse files Browse the repository at this point in the history
Display.ElementSelected Request & Hint Directive
  • Loading branch information
maxbeckers authored Dec 4, 2017
2 parents ac91c77 + cd3d1c3 commit aed8a6b
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use MaxBeckers\AmazonAlexa\Request\Request\AudioPlayer\PlaybackNearlyFinishedRequest;
use MaxBeckers\AmazonAlexa\Request\Request\AudioPlayer\PlaybackStartedRequest;
use MaxBeckers\AmazonAlexa\Request\Request\AudioPlayer\PlaybackStoppedRequest;
use MaxBeckers\AmazonAlexa\Request\Request\Display\ElementSelectedRequest;
use MaxBeckers\AmazonAlexa\Request\Request\Standard\IntentRequest;
use MaxBeckers\AmazonAlexa\Request\Request\Standard\LaunchRequest;
use MaxBeckers\AmazonAlexa\Request\Request\Standard\SessionEndedRequest;
Expand All @@ -36,6 +37,8 @@ class Request
PlaybackFailedRequest::TYPE => PlaybackFailedRequest::class,
// System types
ExceptionEncounteredRequest::TYPE => ExceptionEncounteredRequest::class,
// Display types
ElementSelectedRequest::TYPE => ElementSelectedRequest::class,
];

/**
Expand Down
28 changes: 28 additions & 0 deletions src/Request/Request/Display/ElementSelectedRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace MaxBeckers\AmazonAlexa\Request\Request\Display;

use MaxBeckers\AmazonAlexa\Request\Request\AbstractRequest;
use MaxBeckers\AmazonAlexa\Request\Request\Standard\StandardRequest;

/**
* @author Fabian Graßl <fabian.grassl@db-n.com>
*/
class ElementSelectedRequest extends StandardRequest
{
const TYPE = 'Display.ElementSelected';

/**
* {@inheritdoc}
*/
public static function fromAmazonRequest(array $amazonRequest): AbstractRequest
{
$request = new self();

$request->type = self::TYPE;
$request->token = $amazonRequest['token'];
$request->setRequestData($amazonRequest);

return $request;
}
}
28 changes: 28 additions & 0 deletions src/Response/Directives/Display/HintDirective.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace MaxBeckers\AmazonAlexa\Response\Directives\Display;

use MaxBeckers\AmazonAlexa\Response\Directives\Directive;

/**
* @author Maximilian Beckers <beckers.maximilian@gmail.com>
*/
class HintDirective extends Directive
{
const TYPE = 'Hint';

/**
* @var Text|null
*/
public $hint;

public static function create(Text $text): self
{
$hint = new self();

$hint->type = self::TYPE;
$hint->hint = $text;

return $hint;
}
}
19 changes: 19 additions & 0 deletions test/Tests/Request/ElementSelectedRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use MaxBeckers\AmazonAlexa\Request\Request\Display\ElementSelectedRequest;
use PHPUnit\Framework\TestCase;

/**
* @author Fabian Graßl <fabian.grassl@db-n.com>
*/
class ElementSelectedRequestTest extends TestCase
{
public function testFromAmazonRequest()
{
$req = ElementSelectedRequest::fromAmazonRequest(json_decode(file_get_contents(__DIR__.'/RequestData/displayElementSelected.json'), true));
$this->assertInstanceOf(ElementSelectedRequest::class, $req);
$this->assertSame($req->type, 'Display.ElementSelected');
$this->assertSame($req->requestId, 'amzn1.echo-api.request.7zzzzzzzzz');
$this->assertSame($req->locale, 'en-US');
}
}
7 changes: 7 additions & 0 deletions test/Tests/Request/RequestData/displayElementSelected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "Display.ElementSelected",
"requestId": "amzn1.echo-api.request.7zzzzzzzzz",
"timestamp": "2017-06-06T20:05:04Z",
"locale": "en-US",
"token": "getTopicName-Cookie-Contest"
}
10 changes: 10 additions & 0 deletions test/Tests/Response/Directives/DisplayTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use MaxBeckers\AmazonAlexa\Response\Directives\Display\HintDirective;
use MaxBeckers\AmazonAlexa\Response\Directives\Display\Image;
use MaxBeckers\AmazonAlexa\Response\Directives\Display\ImageSource;
use MaxBeckers\AmazonAlexa\Response\Directives\Display\ListItem;
Expand Down Expand Up @@ -127,4 +128,13 @@ public function testListItem()
$this->assertSame('TOKEN', $listItem->token);
$this->assertSame($tc, $listItem->textContent);
}

public function testHint()
{
$txt = Text::create('Test');
$hint = HintDirective::create($txt);
$this->assertInstanceOf(HintDirective::class, $hint);
$this->assertSame('Hint', $hint->type);
$this->assertSame($txt, $hint->hint);
}
}

0 comments on commit aed8a6b

Please sign in to comment.