Commit 42505f86 authored by keven's avatar keven
Browse files

[Client] Added `SendFile` command

git-svn-id: https://svn.libcast.net/libcast/component/Client/branches/2.1@5623 59603aea-79bc-4624-862a-e4db60f57f7e
parent eb2ee0b2
......@@ -159,7 +159,7 @@ abstract class Command implements CommandInterface
}
/* @var $response Response */
$response = $client->request($this->method, $url, $this->getPayload());
$response = $client->request($this->method, $url, $this->getPayload(), $this->getRequestHeaders(), $this->getRequestOptions());
if (!empty($transaction)) {
$client->setHeader('X-Transaction', $transaction);
......@@ -177,6 +177,24 @@ abstract class Command implements CommandInterface
return $this->process($response, $serializer);
}
/**
*
* @return array
*/
protected function getRequestHeaders()
{
return array();
}
/**
*
* @return array
*/
protected function getRequestOptions()
{
return array();
}
/**
*
* @todo This should use a real URI Template resolver
......
<?php
namespace Libcast\Client\Command;
abstract class FileCommand extends Command
{
/**
*
* @var string
*/
protected $path = '/files';
/**
*
* @var string
*/
protected $objectClass = 'Libcast\Client\Entity\File';
}
\ No newline at end of file
<?php
namespace Libcast\Client\Command;
use Libcast\Client\Exception\BadParameterException;
class SendFile extends FileCommand
{
/**
*
* @var resource stream
*/
private $options = array();
/**
*
* @var string
*/
protected $method = 'POST';
/**
*
* @param string $name
* @param string $path Path is either an absolute path to the file or a stream resource
*/
public function __construct($name, $path)
{
if (is_readable($path)) {
$this->options[CURLOPT_POSTFIELDS] = array('path' => "@$path", 'name' => $name);
} elseif (is_resource($path) && ('stream' === get_resource_type($path))) {
$this->options[CURLOPT_POSTFIELDS] = array('name' => $name);
$this->options[CURLOPT_INFILE] = $path;
} else {
throw new BadParameterException('Path parameter must be an absolute path to a readable file or a stream resource.');
}
$this->setPayload(array('name' => $name));
}
/**
*
* @return array
*/
protected function getRequestOptions()
{
return $this->options + parent::getRequestOptions();
}
}
\ No newline at end of file
<?php
namespace Libcast\Client\Entity;
use Libcast\Client\Model\FileInterface;
use JMS\Serializer\Annotation\Type;
use JMS\Serializer\Annotation\XmlRoot;
/**
*
* @XmlRoot("file")
*/
class File extends Entity implements FileInterface
{
/**
*
* @Type("string")
* @var string
*/
protected $name;
/**
*
* @Type("integer")
* @var int
*/
protected $size;
/**
*
* @Type("string")
* @var string
*/
protected $embed;
/**
*
* @Type("string")
* @var string
*/
protected $encodingStatus;
/**
*
* @Type("string")
* @var string
*/
protected $thumbnail;
/**
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Size in bytes
*
* @return int
*/
public function getSize()
{
return $this->size;
}
/**
*
* @return ???
*/
public function getEncodingStatus()
{
return $this->encodingStatus;
}
/**
* URL of the thumbnail
*
* @return string
*/
public function getThumbnail()
{
return $this->thumbnail;
}
/**
* Code of the embed (URL encoded)
*
* @return string
*/
public function getEmbed()
{
return $this->embed;
}
}
\ No newline at end of file
......@@ -62,8 +62,12 @@ use Psr\Log\LogLevel;
*
* Access
*
* @method \Libcast\Client\Model\ChannelInterface createAccess(\Libcast\Client\Model\AccessInterface $access) Access instance
* @method \Libcast\Client\Model\AccessInterface createAccess(\Libcast\Client\Model\AccessInterface $access) Access instance
* @method \Libcast\Client\Entity\Collection accesses(mixed $entity, $filters = array()) List the accesses of a Platform, a Media, a Stream, a Publication, a User or a Group
*
* File
*
* @method \Libcast\Client\Model\FileInterface sendFile(string $name, string $path) Upload a file to the user briefcase
*/
class LibcastClient implements LoggerAwareInterface
{
......
<?php
namespace Libcast\Client\Model;
interface FileInterface extends RestfulResource
{
/**
*
* @return string
*/
public function getName();
/**
* Size in bytes
*
* @return int
*/
public function getSize();
/**
*
* @return ???
*/
public function getEncodingStatus();
/**
* URL of the thumbnail
*
* @return string
*/
public function getThumbnail();
/**
* Code of the embed (URL encoded)
*
* @return string
*/
public function getEmbed();
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment