Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applied fixes from StyleCI #5

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@
"require": {
"php": ">=5.5.0",
"guzzlehttp/guzzle": "^6.2"
},

"require-dev": {
"phpunit/phpunit": "~5.6"
}

}
24 changes: 24 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="API.AI Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
18 changes: 8 additions & 10 deletions src/ActionMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,30 @@
use ApiAi\Model\Context;

/**
* Class ActionMapping
*
* @package ApiAi
* Class ActionMapping.
*/
abstract class ActionMapping
{
/**
* @param string $sessionId
* @param string $action
* @param array $parameters
* @param string $sessionId
* @param string $action
* @param array $parameters
* @param Context[] $contexts
*
* @return
*/
abstract public function action($sessionId, $action, $parameters, $contexts);

/**
* @param string $sessionId
* @param string $speech
* @param string $sessionId
* @param string $speech
* @param Context[] $contexts
*/
abstract public function speech($sessionId, $speech, $contexts);

/**
* @param string $sessionId
* @param string $sessionId
* @param \Exception|string $error
*/
abstract public function error($sessionId, $error);

}
50 changes: 24 additions & 26 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,43 @@

namespace ApiAi;

use ApiAi\HttpClient\HttpClient;
use ApiAi\HttpClient\GuzzleHttpClient;
use ApiAi\Exception\BadResponseException;
use ApiAi\HttpClient\GuzzleHttpClient;
use ApiAi\HttpClient\HttpClient;
use Psr\Http\Message\ResponseInterface;

/**
* Class Client
*
* @package ApiAi
* Class Client.
*/
class Client
{
/**
* API Base url
* API Base url.
*/
const API_BASE_URI = 'https://api.api.ai/';

/**
* API Version
* API Version.
*/
const DEFAULT_API_VERSION = '20150910';

/**
* API Endpoint
* API Endpoint.
*/
const DEFAULT_API_ENDPOINT = 'v1/';

/**
* API Default Language
* API Default Language.
*/
const DEFAULT_API_LANGUAGE = 'en';

/**
* API Default Source
* API Default Source.
*/
const DEFAULT_API_SOURCE = 'php';

/**
* Request default timeout
* Request default timeout.
*/
const DEFAULT_TIMEOUT = 5;

Expand Down Expand Up @@ -77,10 +75,10 @@ class Client
/**
* Client constructor.
*
* @param string $accessToken
* @param string $accessToken
* @param HttpClient|null $httpClient
* @param string $apiLanguage
* @param string $apiVersion
* @param string $apiLanguage
* @param string $apiVersion
*/
public function __construct($accessToken, HttpClient $httpClient = null, $apiLanguage = self::DEFAULT_API_LANGUAGE, $apiVersion = self::DEFAULT_API_VERSION)
{
Expand Down Expand Up @@ -136,7 +134,7 @@ public function getLastResponse()

/**
* @param string $uri
* @param array $params
* @param array $params
*
* @return ResponseInterface
*/
Expand All @@ -147,7 +145,7 @@ public function get($uri, array $params = [])

/**
* @param string $uri
* @param array $params
* @param array $params
*
* @return ResponseInterface
*/
Expand All @@ -159,10 +157,10 @@ public function post($uri, array $params = [])
/**
* @param string $method
* @param string $uri
* @param mixed $body
* @param array $query
* @param array $headers
* @param array $options
* @param mixed $body
* @param array $query
* @param array $headers
* @param array $options
*
* @return ResponseInterface
*/
Expand Down Expand Up @@ -193,6 +191,7 @@ private function validateMethod($method)

/**
* @param ResponseInterface $response
*
* @throws BadResponseException
*/
private function validateResponse(ResponseInterface $response)
Expand All @@ -204,30 +203,29 @@ private function validateResponse(ResponseInterface $response)
}

/**
* Get the defaults query
* Get the defaults query.
*
* @return array
*/
private function getDefaultQuery()
{
return [
'v' => $this->apiVersion,
'v' => $this->apiVersion,
'lang' => $this->apiLanguage,
];
}

/**
* Get the defaults headers
* Get the defaults headers.
*
* @return array
*/
private function getDefaultHeaders()
{
return [
'Content-Type' => 'application/json; charset=utf-8',
'Authorization' => 'Bearer ' . $this->accessToken,
'Content-Type' => 'application/json; charset=utf-8',
'Authorization' => 'Bearer '.$this->accessToken,
'api-request-source' => self::DEFAULT_API_SOURCE,
];
}

}
19 changes: 8 additions & 11 deletions src/Dialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

