private function build_attachment($name, $filename, $content, $mime_type, $size)
{
// Ensure the file isn't empty
if (empty($content)) {
throw new Request_Exception(sprintf(__('The attachment %s could not be included in the request because it was empty.', 'apple-news'), esc_html($filename)));
}
// Ensure a valid size was provided
if (0 >= intval($size)) {
throw new Request_Exception(sprintf(__('The attachment %s could not be included in the request because its size was %s.', 'apple-news'), esc_html($filename), esc_html($size)));
}
// Build the attachment
$attachment = '--' . $this->boundary . $this->eol;
$attachment .= 'Content-Type: ' . $mime_type . $this->eol;
$attachment .= 'Content-Disposition: form-data; name=' . $name . '; filename=' . $filename . '; size=' . $size . $this->eol . $this->eol;
$this->debug_content .= $attachment;
$attachment .= $content . $this->eol;
if ('application/json' === $mime_type) {
$this->debug_content .= $content . $this->eol;
} else {
$this->debug_content .= "(binary contents of {$filename})" . $this->eol;
}
return $attachment;
}