public function post($endpointUrl, array $postData = [], $files = [])
{
$postFiles = [];
$fields = ['message', 'attachment', 'inline'];
foreach ($fields as $fieldName) {
if (isset($files[$fieldName])) {
if (is_array($files[$fieldName])) {
$fileIndex = 0;
foreach ($files[$fieldName] as $file) {
$postFiles[] = $this->prepareFile($fieldName, $file, $fileIndex);
++$fileIndex;
}
} else {
$postFiles[] = $this->prepareFile($fieldName, $files[$fieldName]);
}
}
}
$postDataMultipart = [];
foreach ($postData as $key => $value) {
if (is_array($value)) {
$index = 0;
foreach ($value as $subValue) {
$postDataMultipart[] = ['name' => sprintf('%s[%d]', $key, $index++), 'contents' => $subValue];
}
} else {
$postDataMultipart[] = ['name' => $key, 'contents' => $value];
}
}
return $this->send('POST', $endpointUrl, [], array_merge($postDataMultipart, $postFiles));
}