public static function run()
 {
     $apikey = $_SERVER['PHP_AUTH_USER'];
     if (empty($apikey) === true) {
         $apikey = filter_input(INPUT_POST, 'apikey');
     }
     if (strlen($apikey) == 0) {
         $result = Nl2go_ResponseHelper::generateErrorResponse('api-key is missing', Nl2go_ResponseHelper::ERRNO_PLUGIN_CREDENTIALS_MISSING);
         echo $result;
         exit;
     }
     if (get_option('n2go_apikey') === $apikey) {
         $method = get_query_var('method');
         switch ($method) {
             case 'getPost':
                 $id = get_query_var('postId');
                 $post = self::getPost($id);
                 if ($post === null) {
                     $result = Nl2go_ResponseHelper::generateErrorResponse('no post found', Nl2go_ResponseHelper::ERRNO_PLUGIN_OTHER);
                 } else {
                     $result = Nl2go_ResponseHelper::generateSuccessResponse(array('post' => $post));
                 }
                 break;
             case 'test':
                 $result = Nl2go_ResponseHelper::generateSuccessResponse();
                 //$result = array('success' => true, 'message' => 'API Connected!');
                 break;
             case 'getVersion':
                 $pluginInfo = get_plugin_data(WP_PLUGIN_DIR . '/newsletter2go/newsletter2go.php');
                 $result = Nl2go_ResponseHelper::generateSuccessResponse(array('version' => str_replace('.', '', $pluginInfo['Version'])));
                 //$result = array('success' => true, 'message' => 'OK', 'version' => get_option('n2go_plugin_version'));
                 break;
             default:
                 $result = Nl2go_ResponseHelper::generateErrorResponse('Invalid method call', Nl2go_ResponseHelper::ERRNO_PLUGIN_OTHER);
                 break;
         }
     } else {
         $result = Nl2go_ResponseHelper::generateErrorResponse('API Key is invalid', Nl2go_ResponseHelper::ERRNO_PLUGIN_CREDENTIALS_WRONG);
     }
     $charset = get_option('blog_charset');
     if (!headers_sent()) {
         header('HTTP/1.1 200 OK', true);
         header("Content-Type: application/json; charset={$charset}", true);
     }
     echo $result;
     exit;
 }
 public function processRequest($apikey, $getParams, $postParams)
 {
     $this->apikey = $apikey;
     if ($apikey == null && isset($postParams['apikey'])) {
         $this->apikey = $postParams['apikey'];
     }
     $this->getParams = $getParams;
     $this->postParams = $postParams;
     $result = array('success' => 1);
     if (!$this->checkApiKey()) {
         $result = Nl2go_ResponseHelper::generateErrorResponse('Invalid or missing API key!', Nl2go_ResponseHelper::ERRNO_PLUGIN_CREDENTIALS_WRONG);
     } else {
         switch ($this->postParams['action']) {
             case 'test':
                 $result['message'] = $this->test();
                 break;
             case 'getPost':
                 $post = $this->getPost();
                 if (!$post) {
                     $result = Nl2go_ResponseHelper::generateErrorResponse('Post with given id not found!', Nl2go_ResponseHelper::ERRNO_PLUGIN_OTHER);
                 } else {
                     $result = Nl2go_ResponseHelper::generateSuccessResponse(array('post' => $post));
                 }
                 break;
             case 'getPluginVersion':
                 $version = $this->getPluginVersion();
                 $result = Nl2go_ResponseHelper::generateSuccessResponse(array('version' => $version));
                 break;
             default:
                 $result = Nl2go_ResponseHelper::generateErrorResponse('Invalid action!', Nl2go_ResponseHelper::ERRNO_PLUGIN_OTHER);
                 break;
         }
     }
     drupal_json_output($result);
     drupal_exit();
 }