diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-05-02 12:44:17 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-05-02 12:44:37 +0200 |
commit | 0da3c160df7f2af1b7800e70a2eba8c04126f3d4 (patch) | |
tree | 5f063e6e25fccaa9103dcaf9778b6c0803b1f53d | |
parent | 7af27f8c177d69533bc07a59fa6a53f245f7898c (diff) |
add serialize method for api
-rw-r--r-- | db/iapi.php | 33 | ||||
-rw-r--r-- | db/item.php | 22 | ||||
-rw-r--r-- | tests/unit/db/ItemTest.php | 36 |
3 files changed, 90 insertions, 1 deletions
diff --git a/db/iapi.php b/db/iapi.php new file mode 100644 index 000000000..2fed0c01a --- /dev/null +++ b/db/iapi.php @@ -0,0 +1,33 @@ +<?php + +/** +* ownCloud - News +* +* @author Alessandro Cosentino +* @author Bernhard Posselt +* @copyright 2012 Alessandro Cosentino cosenal@gmail.com +* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +namespace OCA\News\Db; + +use \OCA\AppFramework\Db\Entity; + + +interface IAPI { + public function toAPI(); +} diff --git a/db/item.php b/db/item.php index e24835226..6a627d8ff 100644 --- a/db/item.php +++ b/db/item.php @@ -28,7 +28,7 @@ namespace OCA\News\Db; use \OCA\AppFramework\Db\Entity; -class Item extends Entity { +class Item extends Entity implements IAPI { public $guidHash; public $guid; @@ -88,5 +88,25 @@ class Item extends Entity { return !$this->isStarred(); } + + public function toAPI() { + return array( + 'id' => $this->getId(), + 'guid' => $this->getGuid(), + 'guidHash' => $this->getGuidHash(), + 'url' => $this->getUrl(), + 'title' => $this->getTitle(), + 'author' => $this->getAuthor(), + 'pubDate' => $this->getPubDate(), + 'body' => $this->getBody(), + 'enclosureMime' => $this->getEnclosureMime(), + 'enclosureLink' => $this->getEnclosureLink(), + 'feedId' => $this->getFeedId(), + 'unread' => $this->isUnread(), + 'starred' => $this->isStarred(), + 'lastModified' => $this->getLastModified() + ); + } + } diff --git a/tests/unit/db/ItemTest.php b/tests/unit/db/ItemTest.php index 3ce7183fd..6c1c5ea6c 100644 --- a/tests/unit/db/ItemTest.php +++ b/tests/unit/db/ItemTest.php @@ -66,4 +66,40 @@ class ItemTest extends \PHPUnit_Framework_TestCase { } + public function testToAPI() { + $item = new Item(); + $item->setId(3); + $item->setGuid('guid'); + $item->setGuidHash('hash'); + $item->setUrl('url'); + $item->setTitle('title'); + $item->setAuthor('author'); + $item->setPubDate(123); + $item->setBody('body'); + $item->setEnclosureMime('audio/ogg'); + $item->setEnclosureLink('enclink'); + $item->setFeedId(1); + $item->setStatus(0); + $item->setUnread(); + $item->setStarred(); + $item->setLastModified(321); + + $this->assertEquals(array( + 'id' => 3, + 'guid' => 'guid', + 'guidHash' => 'hash', + 'url' => 'url', + 'title' => 'title', + 'author' => 'author', + 'pubDate' => 123, + 'body' => 'body', + 'enclosureMime' => 'audio/ogg', + 'enclosureLink' => 'enclink', + 'feedId' => 1, + 'unread' => true, + 'starred' => true, + 'lastModified' => 321 + ), $item->toAPI()); + } + }
\ No newline at end of file |