/**
* Add an media file to mobypicture.
*
* @param string $filepath
* @param string $title
* @param string $description
* @param string $format
* @param array $options
* @throws Zend_Http_Client_Exception if HTTP request fails or times out
* @throws HausDesign_Service_Mobypicture_Exception If username is not set
* @throws HausDesign_Service_Mobypicture_Exception If file can't read.
* @throws HausDesign_Service_Mobypicture_Exception If file is larger then 16M.
* @return mixed
*/
public function postMedia($filepath, $title, $description = '', $format = self::FORMAT_XML, $options = array())
{
if (null == $this->_username || null == $this->_password) {
throw new HausDesign_Service_Mobypicture_Exception('Username and password must be set.');
}
if (!is_readable($filepath)) {
throw new HausDesign_Service_Mobypicture_Exception('File can\'t be read.');
}
if (filesize($filepath) > 16777216) {
throw new HausDesign_Service_Mobypicture_Exception('File can\'t be larger then 16M.');
}
if (strlen($title) > self::MAX_LENGTH_TITLE) {
$title = substr($title, 0, self::MAX_LENGTH_TITLE);
}
if (strlen($description) > self::MAX_LENGTH_DESCRIPTION) {
$title = substr($title, 0, self::MAX_LENGTH_DESCRIPTION);
}
$options['t'] = $title;
if ($description) {
$options['d'] = $description;
}
$this->_localHttpClient->resetParameters();
$this->_localHttpClient->setUri(self::MOBYPICTURE_API);
$this->_localHttpClient->setParameterPost('action', 'postMediaUrl');
$this->_localHttpClient->setFileUpload($filepath, 'i');
$this->_localHttpClient->setParameterPost('u', $this->_username);
$this->_localHttpClient->setParameterPost('p', $this->_password);
$this->_localHttpClient->setParameterPost('k', $this->_apiKey);
$this->_localHttpClient->setParameterPost('format', $format);
$this->_localHttpClient->setConfig(array('timeout' => 30));
foreach ($options as $option => $value) {
$this->_localHttpClient->setParameterPost($option, $value);
}
return $this->_parseContent($this->_localHttpClient->request('GET')->getBody(), $format);
}