1
0

Made the Gallery3::load() and create() functions a little more robust

Added example for REST comments.
This commit is contained in:
Bharat Mediratta 2010-06-20 09:54:22 -07:00
parent 2b75fef32f
commit 033e35d07e
2 changed files with 14 additions and 2 deletions

View File

@ -111,6 +111,10 @@ class Gallery3 {
* @return object Gallery3
*/
public function create($url, $token) {
if (!is_string($url)) {
throw new Gallery3_Exception("Invalid url: " . var_export($url));
}
$response = Gallery3_Helper::request(
"post", $url, $token, array("entity" => $this->data->entity), $this->file);
$this->url = $response->url;
@ -153,7 +157,7 @@ class Gallery3 {
public function load() {
$response = Gallery3_Helper::request("get", $this->url, $this->token);
$this->data = $response;
$this->original_entity = (array)$response->entity;
$this->original_entity = isset($response->entity) ? (array)$response->entity : null;
return $this;
}
}

View File

@ -13,6 +13,7 @@ alert("Connect to $SITE_URL");
$auth = Gallery3::login($SITE_URL, $USER, $PASSWORD);
$root = Gallery3::factory("$SITE_URL/item/1", $auth);
$tags = Gallery3::factory("$SITE_URL/tags", $auth);
$comments = Gallery3::factory("$SITE_URL/comments", $auth);
$tag = Gallery3::factory()
->set("name", "My Tag")
@ -45,6 +46,13 @@ for ($i = 0; $i < 2; $i++) {
$album->load();
alert("Album members: <b>" . join(", ", $album->data->members) . "</b>");
$comment = Gallery3::factory()
->set("item", $album->data->members[0])
->set("type", "comment")
->set("text", "This is a random comment-- whee!")
->create($comments->url, $auth);
alert("Comment: <b>{$comment->url}</b>");
alert("Reorder the album");
$album
->set_members(array($album->data->members[1], $album->data->members[0]))
@ -93,7 +101,7 @@ $tag->delete();
alert("Done!");
function alert($msg) {
print "$msg <br/>";
print "$msg <br/>\n";
flush();
}
?>