1 | <?php |
||
33 | class ApiClient implements ApiClientInterface |
||
34 | { |
||
35 | /** |
||
36 | * The (base) URL used for all communication with the Slack API. |
||
37 | */ |
||
38 | const API_BASE_URL = 'https://slack.com/api/'; |
||
39 | |||
40 | /** |
||
41 | * Event triggered just before it's sent to the Slack API |
||
42 | * Any listeners are passed the request data (array) as the first argument. |
||
43 | */ |
||
44 | const EVENT_REQUEST = 'EVENT_REQUEST'; |
||
45 | |||
46 | /** |
||
47 | * Event triggered just before it's sent to the Slack API |
||
48 | * Any listeners are passed the response data (array) as the first argument. |
||
49 | */ |
||
50 | const EVENT_RESPONSE = 'EVENT_RESPONSE'; |
||
51 | |||
52 | /** |
||
53 | * @var string|null |
||
54 | */ |
||
55 | private $token; |
||
56 | |||
57 | /** |
||
58 | * @var PayloadSerializer |
||
59 | */ |
||
60 | private $payloadSerializer; |
||
61 | |||
62 | /** |
||
63 | * @var PayloadResponseSerializer |
||
64 | */ |
||
65 | private $payloadResponseSerializer; |
||
66 | |||
67 | /** |
||
68 | * @var ClientInterface |
||
69 | */ |
||
70 | private $client; |
||
71 | |||
72 | /** |
||
73 | * @var EventDispatcherInterface |
||
74 | */ |
||
75 | private $eventDispatcher; |
||
76 | |||
77 | /** |
||
78 | * @param string|null $token |
||
79 | * @param ClientInterface|null $client |
||
80 | * @param EventDispatcherInterface|null $eventDispatcher |
||
81 | */ |
||
82 | 2 | public function __construct( |
|
93 | |||
94 | /** |
||
95 | * @param PayloadInterface $payload The payload to send |
||
96 | * @param string|null $token Optional token to use during the API-call, |
||
97 | * defaults to the one configured during construction |
||
98 | * |
||
99 | * @throws SlackException If the payload could not be sent |
||
100 | * |
||
101 | * @return PayloadResponseInterface Actual class depends on the payload used, |
||
102 | * e.g. chat.postMessage will return an instance of ChatPostMessagePayloadResponse |
||
103 | */ |
||
104 | 2 | public function send(PayloadInterface $payload, $token = null) |
|
119 | |||
120 | /** |
||
121 | * @param callable $callable |
||
122 | */ |
||
123 | 1 | public function addRequestListener($callable) |
|
127 | |||
128 | /** |
||
129 | * @param callable $callable |
||
130 | */ |
||
131 | 1 | public function addResponseListener($callable) |
|
135 | |||
136 | /** |
||
137 | * @param string $method |
||
138 | * @param array $data |
||
139 | * @param string|null $token |
||
140 | * |
||
141 | * @throws SlackException |
||
142 | * |
||
143 | * @return array |
||
144 | */ |
||
145 | 1 | private function doSend($method, array $data, $token = null) |
|
176 | |||
177 | /** |
||
178 | * @param string $method |
||
179 | * @param array $payload |
||
180 | * |
||
181 | * @return RequestInterface |
||
182 | */ |
||
183 | 1 | private function createRequest($method, array $payload) |
|
194 | } |
||
195 |