WIP
This commit is contained in:
parent
dd698907c6
commit
05c416f0e8
|
@ -1,7 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if (!defined('DC_CONTEXT_ADMIN')) { return; }
|
if (!defined('DC_CONTEXT_ADMIN')) { return; }
|
||||||
// dead but useful code, in order to have translations
|
|
||||||
|
|
||||||
$_menu['Blog']->addItem(__('Rest API'),
|
$_menu['Blog']->addItem(__('Rest API'),
|
||||||
'plugin.php?p=rest',
|
'plugin.php?p=rest',
|
||||||
|
|
11
_public.php
11
_public.php
|
@ -19,9 +19,18 @@ class rest extends dcUrlHandlers
|
||||||
header('Access-Control-Allow-Methods: GET, POST');
|
header('Access-Control-Allow-Methods: GET, POST');
|
||||||
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -17,6 +17,11 @@ paths:
|
||||||
/blogs:
|
/blogs:
|
||||||
get:
|
get:
|
||||||
summary: Get list of availables blogs
|
summary: Get list of availables blogs
|
||||||
|
parameters:
|
||||||
|
- name: x_dc_key
|
||||||
|
in: header
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: array serving blogs properties
|
description: array serving blogs properties
|
||||||
|
@ -32,6 +37,10 @@ paths:
|
||||||
post:
|
post:
|
||||||
summary: Create a new blog
|
summary: Create a new blog
|
||||||
parameters:
|
parameters:
|
||||||
|
- name: x_dc_key
|
||||||
|
in: header
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
- name: blog
|
- name: blog
|
||||||
in: body
|
in: body
|
||||||
description: The blog you want to create
|
description: The blog you want to create
|
||||||
|
@ -51,6 +60,10 @@ paths:
|
||||||
get:
|
get:
|
||||||
summary: Get a blog poperties
|
summary: Get a blog poperties
|
||||||
parameters:
|
parameters:
|
||||||
|
- name: x_dc_key
|
||||||
|
in: header
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
- name: blog-id
|
- name: blog-id
|
||||||
in: path
|
in: path
|
||||||
type: string
|
type: string
|
||||||
|
@ -69,6 +82,10 @@ paths:
|
||||||
patch:
|
patch:
|
||||||
summary: Update part of blog properties
|
summary: Update part of blog properties
|
||||||
parameters:
|
parameters:
|
||||||
|
- name: x_dc_key
|
||||||
|
in: header
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
- name: blog-id
|
- name: blog-id
|
||||||
in: path
|
in: path
|
||||||
type: string
|
type: string
|
||||||
|
@ -93,6 +110,10 @@ paths:
|
||||||
put:
|
put:
|
||||||
summary: Overwrite blog Properties (if a parameter is not set, his value will be erased by de default value)
|
summary: Overwrite blog Properties (if a parameter is not set, his value will be erased by de default value)
|
||||||
parameters:
|
parameters:
|
||||||
|
- name: x_dc_key
|
||||||
|
in: header
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
- name: blog-id
|
- name: blog-id
|
||||||
in: path
|
in: path
|
||||||
type: string
|
type: string
|
||||||
|
@ -118,6 +139,10 @@ paths:
|
||||||
delete:
|
delete:
|
||||||
summary: Delete this blog
|
summary: Delete this blog
|
||||||
parameters:
|
parameters:
|
||||||
|
- name: x_dc_key
|
||||||
|
in: header
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
- name: blog-id
|
- name: blog-id
|
||||||
in: path
|
in: path
|
||||||
type: string
|
type: string
|
||||||
|
@ -138,6 +163,10 @@ paths:
|
||||||
get:
|
get:
|
||||||
summary: Get list of posts
|
summary: Get list of posts
|
||||||
parameters:
|
parameters:
|
||||||
|
- name: x_dc_key
|
||||||
|
in: header
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
- name: blog-id
|
- name: blog-id
|
||||||
in: path
|
in: path
|
||||||
type: string
|
type: string
|
||||||
|
@ -172,6 +201,10 @@ paths:
|
||||||
post:
|
post:
|
||||||
summary: Create a new post
|
summary: Create a new post
|
||||||
parameters:
|
parameters:
|
||||||
|
- name: x_dc_key
|
||||||
|
in: header
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
- name: blog-id
|
- name: blog-id
|
||||||
in: path
|
in: path
|
||||||
type: string
|
type: string
|
||||||
|
@ -195,6 +228,10 @@ paths:
|
||||||
get:
|
get:
|
||||||
summary: Get a post entry
|
summary: Get a post entry
|
||||||
parameters:
|
parameters:
|
||||||
|
- name: x_dc_key
|
||||||
|
in: header
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
- name: blog-id
|
- name: blog-id
|
||||||
in: path
|
in: path
|
||||||
type: string
|
type: string
|
||||||
|
@ -229,6 +266,10 @@ paths:
|
||||||
patch:
|
patch:
|
||||||
summary: Update part of a post entry's properties
|
summary: Update part of a post entry's properties
|
||||||
parameters:
|
parameters:
|
||||||
|
- name: x_dc_key
|
||||||
|
in: header
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
- name: blog-id
|
- name: blog-id
|
||||||
in: path
|
in: path
|
||||||
type: string
|
type: string
|
||||||
|
@ -255,6 +296,10 @@ paths:
|
||||||
put:
|
put:
|
||||||
summary: Update full blog properties. Unsetted parameters will be erased
|
summary: Update full blog properties. Unsetted parameters will be erased
|
||||||
parameters:
|
parameters:
|
||||||
|
- name: x_dc_key
|
||||||
|
in: header
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
- name: blog-id
|
- name: blog-id
|
||||||
in: path
|
in: path
|
||||||
type: string
|
type: string
|
||||||
|
@ -281,6 +326,10 @@ paths:
|
||||||
delete:
|
delete:
|
||||||
summary: Delete the post
|
summary: Delete the post
|
||||||
parameters:
|
parameters:
|
||||||
|
- name: x_dc_key
|
||||||
|
in: header
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
- name: blog-id
|
- name: blog-id
|
||||||
in: path
|
in: path
|
||||||
type: string
|
type: string
|
||||||
|
@ -304,6 +353,10 @@ paths:
|
||||||
get:
|
get:
|
||||||
summary: Get list of available categories
|
summary: Get list of available categories
|
||||||
parameters:
|
parameters:
|
||||||
|
- name: x_dc_key
|
||||||
|
in: header
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
- name: blog-id
|
- name: blog-id
|
||||||
in: path
|
in: path
|
||||||
type: string
|
type: string
|
||||||
|
@ -323,6 +376,10 @@ paths:
|
||||||
post:
|
post:
|
||||||
summary: Create a new category
|
summary: Create a new category
|
||||||
parameters:
|
parameters:
|
||||||
|
- name: x_dc_key
|
||||||
|
in: header
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
- name: blog-id
|
- name: blog-id
|
||||||
in: path
|
in: path
|
||||||
type: string
|
type: string
|
||||||
|
@ -346,6 +403,10 @@ paths:
|
||||||
get:
|
get:
|
||||||
summary: get one category properties
|
summary: get one category properties
|
||||||
parameters:
|
parameters:
|
||||||
|
- name: x_dc_key
|
||||||
|
in: header
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
- name: blog-id
|
- name: blog-id
|
||||||
in: path
|
in: path
|
||||||
type: string
|
type: string
|
||||||
|
|
24
inc/class.rest.auth.php
Normal file
24
inc/class.rest.auth.php
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class restAuth extends dcAuth
|
||||||
|
{
|
||||||
|
# L'utilisateur n'a pas le droit de changer son mot de passe
|
||||||
|
protected $allow_pass_change = false;
|
||||||
|
|
||||||
|
# La méthode de vérification du mot de passe
|
||||||
|
public function checkUser($api_key)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
# Si un mot de passe a été donné, nous allons le vérifier avec la
|
||||||
|
# méthode auth.login XML-RPC.
|
||||||
|
|
||||||
|
|
||||||
|
# Les opérations précédentes se sont déroulées sans erreur, nous
|
||||||
|
# pouvons maintenant appeler la méthode parente afin d'initialiser
|
||||||
|
# l'utilisateur dans l'object $core->auth
|
||||||
|
return parent::checkUser($user_id,$pwd);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
120
inc/class.rest.query.php
Normal file
120
inc/class.rest.query.php
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class RestQuery{
|
||||||
|
public $response_code;
|
||||||
|
public $response_message; //array
|
||||||
|
private $queryObj;
|
||||||
|
|
||||||
|
public function __construct($httpMethod,$params){
|
||||||
|
|
||||||
|
//définir la methode API (pas HTML) appelée
|
||||||
|
switch($httpMethod){
|
||||||
|
case "get":
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "post":
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "put":
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "patch":
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "delete":
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$this->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...
|
Loading…
Reference in New Issue
Block a user