1 | <?php |
||
11 | class Client |
||
12 | { |
||
13 | /** |
||
14 | * API base uri |
||
15 | */ |
||
16 | const API_BASE_URI = 'https://api.wit.ai/'; |
||
17 | |||
18 | /* |
||
19 | * API Version |
||
20 | */ |
||
21 | const API_VERSION = '20160330'; |
||
22 | |||
23 | /** |
||
24 | * Request default timeout |
||
25 | */ |
||
26 | const DEFAULT_TIMEOUT = 5; |
||
27 | |||
28 | /** |
||
29 | * @var HTTP client |
||
30 | */ |
||
31 | private $client; |
||
32 | |||
33 | /** |
||
34 | * @var LoggerInterface |
||
35 | */ |
||
36 | private $logger; |
||
37 | |||
38 | /** |
||
39 | * @var ResponseInterface|null |
||
40 | */ |
||
41 | private $lastResponse; |
||
42 | |||
43 | /** |
||
44 | * @var string Wit app token |
||
45 | */ |
||
46 | private $accessToken; |
||
47 | |||
48 | 7 | public function __construct($accessToken, $httpClient = null, LoggerInterface $logger = null) |
|
58 | |||
59 | /** |
||
60 | * @param string $method |
||
61 | * @param string $uri |
||
62 | * @param array $query |
||
63 | * @param mixed $content |
||
64 | * |
||
65 | * @return ResponseInterface |
||
66 | */ |
||
67 | 5 | public function send($method, $uri, array $query = [], $content = null) |
|
85 | |||
86 | /** |
||
87 | * Get the last response from the API |
||
88 | * |
||
89 | * @return null|ResponseInterface |
||
90 | */ |
||
91 | 1 | public function getLastResponse() |
|
95 | |||
96 | 1 | public function getClient() |
|
100 | |||
101 | /** |
||
102 | * Get the defaults headers like the Authorization field |
||
103 | * |
||
104 | * @return array |
||
105 | */ |
||
106 | 5 | protected function getDefaultHeaders() |
|
114 | |||
115 | /** |
||
116 | * @param ResponseInterface $response |
||
117 | * |
||
118 | * @return bool |
||
119 | * |
||
120 | * @throws BadResponseException |
||
121 | */ |
||
122 | 5 | protected function validateResponse(ResponseInterface $response) |
|
132 | } |
||
133 |