Move Mastodon API factories to Factory\Api\Mastodon
This commit is contained in:
parent
75a2190af5
commit
1ac9107e5f
5 changed files with 60 additions and 14 deletions
46
src/Factory/Api/Mastodon/Account.php
Normal file
46
src/Factory/Api/Mastodon/Account.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Factory\Api\Mastodon;
|
||||
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\Model\APContact;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Account extends BaseFactory
|
||||
{
|
||||
/** @var BaseURL */
|
||||
protected $baseUrl;
|
||||
|
||||
public function __construct(LoggerInterface $logger, BaseURL $baseURL)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
|
||||
$this->baseUrl = $baseURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $contactId
|
||||
* @param int $uid User Id
|
||||
* @return \Friendica\Object\Api\Mastodon\Account
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public function createFromContactId(int $contactId, $uid = 0)
|
||||
{
|
||||
$cdata = Contact::getPublicAndUserContacID($contactId, $uid);
|
||||
if (!empty($cdata)) {
|
||||
$publicContact = Contact::getById($cdata['public']);
|
||||
$userContact = Contact::getById($cdata['user']);
|
||||
} else {
|
||||
$publicContact = Contact::getById($contactId);
|
||||
$userContact = [];
|
||||
}
|
||||
|
||||
$apcontact = APContact::getByURL($publicContact['url'], false);
|
||||
|
||||
return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, $apcontact, $userContact);
|
||||
}
|
||||
}
|
46
src/Factory/Api/Mastodon/Emoji.php
Normal file
46
src/Factory/Api/Mastodon/Emoji.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Factory\Api\Mastodon;
|
||||
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\Model\APContact;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Emoji extends BaseFactory
|
||||
{
|
||||
/** @var BaseURL */
|
||||
protected $baseUrl;
|
||||
|
||||
public function __construct(LoggerInterface $logger, BaseURL $baseURL)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
|
||||
$this->baseUrl = $baseURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $contactId
|
||||
* @param int $uid User Id
|
||||
* @return \Friendica\Api\Entity\Mastodon\Account
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public function createFromContactId(int $contactId, $uid = 0)
|
||||
{
|
||||
$cdata = Contact::getPublicAndUserContacID($contactId, $uid);
|
||||
if (!empty($cdata)) {
|
||||
$publicContact = Contact::getById($cdata['public']);
|
||||
$userContact = Contact::getById($cdata['user']);
|
||||
} else {
|
||||
$publicContact = Contact::getById($contactId);
|
||||
$userContact = [];
|
||||
}
|
||||
|
||||
$apcontact = APContact::getByURL($publicContact['url'], false);
|
||||
|
||||
return new \Friendica\Api\Entity\Mastodon\Account($this->baseUrl, $publicContact, $apcontact, $userContact);
|
||||
}
|
||||
}
|
47
src/Factory/Api/Mastodon/FollowRequest.php
Normal file
47
src/Factory/Api/Mastodon/FollowRequest.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Factory\Api\Mastodon;
|
||||
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\Model\APContact;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Introduction;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class FollowRequest extends BaseFactory
|
||||
{
|
||||
/** @var BaseURL */
|
||||
protected $baseUrl;
|
||||
|
||||
public function __construct(LoggerInterface $logger, BaseURL $baseURL)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
|
||||
$this->baseUrl = $baseURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Introduction $introduction
|
||||
* @return \Friendica\Object\Api\Mastodon\FollowRequest
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public function createFromIntroduction(Introduction $introduction)
|
||||
{
|
||||
$cdata = Contact::getPublicAndUserContacID($introduction->{'contact-id'}, $introduction->uid);
|
||||
|
||||
if (empty($cdata)) {
|
||||
$this->logger->warning('Wrong introduction data', ['Introduction' => $introduction]);
|
||||
throw new HTTPException\InternalServerErrorException('Wrong introduction data');
|
||||
}
|
||||
|
||||
$publicContact = Contact::getById($cdata['public']);
|
||||
$userContact = Contact::getById($cdata['user']);
|
||||
|
||||
$apcontact = APContact::getByURL($publicContact['url'], false);
|
||||
|
||||
return new \Friendica\Object\Api\Mastodon\FollowRequest($this->baseUrl, $introduction->id, $publicContact, $apcontact, $userContact);
|
||||
}
|
||||
}
|
38
src/Factory/Api/Mastodon/Relationship.php
Normal file
38
src/Factory/Api/Mastodon/Relationship.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Factory\Api\Mastodon;
|
||||
|
||||
use Friendica\Object\Api\Mastodon\Relationship as RelationshipEntity;
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\Model\Contact;
|
||||
|
||||
class Relationship extends BaseFactory
|
||||
{
|
||||
/**
|
||||
* @param int $userContactId Contact row id with uid != 0
|
||||
* @return RelationshipEntity
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createFromContactId(int $userContactId)
|
||||
{
|
||||
return $this->createFromContact(Contact::getById($userContactId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $userContact Full contact row record with uid != 0
|
||||
* @return RelationshipEntity
|
||||
*/
|
||||
public function createFromContact(array $userContact)
|
||||
{
|
||||
return new RelationshipEntity($userContact['id'], $userContact);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userContactId Contact row id with uid != 0
|
||||
* @return RelationshipEntity
|
||||
*/
|
||||
public function createDefaultFromContactId(int $userContactId)
|
||||
{
|
||||
return new RelationshipEntity($userContactId);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue