master
Gnieark 7 years ago
parent dd698907c6
commit 05c416f0e8

@ -1,7 +1,6 @@
<?php
if (!defined('DC_CONTEXT_ADMIN')) { return; }
// dead but useful code, in order to have translations
$_menu['Blog']->addItem(__('Rest API'),
'plugin.php?p=rest',

@ -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;
}
}
}

@ -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

@ -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);
}
}

@ -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 =>"Im 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…
Cancel
Save