1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42:
<?php
namespace Donut\Instagram;
use Donut\IWorker;
use Donut\Message;
use Donut\Manager;
class PublishInstagramPost implements IWorker
{
private $instagramApi;
public function __construct(InstagramApi $instagramApi)
{
$this->instagramApi = $instagramApi;
}
public function processMessage(Message $message, Manager $manager)
{
$instagram = $this->instagramApi->getInstagram();
$instagramPost = InstagramPost::fromArray($message->getData());
$tmpPhoto = tempnam(sys_get_temp_dir(), 'instagram-photo');
file_put_contents($tmpPhoto, file_get_contents($instagramPost->getPhoto()));
$resizer = new \InstagramAPI\MediaAutoResizer($tmpPhoto);
$instagram->timeline->uploadPhoto($resizer->getFile(), array(
'caption' => $instagramPost->getText(),
));
$resizer->deleteFile();
}
}