]> git.mxchange.org Git - friendica.git/commitdiff
Add Mastodon API entity classes
authorHypolite Petovan <hypolite@mrpetovan.com>
Thu, 5 Dec 2019 13:11:32 +0000 (08:11 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Tue, 10 Dec 2019 03:50:35 +0000 (22:50 -0500)
src/Api/Mastodon/Account.php [new file with mode: 0644]
src/Api/Mastodon/Emoji.php [new file with mode: 0644]
src/Api/Mastodon/Field.php [new file with mode: 0644]

diff --git a/src/Api/Mastodon/Account.php b/src/Api/Mastodon/Account.php
new file mode 100644 (file)
index 0000000..5d4f369
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+
+namespace Friendica\Api\Mastodon;
+
+use Friendica\Content\Text\BBCode;
+use Friendica\Database\DBA;
+use Friendica\Util\DateTimeFormat;
+
+/**
+ * Class Account
+ *
+ * @see https://docs.joinmastodon.org/api/entities/#account
+ */
+class Account
+{
+       /** @var string */
+       var $id;
+       /** @var string */
+       var $username;
+       /** @var string */
+       var $acct;
+       /** @var string */
+       var $display_name;
+       /** @var bool */
+       var $locked;
+       /** @var string (Datetime) */
+       var $created_at;
+       /** @var int */
+       var $followers_count;
+       /** @var int */
+       var $following_count;
+       /** @var int */
+       var $statuses_count;
+       /** @var string */
+       var $note;
+       /** @var string (URL)*/
+       var $url;
+       /** @var string (URL) */
+       var $avatar;
+       /** @var string (URL) */
+       var $avatar_static;
+       /** @var string (URL) */
+       var $header;
+       /** @var string (URL) */
+       var $header_static;
+       /** @var Emoji[] */
+       var $emojis;
+       /** @var Account|null */
+       var $moved = null;
+       /** @var Field[]|null */
+       var $fields = null;
+       /** @var bool|null */
+       var $bot = null;
+
+       /**
+        * Creates an account record from a contact record. Expects all contact table fields to be set
+        *
+        * @param array $contact
+        * @return Account
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        */
+       public static function createFromContact(array $contact) {
+               $account = new Account();
+               $account->id = $contact['id'];
+               $account->username = $contact['nick'];
+               $account->acct = $contact['nick'];
+               $account->display_name = $contact['name'];
+               $account->locked = $contact['blocked'];
+               $account->created_at = DateTimeFormat::utc($contact['created'], DateTimeFormat::ATOM);
+               // No data is available from contact
+               $account->followers_count = 0;
+               $account->following_count = 0;
+               $account->statuses_count = 0;
+               $account->note = BBCode::convert($contact['about']);
+               $account->url = $contact['url'];
+               $account->avatar = $contact['avatar'];
+               $account->avatar_static = $contact['avatar'];
+               // No header picture in Friendica
+               $account->header = '';
+               $account->header_static = '';
+               // No custom emojis per account in Friendica
+               $account->emojis = [];
+
+               return $account;
+       }
+}
diff --git a/src/Api/Mastodon/Emoji.php b/src/Api/Mastodon/Emoji.php
new file mode 100644 (file)
index 0000000..0fda2d1
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+namespace Friendica\Api\Mastodon;
+
+/**
+ * Class Emoji
+ *
+ * @see https://docs.joinmastodon.org/api/entities/#emoji
+ */
+class Emoji
+{
+       /** @var string */
+       var $shortcode;
+       /** @var string (URL)*/
+       var $static_url;
+       /** @var string (URL)*/
+       var $url;
+       /** @var bool */
+       var $visible_in_picker;
+}
diff --git a/src/Api/Mastodon/Field.php b/src/Api/Mastodon/Field.php
new file mode 100644 (file)
index 0000000..92a3d4e
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+
+namespace Friendica\Api\Mastodon;
+
+/**
+ * Class Field
+ *
+ * @see https://docs.joinmastodon.org/api/entities/#field
+ */
+class Field
+{
+       /** @var string */
+       var $name;
+       /** @var string (HTML) */
+       var $value;
+       /** @var string (Datetime)*/
+       var $verified_at;
+}