1 | <?php |
||
11 | class Client |
||
12 | { |
||
13 | /** |
||
14 | * API base uri |
||
15 | */ |
||
16 | const API_BASE_URI = 'https://graph.facebook.com/'; |
||
17 | |||
18 | /* |
||
19 | * API Version |
||
20 | */ |
||
21 | const DEFAULT_API_VERSION = 'v2.6'; |
||
22 | |||
23 | /** |
||
24 | * Request default timeout |
||
25 | */ |
||
26 | const DEFAULT_TIMEOUT = 60; |
||
27 | |||
28 | /** |
||
29 | * Request default file upload timeout |
||
30 | */ |
||
31 | const DEFAULT_FILE_UPLOAD_TIMEOUT = 3600; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | public static $allowedMethod = ['POST', 'GET', 'PUT', 'DELETE']; |
||
37 | |||
38 | /** |
||
39 | * @var string Wit app token |
||
40 | */ |
||
41 | private $accessToken; |
||
42 | |||
43 | /** |
||
44 | * @var ClientInterface client |
||
45 | */ |
||
46 | private $client; |
||
47 | |||
48 | /** |
||
49 | * @var ResponseInterface|null |
||
50 | */ |
||
51 | private $lastResponse; |
||
52 | |||
53 | 15 | public function __construct($accessToken, ClientInterface $httpClient = null) |
|
58 | |||
59 | /** |
||
60 | * @param string $uri |
||
61 | * @param mixed $body |
||
62 | * |
||
63 | * @return ResponseInterface |
||
64 | */ |
||
65 | 2 | public function post($uri, $body = null) |
|
69 | |||
70 | /** |
||
71 | * @param string $uri |
||
72 | * @param array $params |
||
73 | * |
||
74 | * @return ResponseInterface |
||
75 | */ |
||
76 | 1 | public function get($uri, array $params = []) |
|
80 | |||
81 | /** |
||
82 | * @param string $uri |
||
83 | * @param mixed $data |
||
84 | * |
||
85 | * @return ResponseInterface |
||
86 | */ |
||
87 | 1 | public function put($uri, $data = null) |
|
91 | |||
92 | /** |
||
93 | * @param string $uri |
||
94 | * |
||
95 | * @return ResponseInterface |
||
96 | */ |
||
97 | 1 | public function delete($uri) |
|
101 | |||
102 | /** |
||
103 | * @param string $method |
||
104 | * @param string $uri |
||
105 | * @param mixed $body |
||
106 | * @param array $query |
||
107 | * @param array $headers |
||
108 | * @param array $options |
||
109 | * |
||
110 | * @return ResponseInterface |
||
111 | * |
||
112 | * @throws ApiException |
||
113 | */ |
||
114 | 13 | public function send($method, $uri, $body = null, array $query = [], array $headers = [], array $options = []) |
|
128 | |||
129 | /** |
||
130 | * Get the last response from the API |
||
131 | * |
||
132 | * @return null|ResponseInterface |
||
133 | */ |
||
134 | 1 | public function getLastResponse() |
|
138 | |||
139 | 1 | public function getHttpClient() |
|
143 | |||
144 | /** |
||
145 | * @param ResponseInterface $response |
||
146 | * |
||
147 | * @throws ApiException |
||
148 | */ |
||
149 | 12 | private function validateResponse(ResponseInterface $response) |
|
159 | |||
160 | /** |
||
161 | * @return ClientInterface |
||
162 | */ |
||
163 | 1 | private function defaultHttpClient() |
|
171 | |||
172 | 13 | private function enhanceOptions($body = null, array $query = [], array $headers = [], array $options = []) |
|
191 | } |
||
192 |