From 8f5191f5cfa7ec4bd2073a409f3b8c124c0aee2e Mon Sep 17 00:00:00 2001 From: Synox Date: Thu, 14 Jun 2018 18:57:50 +0200 Subject: [PATCH] moved to json api --- src/json-api.php | 11 +++++++++++ src/router.php | 5 ----- src/view.php | 3 +-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/json-api.php b/src/json-api.php index f6fc3c2..d4b8f54 100644 --- a/src/json-api.php +++ b/src/json-api.php @@ -28,6 +28,11 @@ class RestRouter extends Router { && $this->action === 'random_username') { return new RedirectToRandomAddressController($this->config['domains']); + } elseif ($this->action === "has_new_messages" + && isset($this->get_vars['email_ids']) + && isset($this->get_vars['address'])) { + return new HasNewMessagesController($this->get_vars['email_ids'], $this->get_vars['address'], $this->config['domains'], $this->config['blocked_usernames']); + } elseif ($this->method === "GET" && $this->action === 'emails' && isset($this->get_vars['address'])) { @@ -76,6 +81,12 @@ class JsonViewHandler implements ViewHandler { function invalid_input($config_domains) { $this->error(400, 'Bad Request'); } + + function new_mail_counter_json($counter) { + header('Content-Type: application/json'); + print json_encode($counter); + } + } diff --git a/src/router.php b/src/router.php index 2b91c50..6896e5b 100644 --- a/src/router.php +++ b/src/router.php @@ -37,11 +37,6 @@ class Router { && isset($this->get_vars['address'])) { return new DeleteEmailController($this->get_vars['email_id'], $this->get_vars['address'], $this->config['domains'], $this->config['blocked_usernames']); - } elseif ($this->action === "has_new_messages" - && isset($this->get_vars['email_ids']) - && isset($this->get_vars['address'])) { - return new HasNewMessagesController($this->get_vars['email_ids'], $this->get_vars['address'], $this->config['domains'], $this->config['blocked_usernames']); - } elseif ($this->action === 'random') { return new RedirectToRandomAddressController($this->config['domains']); diff --git a/src/view.php b/src/view.php index 1219206..2fc4d61 100644 --- a/src/view.php +++ b/src/view.php @@ -53,7 +53,6 @@ class ServerRenderViewHandler implements ViewHandler { } function new_mail_counter_json($counter) { - header('Content-Type: application/json'); - print json_encode($counter); + $this->error("not implemented for ServerRenderViewHandler, see json-api"); } }