diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-12-09 08:41:38 -0800 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-12-09 08:41:38 -0800 |
commit | 367f2218f6bc278a7d0bd870e03a5d631155871a (patch) | |
tree | f5a8d428ca8c736b9b25273ee043e2e57536ac22 | |
parent | 3c30d595ae6a9a82e06f5427150d3667f00ef695 (diff) |
Use the relative url cache to look up resources instead of the relative path. This allows us to forego the extension as part of the REST url. As well, urls are consistent between normal usage and rest usage.
-rw-r--r-- | modules/gallery/helpers/gallery_rest.php | 6 | ||||
-rw-r--r-- | modules/gallery/tests/Gallery_Rest_Helper_Test.php | 4 | ||||
-rw-r--r-- | modules/rest/controllers/rest.php | 1 | ||||
-rw-r--r-- | modules/rest/tests/Rest_Controller_Test.php | 16 |
4 files changed, 14 insertions, 13 deletions
diff --git a/modules/gallery/helpers/gallery_rest.php b/modules/gallery/helpers/gallery_rest.php index dba109fd..043e17b5 100644 --- a/modules/gallery/helpers/gallery_rest.php +++ b/modules/gallery/helpers/gallery_rest.php @@ -24,7 +24,7 @@ class gallery_rest_Core { } $item = ORM::factory("item") - ->where("relative_path_cache", $request->path) + ->where("relative_url_cache", $request->path) ->viewable() ->find(); @@ -32,7 +32,7 @@ class gallery_rest_Core { return rest::not_found("Resource: {$request->path} missing."); } - $response_data = array("path" => $item->relative_path(), + $response_data = array("path" => $item->relative_url(), "title" => $item->title, "thumb_url" => $item->thumb_url(), "url" => $item->abs_url(), @@ -54,7 +54,7 @@ class gallery_rest_Core { foreach ($item->viewable()->children($limit, $offset, $where) as $child) { $children[] = array("type" => $child->type, "has_children" => $child->children_count() > 0, - "path" => $child->relative_path(), + "path" => $child->relative_url(), "title" => $child->title); } diff --git a/modules/gallery/tests/Gallery_Rest_Helper_Test.php b/modules/gallery/tests/Gallery_Rest_Helper_Test.php index 1bf0b1ca..b874863f 100644 --- a/modules/gallery/tests/Gallery_Rest_Helper_Test.php +++ b/modules/gallery/tests/Gallery_Rest_Helper_Test.php @@ -58,7 +58,7 @@ class Gallery_Rest_Helper_Test extends Unit_Test_Case { $this->assert_equal( json_encode(array("status" => "OK", - "album" => array("path" => $this->_child->relative_path(), + "album" => array("path" => $this->_child->relative_url_path(), "title" => $this->_child->title, "thumb_url" => $this->_child->thumb_url(), "url" => $this->_child->abs_url(), @@ -67,7 +67,7 @@ class Gallery_Rest_Helper_Test extends Unit_Test_Case { "children" => array(array( "type" => "photo", "has_children" => false, - "path" => $this->_photo->relative_path(), + "path" => $this->_photo->relative_url_path(), "title" => $this->_photo->title))))), gallery_rest::get($request)); } diff --git a/modules/rest/controllers/rest.php b/modules/rest/controllers/rest.php index 1ec24493..577d8aeb 100644 --- a/modules/rest/controllers/rest.php +++ b/modules/rest/controllers/rest.php @@ -34,6 +34,7 @@ class Rest_Controller extends Controller { print rest::forbidden("Invalid password for '{$request->user}'."); return; } + $key = ORM::factory("user_access_token") ->where("user_id", $user->id) ->find(); diff --git a/modules/rest/tests/Rest_Controller_Test.php b/modules/rest/tests/Rest_Controller_Test.php index d9b576de..5f7bdfe4 100644 --- a/modules/rest/tests/Rest_Controller_Test.php +++ b/modules/rest/tests/Rest_Controller_Test.php @@ -100,12 +100,12 @@ class Rest_Controller_Test extends Unit_Test_Case { $this->assert_equal( json_encode(array("status" => "OK", "message" => (string)t("Processed"), - "photo" => array("path" => $this->_photo->relative_path(), + "photo" => array("path" => $this->_photo->relative_url(), "title" => $this->_photo->title, "thumb_url" => $this->_photo->thumb_url(), "description" => $this->_photo->description, "internet_address" => $this->_photo->slug))), - $this->_call_controller("rest", explode("/", $this->_photo->relative_path()))); + $this->_call_controller("rest", explode("/", $this->_photo->relative_url()))); } public function rest_get_resource_invalid_key_test() { @@ -126,7 +126,7 @@ class Rest_Controller_Test extends Unit_Test_Case { $this->assert_equal( json_encode(array("status" => "ERROR", "message" => (string)t("Authorization failed"))), - $this->_call_controller("rest", explode("/", $this->_photo->relative_path()))); + $this->_call_controller("rest", explode("/", $this->_photo->relative_url()))); } public function rest_get_resource_no_handler_test() { @@ -136,7 +136,7 @@ class Rest_Controller_Test extends Unit_Test_Case { $this->assert_equal( json_encode(array("status" => "ERROR", "message" => (string)t("Service not implemented"))), - $this->_call_controller("rest", explode("/", $this->_photo->relative_path()))); + $this->_call_controller("rest", explode("/", $this->_photo->relative_url()))); } public function rest_get_resource_test() { @@ -145,12 +145,12 @@ class Rest_Controller_Test extends Unit_Test_Case { $this->assert_equal( json_encode(array("status" => "OK", "message" => (string)t("Processed"), - "photo" => array("path" => $this->_photo->relative_path(), + "photo" => array("path" => $this->_photo->relative_url(), "title" => $this->_photo->title, "thumb_url" => $this->_photo->thumb_url(), "description" => $this->_photo->description, "internet_address" => $this->_photo->slug))), - $this->_call_controller("rest", explode("/", $this->_photo->relative_path()))); + $this->_call_controller("rest", explode("/", $this->_photo->relative_url()))); } private function _call_controller($method="access_key", $arg=null) { @@ -171,9 +171,9 @@ class rest_rest { static function get($request) { self::$request = $request; $item = ORM::factory("item") - ->where("relative_path_cache", $request->path) + ->where("relative_url_cache", $request->path) ->find(); - $response["path"] = $item->relative_path(); + $response["path"] = $item->relative_url(); $response["title"] = $item->title; $response["thumb_url"] = $item->thumb_url(); $response["description"] = $item->description; |