From 140141edf2c5d89f083b4d254c0533e0209d517b Mon Sep 17 00:00:00 2001 From: Tom Needham Date: Wed, 12 Dec 2012 16:50:25 +0000 Subject: API: Further tidying, implement OC_OCS_Result object for api results. --- lib/ocs/result.php | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 lib/ocs/result.php (limited to 'lib/ocs') 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 @@ +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 -- cgit v1.2.3