summaryrefslogtreecommitdiffstats
path: root/lib/ocs
diff options
context:
space:
mode:
authorTom Needham <needham.thomas@gmail.com>2012-12-12 16:50:25 +0000
committerTom Needham <needham.thomas@gmail.com>2012-12-12 16:50:25 +0000
commit140141edf2c5d89f083b4d254c0533e0209d517b (patch)
treece6ac139ecb19fc38b92bf883002709c5c96b1aa /lib/ocs
parent115dbc721d77509274e7a1bacf0239ada565b005 (diff)
downloadnextcloud-server-140141edf2c5d89f083b4d254c0533e0209d517b.tar.gz
nextcloud-server-140141edf2c5d89f083b4d254c0533e0209d517b.zip
API: Further tidying, implement OC_OCS_Result object for api results.
Diffstat (limited to 'lib/ocs')
-rw-r--r--lib/ocs/result.php65
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/ocs/result.php b/lib/ocs/result.php
new file mode 100644
index 00000000000..a7199cb5ac7
--- /dev/null
+++ b/lib/ocs/result.php
@@ -0,0 +1,65 @@
+<?php
+
+class OC_OCS_Result{
+
+ private $data, $message, $statuscode, $items, $perpage;
+
+ /**
+ * create the OCS_Result object
+ * @param $data mixed the data to return
+ */
+ public function __construct($data=null, $code=100, $message=null){
+ $this->data = $data;
+ $this->statuscode = $code;
+ $this->message = $message;
+ }
+
+ /**
+ * sets the statuscode
+ * @param $code int
+ */
+ public function setCode(int $code){
+ $this->statuscode = $code;
+ }
+
+ /**
+ * optionally set the total number of items available
+ * @param $items int
+ */
+ public function setItems(int $items){
+ $this->items = $items;
+ }
+
+ /**
+ * optionally set the the number of items per page
+ * @param $items int
+ */
+ public function setItemsPerPage(int $items){
+ $this->perpage = $items;
+ }
+
+ /**
+ * set a custom message for the response
+ * @param $message string the message
+ */
+ public function setMessage(string $message){
+ $this->message = $message;
+ }
+
+ /**
+ * returns the data associated with the api result
+ * @return array
+ */
+ public function getResult(){
+ $return = array();
+ $return['meta'] = array();
+ $return['meta']['status'] = ($this->statuscode === 100) ? 'ok' : 'failure';
+ $return['meta']['statuscode'] = $this->statuscode;
+ $return['meta']['message'] = $this->message;
+ $return['data'] = $this->data;
+ // Return the result data.
+ return $return;
+ }
+
+
+} \ No newline at end of file