namespace ApiAi;

use ApiAi\Exception\DialogException;
use ApiAi\Exception\InvalidStepException;
use ApiAi\Method\QueryApi;
use ApiAi\Model\Query;
use ApiAi\Model\Step;
use ApiAi\Model\Step\Action;
use ApiAi\Model\Step\Speech;
use ApiAi\Exception\DialogException;
use ApiAi\Exception\InvalidStepException;

/**
* Class Dialog
*
* @package ApiAi
* Class Dialog.
*/
class Dialog
{
Expand All @@ -30,7 +28,7 @@ class Dialog
/**
* Dialog constructor.
*
* @param QueryApi $queryApi
* @param QueryApi $queryApi
* @param ActionMapping $actionMapping
*/
public function __construct(QueryApi $queryApi, ActionMapping $actionMapping)
Expand All @@ -42,7 +40,7 @@ public function __construct(QueryApi $queryApi, ActionMapping $actionMapping)
/**
* @param string $sessionId
* @param string $message
* @param array $contexts
* @param array $contexts
*
* @return bool|void
*/
Expand All @@ -60,15 +58,15 @@ public function create($sessionId, $message, $contexts = [])
/**
* @param string $sessionId
* @param string $message
* @param array $contexts
* @param array $contexts
*
* @return Action|Speech
*/
private function getStep($sessionId, $message, $contexts = [])
{
$query = $this->queryApi->extractMeaning($message, [
'sessionId' => $sessionId,
'contexts' => $contexts,
'contexts' => $contexts,
]);

$query = new Query($query);
Expand All @@ -92,7 +90,7 @@ private function getStep($sessionId, $message, $contexts = [])

/**
* @param string $sessionId
* @param Step $step
* @param Step $step
*
* @return bool
*/
Expand All @@ -109,5 +107,4 @@ private function performStep($sessionId, Step $step)

return false;
}

}
6 changes: 2 additions & 4 deletions src/Exception/BadResponseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
use Psr\Http\Message\ResponseInterface;

/**
* Class BadResponseException
*
* @package ApiAi\Exception
* Class BadResponseException.
*/
class BadResponseException extends \RuntimeException
{
Expand All @@ -19,7 +17,7 @@ class BadResponseException extends \RuntimeException
/**
* BadResponseException constructor.
*
* @param string $message
* @param string $message
* @param ResponseInterface $response
*/
public function __construct($message, ResponseInterface $response)
Expand Down
5 changes: 1 addition & 4 deletions src/Exception/DialogException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
use ApiAi\Model\Query;

/**
* Class DialogException
*
* @package ApiAi\Exception
* Class DialogException.
*/
class DialogException extends \RuntimeException
{
Expand Down Expand Up @@ -44,5 +42,4 @@ public function getQuery()
{
return $this->query;
}

}
7 changes: 2 additions & 5 deletions src/Exception/InvalidStepException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
use ApiAi\Model\Query;

/**
* Class InvalidStepException
*
* @package ApiAi\Exception
* Class InvalidStepException.
*/
class InvalidStepException extends \RuntimeException
{
Expand All @@ -20,7 +18,7 @@ class InvalidStepException extends \RuntimeException
* InvalidStepException constructor.
*
* @param string $message
* @param Query $query
* @param Query $query
*/
public function __construct($message, Query $query)
{
Expand All @@ -36,5 +34,4 @@ public function getQuery()
{
return $this->query;
}

}
Loading