From fa0663d7df0cfcf0818e182f3d2d19fc6be2a5d1 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 8 Dec 2009 09:19:48 -0800 Subject: Rename the backing table from rest_keys to user_access_tokens Implement an api to format the errors and success messages Removed the custom routing... urls are now /rest// --- modules/rest/helpers/rest.php | 69 +++++++++++++++++++++++++++++++++ modules/rest/helpers/rest_event.php | 8 ++-- modules/rest/helpers/rest_installer.php | 4 +- 3 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 modules/rest/helpers/rest.php (limited to 'modules/rest/helpers') diff --git a/modules/rest/helpers/rest.php b/modules/rest/helpers/rest.php new file mode 100644 index 00000000..34852a9e --- /dev/null +++ b/modules/rest/helpers/rest.php @@ -0,0 +1,69 @@ + "OK"); + if (!empty($message)) { + $response["message"] = (string)$message; + } + // We don't need to save the session for this request + Session::abort_save(); + return json_encode(array_merge($response, $response_data)); + } + + private static function _format_response($message, $log_message) { + if (!empty($log_message)) { + Kohana::log("info", $log_message); + } + // We don't need to save the session for this request + Session::abort_save(); + return json_encode(array("status" => "ERROR", "message" => (string)$message)); + } +} diff --git a/modules/rest/helpers/rest_event.php b/modules/rest/helpers/rest_event.php index fd1c25be..ce926107 100644 --- a/modules/rest/helpers/rest_event.php +++ b/modules/rest/helpers/rest_event.php @@ -22,7 +22,7 @@ class rest_event { * the user_homes directory. */ static function user_before_delete($user) { - ORM::factory("rest_key") + ORM::factory("user_access_token") ->where("id", $user->id) ->delete_all(); } @@ -32,7 +32,7 @@ class rest_event { * on every add. */ static function user_add_form_admin_completed($user, $form) { - $key = ORM::factory("rest_key"); + $key = ORM::factory("user_access_token"); $key->user_id = $user->id; $key->access_key = md5($user->name . rand()); $key->save(); @@ -56,7 +56,7 @@ class rest_event { * Get the form fields for user edit */ static function _get_access_key_form($user, $form) { - $key = ORM::factory("rest_key") + $key = ORM::factory("user_access_token") ->where("user_id", $user->id) ->find(); @@ -66,7 +66,7 @@ class rest_event { $key->save(); } - $form->edit_user->input("access_key") + $form->edit_user->input("user_access_token") ->value($key->access_key) ->readonly("readonly") ->class("g-form-static") diff --git a/modules/rest/helpers/rest_installer.php b/modules/rest/helpers/rest_installer.php index 274002c0..9fbc5b2e 100644 --- a/modules/rest/helpers/rest_installer.php +++ b/modules/rest/helpers/rest_installer.php @@ -20,7 +20,7 @@ class rest_installer { static function install() { Database::instance() - ->query("CREATE TABLE {rest_keys} ( + ->query("CREATE TABLE {user_access_tokens} ( `id` int(9) NOT NULL auto_increment, `user_id` int(9) NOT NULL, `access_key` char(32) NOT NULL, @@ -32,6 +32,6 @@ class rest_installer { } static function uninstall() { - Database::instance()->query("DROP TABLE IF EXISTS {rest_keys}"); + Database::instance()->query("DROP TABLE IF EXISTS {user_access_tokens}"); } } -- cgit v1.2.3