Skip to content

Commit

Permalink
handle request
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbeckers committed Aug 3, 2017
0 parents commit db75590
Show file tree
Hide file tree
Showing 23 changed files with 878 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
composer.phar
/vendor/
composer.lock
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Maximilian Beckers <beckers.maximilian@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Amazon alexa php library
This library is a helper for google actions with php.
34 changes: 34 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "maxbeckers/google-actions-php",
"type": "library",
"description": "This library is a helper for google actions with php.",
"keywords": [
"google",
"actions",
"php"
],
"license": "MIT",
"support": {
"issues": "https://github.com/maxbeckers/google-actions-php/issues",
"source": "https://github.com/maxbeckers/google-actions-php"
},
"authors": [
{
"name": "Maximilian Beckers",
"email": "beckers.maximilian@gmail.com",
"role": "Developer"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=7.0"
},
"require-dev": {
"phpunit/phpunit": "^6.2"
},
"autoload": {
"psr-4": {
"MaxBeckers\\GoogleActions\\": "src/"
}
}
}
19 changes: 19 additions & 0 deletions examples/simple-request.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use MaxBeckers\GoogleActions\Request\Request;
use MaxBeckers\GoogleActions\Response\Response;

require '../vendor/autoload.php';

$requestBody = file_get_contents('php://input');
if ($requestBody) {
$alexaRequest = Request::fromGoogleRequest($requestBody);

// todo generate response
$response = new Response();
// render response
header('Content-Type: application/json');
echo json_encode($response);
}

exit();
28 changes: 28 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="test/bootstrap.php"
checkForUnintentionallyCoveredCode="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
verbose="true"
>
<testsuites>
<testsuite name="unit">
<directory>./test/Tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
<exclude>
<directory>./test</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
61 changes: 61 additions & 0 deletions src/Request/Argument.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace MaxBeckers\GoogleActions\Request;

/**
* @author Maximilian Beckers <beckers.maximilian@gmail.com>
*/
class Argument
{
/**
* @var string|null
*/
public $name;

/**
* @var string|null
*/
public $rawText;

/**
* @var bool
*/
public $boolValue = false;

/**
* @var string|null
*/
public $textValue;

/**
* @var DateTime|null
*/
public $datetimeValue;

/**
* TODO
*
* @var array
*/
public $extension;

/**
* @param array $googleRequest
*
* @return Argument
*/
public static function fromGoogleRequest(array $googleRequest): Argument
{
$argument = new self();

$argument->name = isset($googleRequest['name']) ? $googleRequest['name'] : null;
$argument->rawText = isset($googleRequest['rawText']) ? $googleRequest['rawText'] : null;
$argument->boolValue = isset($googleRequest['boolValue']) ? (bool)$googleRequest['boolValue'] : false;
$argument->textValue = isset($googleRequest['textValue']) ? $googleRequest['textValue'] : null;
$argument->datetimeValue = isset($googleRequest['datetimeValue']) ? DateTime::fromGoogleRequest($googleRequest['datetimeValue']) : null;
// TODO
$argument->extension = isset($googleRequest['extension']) ? (array)$googleRequest['extension'] : [];

return $argument;
}
}
28 changes: 28 additions & 0 deletions src/Request/Capability.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace MaxBeckers\GoogleActions\Request;

/**
* @author Maximilian Beckers <beckers.maximilian@gmail.com>
*/
class Capability
{
/**
* @var string|null
*/
public $name;

/**
* @param array $googleRequest
*
* @return Capability
*/
public static function fromGoogleRequest(array $googleRequest): Capability
{
$capability = new self();

$capability->name = isset($googleRequest['name']) ? $googleRequest['name'] : null;

return $capability;
}
}
44 changes: 44 additions & 0 deletions src/Request/Conversation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace MaxBeckers\GoogleActions\Request;

/**
* @author Maximilian Beckers <beckers.maximilian@gmail.com>
*/
class Conversation
{
const TYPE_UNSPECIFIED = 'TYPE_UNSPECIFIED';
const TYPE_NEW = 'NEW';
const TYPE_ACTIVE = 'ACTIVE';

/**
* @var string|null
*/
public $conversationId;

/**
* @var string|null
*/
public $type;

/**
* @var string|null
*/
public $conversationToken;

/**
* @param array $googleRequest
*
* @return Conversation
*/
public static function fromGoogleRequest(array $googleRequest): Conversation
{
$conversation = new self();

$conversation->conversationId = isset($googleRequest['conversationId']) ? $googleRequest['conversationId'] : null;
$conversation->type = isset($googleRequest['type']) ? $googleRequest['type'] : null;
$conversation->conversationToken = isset($googleRequest['conversationToken']) ? $googleRequest['conversationToken'] : null;

return $conversation;
}
}
40 changes: 40 additions & 0 deletions src/Request/Date.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace MaxBeckers\GoogleActions\Request;

/**
* @author Maximilian Beckers <beckers.maximilian@gmail.com>
*/
class Date
{
/**
* @var int|null
*/
public $year;

/**
* @var int|null
*/
public $month;

/**
* @var int|null
*/
public $day;

/**
* @param array $googleRequest
*
* @return Date
*/
public static function fromGoogleRequest(array $googleRequest): Date
{
$date = new self();

$date->year = isset($googleRequest['year']) ? (int)$googleRequest['year'] : null;
$date->month = isset($googleRequest['month']) ? (int)$googleRequest['month'] : null;
$date->day = isset($googleRequest['day']) ? (int)$googleRequest['day'] : null;

return $date;
}
}
34 changes: 34 additions & 0 deletions src/Request/DateTime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace MaxBeckers\GoogleActions\Request;

/**
* @author Maximilian Beckers <beckers.maximilian@gmail.com>
*/
class DateTime
{
/**
* @var Date|null
*/
public $date;

/**
* @var Time|null
*/
public $time;

/**
* @param array $googleRequest
*
* @return DateTime
*/
public static function fromGoogleRequest(array $googleRequest): DateTime
{
$dateTime = new self();

$dateTime->date = isset($googleRequest['date']) ? Date::fromGoogleRequest($googleRequest['date']) : null;
$dateTime->time = isset($googleRequest['time']) ? Time::fromGoogleRequest($googleRequest['time']) : null;

return $dateTime;
}
}
28 changes: 28 additions & 0 deletions src/Request/Device.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace MaxBeckers\GoogleActions\Request;

/**
* @author Maximilian Beckers <beckers.maximilian@gmail.com>
*/
class Device
{
/**
* @var Location|null
*/
public $location;

/**
* @param array $googleRequest
*
* @return Device
*/
public static function fromGoogleRequest(array $googleRequest): Device
{
$device = new self();

$device->location = isset($googleRequest['location']) ? Location::fromGoogleRequest($googleRequest['location']) : null;

return $device;
}
}
Loading

0 comments on commit db75590

Please sign in to comment.