2015-06-23 09:04:02 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Skobkin\Bundle\PointToolsBundle\Service;
|
|
|
|
|
|
|
|
use Doctrine\ORM\EntityManager;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use Doctrine\ORM\EntityRepository;
|
|
|
|
use Guzzle\Service\Client;
|
|
|
|
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post;
|
|
|
|
use Skobkin\Bundle\PointToolsBundle\Entity\User;
|
2015-10-26 03:00:39 +00:00
|
|
|
use Skobkin\Bundle\PointToolsBundle\Service\Factory\PostFactory;
|
2015-06-23 09:04:02 +00:00
|
|
|
|
|
|
|
/**
|
2015-10-26 03:00:39 +00:00
|
|
|
* Basic Point.im user API functions from /api/post
|
2015-06-23 09:04:02 +00:00
|
|
|
*/
|
|
|
|
class PostApi extends AbstractApi
|
|
|
|
{
|
|
|
|
/**
|
2015-10-26 03:00:39 +00:00
|
|
|
* @var PostFactory
|
2015-06-23 09:04:02 +00:00
|
|
|
*/
|
2015-10-26 03:00:39 +00:00
|
|
|
private $postFactory;
|
2015-06-23 09:04:02 +00:00
|
|
|
|
|
|
|
|
2015-10-26 03:00:39 +00:00
|
|
|
public function __construct(Client $httpClient, $https = true, $baseUrl = null, PostFactory $postFactory)
|
2015-06-23 09:04:02 +00:00
|
|
|
{
|
|
|
|
parent::__construct($httpClient, $https, $baseUrl);
|
|
|
|
|
2015-10-26 03:00:39 +00:00
|
|
|
$this->postFactory = $postFactory;
|
2015-06-23 09:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return 'skobkin_point_tools_api_post';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-26 03:00:39 +00:00
|
|
|
* Get post with comments by id
|
|
|
|
*
|
|
|
|
* @param $id
|
2015-06-23 09:04:02 +00:00
|
|
|
*
|
|
|
|
* @return User[]
|
|
|
|
*/
|
2015-10-26 03:00:39 +00:00
|
|
|
public function getPostById($id)
|
2015-06-23 09:04:02 +00:00
|
|
|
{
|
2015-10-26 03:00:39 +00:00
|
|
|
if (!is_string($id)) {
|
|
|
|
throw new \InvalidArgumentException('$id must be an string');
|
2015-06-23 09:04:02 +00:00
|
|
|
}
|
|
|
|
|
2015-10-26 03:00:39 +00:00
|
|
|
$postData = $this->getGetRequestData('/api/post/'.$id, [], true);
|
2015-06-23 09:04:02 +00:00
|
|
|
|
2015-10-26 03:00:39 +00:00
|
|
|
$post = $this->postFactory->createFromArray($postData);
|
2015-06-23 09:04:02 +00:00
|
|
|
|
2015-10-26 03:00:39 +00:00
|
|
|
return $post;
|
2015-06-23 09:04:02 +00:00
|
|
|
}
|
|
|
|
}
|