diff options
author | Paul Tirk <paultirk@paultirk.com> | 2020-12-25 11:48:38 +0000 |
---|---|---|
committer | Sean Molenaar <SMillerDev@users.noreply.github.com> | 2021-04-08 10:23:11 +0200 |
commit | 6e067dfd430721c6672988d6ac34f3a4d03678c8 (patch) | |
tree | f3c357650940cf90415500feb794a202594a3b7f /lib/Db | |
parent | 6e845124df1d9238d28875c8f745868be1f765b7 (diff) |
add serialization methods for v2 API
Signed-off-by: Paul Tirk <paultirk@paultirk.com>
Diffstat (limited to 'lib/Db')
-rw-r--r-- | lib/Db/Feed.php | 24 | ||||
-rw-r--r-- | lib/Db/Folder.php | 6 | ||||
-rw-r--r-- | lib/Db/IAPI.php | 1 | ||||
-rw-r--r-- | lib/Db/Item.php | 22 |
4 files changed, 53 insertions, 0 deletions
diff --git a/lib/Db/Feed.php b/lib/Db/Feed.php index c468f8272..008390e2b 100644 --- a/lib/Db/Feed.php +++ b/lib/Db/Feed.php @@ -660,4 +660,28 @@ class Feed extends Entity implements IAPI, \JsonSerializable ] ); } + + public function toAPI2(): array + { + $result = [ + 'id' => $this->getId(), + 'name' => $this->getTitle(), + 'faviconLink' => $this->getFaviconLink(), + 'folderId' => $this->getFolderId(), + 'ordering' => $this->getOrdering(), + 'fullTextEnabled' => $this->getFullTextEnabled(), + 'updateMode' => $this->getUpdateMode(), + 'isPinned' => $this->getPinned() + ]; + + if (!empty($this->getLastUpdateError())) { + $result['error'] = [ + 'code' => 1, + 'message' => $this->getLastUpdateError() + ]; + } + + return $result; + } + } diff --git a/lib/Db/Folder.php b/lib/Db/Folder.php index 6f208309b..1845d8e82 100644 --- a/lib/Db/Folder.php +++ b/lib/Db/Folder.php @@ -172,4 +172,10 @@ class Folder extends Entity implements IAPI, \JsonSerializable ] ); } + + public function toAPI2(): array + { + return $this->toAPI(); + } + } diff --git a/lib/Db/IAPI.php b/lib/Db/IAPI.php index c6f844147..58897e9d3 100644 --- a/lib/Db/IAPI.php +++ b/lib/Db/IAPI.php @@ -16,4 +16,5 @@ namespace OCA\News\Db; interface IAPI { public function toAPI(); + public function toAPI2(); } diff --git a/lib/Db/Item.php b/lib/Db/Item.php index 2d87babf7..6e09fde31 100644 --- a/lib/Db/Item.php +++ b/lib/Db/Item.php @@ -574,6 +574,28 @@ class Item extends Entity implements IAPI, \JsonSerializable ]; } + public function toAPI2(): array + { + return [ + 'id' => $this->getId(), + 'url' => $this->getUrl(), + 'title' => $this->getTitle(), + 'author' => $this->getAuthor(), + 'publishedAt' => date('c', $this->getPubDate()), + 'updatedAt' => date('c', $this->getUpdatedDate()), + 'enclosure' => [ + 'mimeType' => $this->getEnclosureMime(), + 'url' => $this->getEnclosureLink() + ], + 'body' => $this->getBody(), + 'feedId' => $this->getFeedId(), + 'isUnread' => $this->isUnread(), + 'isStarred' => $this->isStarred(), + 'fingerprint' => $this->getFingerprint(), + 'contentHash' => $this->getContentHash() + ]; + } + /** * Format for exporting. * |