diff --git a/client/Gallery3.php b/client/Gallery3.php
index ecd6b431..a0b930a2 100644
--- a/client/Gallery3.php
+++ b/client/Gallery3.php
@@ -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;
}
}
diff --git a/client/example.php b/client/example.php
index 934c6d23..1c96cd1b 100644
--- a/client/example.php
+++ b/client/example.php
@@ -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: " . join(", ", $album->data->members) . "");
+$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: {$comment->url}");
+
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
";
+ print "$msg
\n";
flush();
}
?>
\ No newline at end of file