summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul Tirk <paultirk@paultirk.com>2020-12-25 11:48:38 +0000
committerSean Molenaar <SMillerDev@users.noreply.github.com>2021-04-08 10:23:11 +0200
commit6e067dfd430721c6672988d6ac34f3a4d03678c8 (patch)
treef3c357650940cf90415500feb794a202594a3b7f /lib
parent6e845124df1d9238d28875c8f745868be1f765b7 (diff)
add serialization methods for v2 API
Signed-off-by: Paul Tirk <paultirk@paultirk.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Db/Feed.php24
-rw-r--r--lib/Db/Folder.php6
-rw-r--r--lib/Db/IAPI.php1
-rw-r--r--lib/Db/Item.php22
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.
*