Permalink
Browse files

REST_AUTH interface for authenticating connections to models, Combine…

…d Exceptions and send_code(), REST::prefix() getter/setter, cleaned up code
  • Loading branch information...
1 parent f1742a9 commit bab6b96683a231f1fce6dbbe1260b72238440184 @jerfowler committed Mar 20, 2012
View
@@ -8,16 +8,16 @@
* PHP >= 5.3
##Features
-* HTTP_X_HTTP_METHOD_OVERRIDE support
+* X-HTTP-METHOD-OVERRIDE support
* Cross-Origin Resource Sharing
-* ETags enabled
+* ETags
##Installation
* `cd modules`
* `git clone git://github.com/jerfowler/REST.git`
* Enable the REST module in bootstrap
-* create REST extended models in classes/model/rest
+* Create REST extended models in classes/model/rest
* Optional: create your own custom controller_rest
##Controllers handle content type and output
@@ -32,7 +32,7 @@ class Controller_Template_REST extends Controller
```
###The Rest module gets instantiated in the before method of the controller
* The model is determined by the Controller's action
-* REST supports HTTP_X_HTTP_METHOD_OVERRIDE by using `method_override(TRUE)`
+* REST supports X-HTTP-METHOD-OVERRIDE by using `method_override(TRUE)`
```php
/**
@@ -3,7 +3,7 @@
/**
* RESTful web service library.
*
- * @package jeremyf76/REST
+ * @package jerfowler/REST
* @author Jeremy Fowler
* @copyright (c) 2012 Jeremy Fowler
* @license http://www.opensource.org/licenses/BSD-3-Clause
@@ -3,7 +3,7 @@
/**
* RESTful web service library.
*
- * @package jeremyf76/REST
+ * @package jerfowler/REST
* @author Jeremy Fowler
* @copyright (c) 2012 Jeremy Fowler
* @license http://www.opensource.org/licenses/BSD-3-Clause
@@ -1,6 +1,6 @@
<?php defined('SYSPATH') or die('No direct script access.');
-class Model_REST_Test implements REST_CORS, REST_Method_Basic {
+class Model_REST_Test implements REST_CORS, REST_AUTH, REST_Method_Basic {
protected static $origin = array(
'http://example.com:3001',
@@ -14,11 +14,23 @@ class Model_REST_Test implements REST_CORS, REST_Method_Basic {
* @var mixed
*/
protected $_data = array(
- 1 => array('one', 'two', 'three'),
- 2 => array('four', 'five', 'six'),
- 3 => array('seven', 'eight', 'nine')
+ array('id' => 1, 'title' => 'one', 'author' => 'Jeremy', 'content' => 'Hi'),
+ array('id' => 2, 'title' => 'two', 'author' => 'Tara', 'content' => 'Hello'),
+ array('id' => 3, 'title' => 'three', 'author' => 'Isaac', 'content' => 'Hey'),
+ array('id' => 4, 'title' => 'four', 'author' => 'Zander', 'content' => 'Yo'),
+ array('id' => 5, 'title' => 'five', 'author' => 'Bryan', 'content' => 'Holla'),
+ array('id' => 6, 'title' => 'six', 'author' => 'Jon', 'content' => 'Ciao'),
+ array('id' => 7, 'title' => 'seven', 'author' => 'Leah', 'content' => 'How do you do?'),
+ array('id' => 8, 'title' => 'eight', 'author' => 'Sean', 'content' => 'Bonjour'),
+ array('id' => 9, 'title' => 'nine', 'author' => 'Scott', 'content' => 'what\'s up')
);
+ public function rest_auth(Rest $rest)
+ {
+ $user = Auth::instance()->get_user();
+ return $rest->method() == 'OPTIONS' OR $user !== FALSE;
+ }
+
/**
* Cross-Origin Resource Sharing
*
@@ -86,7 +98,6 @@ public function rest_put(Rest $rest)
// TODO
$rest->send_code(403); //Forbidden
}
-
}
/**
@@ -121,4 +132,5 @@ public function rest_delete(Rest $rest)
}
$rest->send_code(204);
}
+
}
View
@@ -3,7 +3,7 @@
/**
* RESTful web service library.
*
- * @package jeremyf76/REST
+ * @package jerfowler/REST
* @author Jeremy Fowler
* @copyright (c) 2012 Jeremy Fowler
* @license http://www.opensource.org/licenses/BSD-3-Clause
View
@@ -0,0 +1,14 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+/**
+ * RESTful web service library.
+ *
+ * @package jerfowler/REST
+ * @author Jeremy Fowler
+ * @copyright (c) 2012 Jeremy Fowler
+ * @license http://www.opensource.org/licenses/BSD-3-Clause
+ */
+
+interface REST_AUTH extends REST_Model {
+ public function rest_auth(Rest $rest);
+}
@@ -3,7 +3,7 @@
/**
* RESTful web service library.
*
- * @package jeremyf76/REST
+ * @package jerfowler/REST
* @author Jeremy Fowler
* @copyright (c) 2012 Jeremy Fowler
* @license http://www.opensource.org/licenses/BSD-3-Clause
@@ -3,7 +3,7 @@
/**
* RESTful web service library.
*
- * @package jeremyf76/REST
+ * @package jerfowler/REST
* @author Jeremy Fowler
* @copyright (c) 2012 Jeremy Fowler
* @license http://www.opensource.org/licenses/BSD-3-Clause
@@ -3,7 +3,7 @@
/**
* RESTful web service library.
*
- * @package jeremyf76/REST
+ * @package jerfowler/REST
* @author Jeremy Fowler
* @copyright (c) 2012 Jeremy Fowler
* @license http://www.opensource.org/licenses/BSD-3-Clause
@@ -3,7 +3,7 @@
/**
* RESTful web service library.
*
- * @package jeremyf76/REST
+ * @package jerfowler/REST
* @author Jeremy Fowler
* @copyright (c) 2012 Jeremy Fowler
* @license http://www.opensource.org/licenses/BSD-3-Clause
@@ -3,7 +3,7 @@
/**
* RESTful web service library.
*
- * @package jeremyf76/REST
+ * @package jerfowler/REST
* @author Jeremy Fowler
* @copyright (c) 2012 Jeremy Fowler
* @license http://www.opensource.org/licenses/BSD-3-Clause
@@ -3,7 +3,7 @@
/**
* RESTful web service library.
*
- * @package jeremyf76/REST
+ * @package jerfowler/REST
* @author Jeremy Fowler
* @copyright (c) 2012 Jeremy Fowler
* @license http://www.opensource.org/licenses/BSD-3-Clause
@@ -3,7 +3,7 @@
/**
* RESTful web service library.
*
- * @package jeremyf76/REST
+ * @package jerfowler/REST
* @author Jeremy Fowler
* @copyright (c) 2012 Jeremy Fowler
* @license http://www.opensource.org/licenses/BSD-3-Clause
@@ -3,7 +3,7 @@
/**
* RESTful web service library.
*
- * @package jeremyf76/REST
+ * @package jerfowler/REST
* @author Jeremy Fowler
* @copyright (c) 2012 Jeremy Fowler
* @license http://www.opensource.org/licenses/BSD-3-Clause
Oops, something went wrong.

0 comments on commit bab6b96

Please sign in to comment.