Skip to content

Instantly share code, notes, and snippets.

@joernroeder
Created May 25, 2012 09:41
Show Gist options
  • Save joernroeder/2786989 to your computer and use it in GitHub Desktop.
Save joernroeder/2786989 to your computer and use it in GitHub Desktop.
JJRestApiExtension Example
<?php
class ExtensionName_RestApiExtension extends JJ_RestApiExtension {
public static $url_handlers = array(
'ExtensionName/$Action/$ID' => 'handleExtensionName'
);
public static $allowed_actions = array(
'handleExtensionName'
);
/**
* sets api access to read only
*
* @var boolean
*/
protected $isReadOnly = true; // remove this line if your Extension uses read/write access
/**
* returns the current user
*
* @todo modify fields via url params. restrict fields to api_access[$context].
*
* @return Data
*/
public function handleExtensionName($request) {
// security checks and response headers
parent::handle();
// use $this->convert{type} if you return raw data such as arrays
return $this->formatter->convertArray(array("foo" => "bar"));
$object = DataObject::get_by_id("Foo", 1);
// get options
$opts = $this->getOptionsFor("Foo", "view"); // api_access key (view/edit/delete etc)
// use $this->toApiObject($obj, $opts) if you're playing with DataObjects
return $this->toApiObject($object, $opts)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment