<?php

class LinksgardenRest {

    private $nonce;

    public static function init(){
        add_action('rest_api_init', array(__CLASS__, 'set_routes'));
    }

    public static function set_routes(){
        require_once LG_PLUGIN_DIR . 'modele/LinksgardenAPI.php';
        self::lg_new_route();
    }

    public static function lg_new_route(){
        register_rest_route('lg/v1', "/API", array(
            'methods' => 'POST',
            'callback' => array('LinksgardenAPI', 'getAction'),
            'permission_callback' => '__return_true'
        ));
    }

    public static function isApiSecret($apiKey, $signature){
        if ($apiKey === get_option('api_lg_public') && md5($apiKey.$signature) === get_option('api_lg_secret')) {
            return true;
        }
        return false;
    }
}
