Skip to content

Commit

Permalink
Added card for ask permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf Eggert committed Oct 26, 2018
1 parent 9166bdb commit 43b22ea
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/Response/Card/AskForPermissionsConsent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Build voice applications for Amazon Alexa with phlexa and PHP
*
* @author Ralf Eggert <ralf@travello.audio>
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
* @link https://github.com/phoice/phlexa
* @link https://www.phoice.tech/
* @link https://www.travello.audio/
*/

declare(strict_types=1);

namespace Phlexa\Response\Card;

/**
* Class AskForPermissionsConsent
*
* @package Phlexa\Response\Card
*/
class AskForPermissionsConsent implements CardInterface
{
public const ALEXA_ALERTS_REMINDERS_SKILL_READWRITE = 'alexa::alerts:reminders:skill:readwrite';
public const WRITE_ALEXA_HOUSEHOLD_LIST = 'write::alexa:household:list';
public const READ_ALEXA_HOUSEHOLD_LIST = 'read::alexa:household:list';
public const READ_ALEXA_DEVICE_ALL_ADDRESS = 'read::alexa:device:all:address';
public const READ_ALEXA_DEVICE_ALL_ADDRESS_COUNTRY = 'read::alexa:device:all:address:country_and_postal_code';

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

/**
* AskForPermissionsConsent constructor.
*
* @param array $permissions
*/

public function __construct(array $permissions)
{
$this->setPermissions($permissions);
}


/**
* Render the card object to an array
*
* @return array
*/
public function toArray(): array
{
return [
'type' => 'AskForPermissionsConsent',
'permissions' => $this->permissions,
];
}

/**
* @param array $permissions
*/
private function setPermissions(array $permissions): void
{
$this->permissions = $permissions;
}
}
59 changes: 59 additions & 0 deletions test/Response/Card/AskForPermissionsConsentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Build voice applications for Amazon Alexa with phlexa and PHP
*
* @author Ralf Eggert <ralf@travello.audio>
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
* @link https://github.com/phoice/phlexa
* @link https://www.phoice.tech/
* @link https://www.travello.audio/
*/

declare(strict_types=1);

namespace PhlexaTest\Response\Card;

use Phlexa\Response\Card\AskForPermissionsConsent;
use PHPUnit\Framework\TestCase;

/**
* Class AskForPermissionsConsentTest
*
* @package PhlexaTest\Response\Card
*/
class AskForPermissionsConsentTest extends TestCase
{
/**
*
*/
public function testInstantiationRemindersSkillReadWrite(): void
{
$card = new AskForPermissionsConsent(
[AskForPermissionsConsent::ALEXA_ALERTS_REMINDERS_SKILL_READWRITE]
);

$expected = [
'type' => 'AskForPermissionsConsent',
'permissions' => [AskForPermissionsConsent::ALEXA_ALERTS_REMINDERS_SKILL_READWRITE],
];

$this->assertEquals($expected, $card->toArray());
}

/**
*
*/
public function testInstantiationDeviceAllAddress(): void
{
$card = new AskForPermissionsConsent(
[AskForPermissionsConsent::READ_ALEXA_DEVICE_ALL_ADDRESS]
);

$expected = [
'type' => 'AskForPermissionsConsent',
'permissions' => [AskForPermissionsConsent::READ_ALEXA_DEVICE_ALL_ADDRESS],
];

$this->assertEquals($expected, $card->toArray());
}
}

0 comments on commit 43b22ea

Please sign in to comment.