Permalink
Browse files

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

Added example for REST comments.
  • Loading branch information...
1 parent 2b75fef commit 033e35d07eb4d8649b69e3b1c4f448fc5dab38a3 @bharat bharat committed Jun 20, 2010
Showing with 14 additions and 2 deletions.
  1. +5 −1 client/Gallery3.php
  2. +9 −1 client/example.php
View
@@ -111,6 +111,10 @@ public function set_file($file) {
* @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 @@ public function delete() {
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
@@ -13,6 +13,7 @@
$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 @@
$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 @@
alert("Done!");
function alert($msg) {
- print "$msg <br/>";
+ print "$msg <br/>\n";
flush();
}
?>

0 comments on commit 033e35d

Please sign in to comment.