From 05c416f0e821592989ce16523e18fae00434e632 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Fri, 28 Apr 2017 19:34:27 +0200 Subject: [PATCH] WIP --- _admin.php | 1 - _public.php | 15 ++++- documentation/definition.yaml | 61 +++++++++++++++++ inc/class.rest.auth.php | 24 +++++++ inc/class.rest.query.php | 120 ++++++++++++++++++++++++++++++++++ 5 files changed, 217 insertions(+), 4 deletions(-) create mode 100644 inc/class.rest.auth.php create mode 100644 inc/class.rest.query.php diff --git a/_admin.php b/_admin.php index ddd6814..01ba038 100644 --- a/_admin.php +++ b/_admin.php @@ -1,7 +1,6 @@ addItem(__('Rest API'), 'plugin.php?p=rest', diff --git a/_public.php b/_public.php index 47283ca..6fd24ed 100644 --- a/_public.php +++ b/_public.php @@ -19,9 +19,18 @@ class rest extends dcUrlHandlers header('Access-Control-Allow-Methods: GET, POST'); header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); } + header('Content-Type: application/json'); - - - echo "HELLO".$_SERVER['REQUEST_METHOD'].$args; + + + + private function get_api_key_sended(){ + $headers = getallheaders(); + if(isset($headers['x_dc_key'])){ + return $headers['x_dc_key']; + }else{ + return false; + } } + } \ No newline at end of file diff --git a/documentation/definition.yaml b/documentation/definition.yaml index b658ac6..8be8fd5 100644 --- a/documentation/definition.yaml +++ b/documentation/definition.yaml @@ -17,6 +17,11 @@ paths: /blogs: get: summary: Get list of availables blogs + parameters: + - name: x_dc_key + in: header + type: string + required: false responses: 200: description: array serving blogs properties @@ -32,6 +37,10 @@ paths: post: summary: Create a new blog parameters: + - name: x_dc_key + in: header + type: string + required: true - name: blog in: body description: The blog you want to create @@ -51,6 +60,10 @@ paths: get: summary: Get a blog poperties parameters: + - name: x_dc_key + in: header + type: string + required: false - name: blog-id in: path type: string @@ -69,6 +82,10 @@ paths: patch: summary: Update part of blog properties parameters: + - name: x_dc_key + in: header + type: string + required: true - name: blog-id in: path type: string @@ -93,6 +110,10 @@ paths: put: summary: Overwrite blog Properties (if a parameter is not set, his value will be erased by de default value) parameters: + - name: x_dc_key + in: header + type: string + required: true - name: blog-id in: path type: string @@ -118,6 +139,10 @@ paths: delete: summary: Delete this blog parameters: + - name: x_dc_key + in: header + type: string + required: true - name: blog-id in: path type: string @@ -138,6 +163,10 @@ paths: get: summary: Get list of posts parameters: + - name: x_dc_key + in: header + type: string + required: true - name: blog-id in: path type: string @@ -172,6 +201,10 @@ paths: post: summary: Create a new post parameters: + - name: x_dc_key + in: header + type: string + required: true - name: blog-id in: path type: string @@ -195,6 +228,10 @@ paths: get: summary: Get a post entry parameters: + - name: x_dc_key + in: header + type: string + required: false - name: blog-id in: path type: string @@ -229,6 +266,10 @@ paths: patch: summary: Update part of a post entry's properties parameters: + - name: x_dc_key + in: header + type: string + required: true - name: blog-id in: path type: string @@ -255,6 +296,10 @@ paths: put: summary: Update full blog properties. Unsetted parameters will be erased parameters: + - name: x_dc_key + in: header + type: string + required: true - name: blog-id in: path type: string @@ -281,6 +326,10 @@ paths: delete: summary: Delete the post parameters: + - name: x_dc_key + in: header + type: string + required: true - name: blog-id in: path type: string @@ -304,6 +353,10 @@ paths: get: summary: Get list of available categories parameters: + - name: x_dc_key + in: header + type: string + required: false - name: blog-id in: path type: string @@ -323,6 +376,10 @@ paths: post: summary: Create a new category parameters: + - name: x_dc_key + in: header + type: string + required: true - name: blog-id in: path type: string @@ -346,6 +403,10 @@ paths: get: summary: get one category properties parameters: + - name: x_dc_key + in: header + type: string + required: false - name: blog-id in: path type: string diff --git a/inc/class.rest.auth.php b/inc/class.rest.auth.php new file mode 100644 index 0000000..e2a0d95 --- /dev/null +++ b/inc/class.rest.auth.php @@ -0,0 +1,24 @@ +auth + return parent::checkUser($user_id,$pwd); + + + } +} \ No newline at end of file diff --git a/inc/class.rest.query.php b/inc/class.rest.query.php new file mode 100644 index 0000000..63bec68 --- /dev/null +++ b/inc/class.rest.query.php @@ -0,0 +1,120 @@ +response_code = RestQuery::get_full_code_header(400); + $this->response_message = array( + "error":"Unrecoknized method", + "code":400 + ); + break; + } + + } + + public function get_full_code_header($code){ + static $codes = array( + 100 =>"Continue", + 101 =>"Switching Protocols", + 102 =>"Processing", + 200 =>"OK", + 201 =>"Created", + 202 =>"Accepted", + 203 =>"Non-Authoritative Information", + 204 =>"No Content", + 205 =>"Reset Content", + 206 =>"Partial Content", + 207 =>"Multi-Status", + 210 =>"Content Different", + 226 =>"IM Used", + 300 =>"Multiple Choices", + 301 =>"Moved Permanently", + 302 =>"Moved Temporarily", + 303 =>"See Other", + 304 =>"Not Modified", + 305 =>"Use Proxy", + 306 =>"(aucun)", + 307 =>"Temporary Redirect", + 308 =>"Permanent Redirect", + 310 =>"Too many Redirects", + 400 =>"Bad Request", + 401 =>"Unauthorized", + 402 =>"Payment Required", + 403 =>"Forbidden", + 404 =>"Not Found", + 405 =>"Method Not Allowed", + 406 =>"Not Acceptable", + 407 =>"Proxy Authentication Required", + 408 =>"Request Time-out", + 409 =>"Conflict", + 410 =>"Gone", + 411 =>"Length Required", + 412 =>"Precondition Failed", + 413 =>"Request Entity Too Large", + 414 =>"Request-URI Too Long", + 415 =>"Unsupported Media Type", + 416 =>"Requested range unsatisfiable", + 417 =>"Expectation failed", + 418 =>"I’m a teapot", + 421 =>"Bad mapping / Misdirected Request", + 422 =>"Unprocessable entity", + 423 =>"Locked", + 424 =>"Method failure", + 425 =>"Unordered Collection", + 426 =>"Upgrade Required", + 428 =>"Precondition Required", + 429 =>"Too Many Requests", + 431 =>"Request Header Fields Too Large", + 449 =>"Retry With", + 450 =>"Blocked by Windows Parental Controls", + 451 =>"Unavailable For Legal Reasons", + 456 =>"Unrecoverable Error" + ); + + if(isset($codes[$code])){ + return "HTTP/1.0 ".$code." ".$codes[$code]; + }else{ + return "HTTP/1.0 ".$code." Something wrong happened"; + } + + + + } + + +} +class QueryGetBlogs extends RestQuery +{ + +} +class QueryPostBlogs extends RestQuery +{ + +} + +//etc... \ No newline at end of file