From 96f9aa482da8bbc409af8c6c213010ee35837149 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 4 Jan 2010 21:49:40 -0800 Subject: [PATCH] Gallery3::create_xxx() methods are now just create(). We don't differentiate between types of resources at this level, it's not necessary. Add example code for dealing with tags. --- client/Gallery3.php | 28 +++++++++------------------- client/example.php | 29 ++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/client/Gallery3.php b/client/Gallery3.php index e7b9337a..d3557948 100644 --- a/client/Gallery3.php +++ b/client/Gallery3.php @@ -40,7 +40,7 @@ class Gallery3 { $response = Gallery3_Helper::request( "post", $url, null, array("user" => $user, "password" => $pass)); - return self::factory($url, $response->token, null); + return self::factory($url, $response, null); } /** @@ -92,26 +92,12 @@ class Gallery3 { } /** - * Create a new album. You must specify a name for the album, and call save() before the album - * will be created in the remote Gallery 3. + * Create a new resource. You must call save() for it to be created in the remote Gallery 3. * * @return object Gallery3 */ - public function create_album() { - return Gallery3::factory(null, $this->token, $this) - ->set_value("type", "album"); - } - - /** - * Create a new photo. You must specify a name for the photo and use set_file() to attach an - * image file. Finally, you must call save() before the photo will be created in the remote - * Gallery 3. - * - * @return object Gallery3 - */ - public function create_photo() { - return Gallery3::factory(null, $this->token, $this) - ->set_value("type", "photo"); + public function create() { + return Gallery3::factory(null, $this->token, $this); } /** @@ -127,7 +113,11 @@ class Gallery3 { "post", $this->parent->url, $this->token, $this->data, $this->file); } - return $this->load($response->url); + if (!empty($response->url)) { + $this->load($response->url); + } + + return $this; } /** diff --git a/client/example.php b/client/example.php index f22709bc..e31903e3 100644 --- a/client/example.php +++ b/client/example.php @@ -9,29 +9,44 @@ if (file_exists("local_config.php")) { include("local_config.php"); } -// Connect to our Gallery +print "Connect to $SITE_URL
"; $gallery3 = Gallery3::connect($SITE_URL, $USER, $PASSWORD); - $root = $gallery3->get("gallery"); +$tags = $gallery3->get("tags"); -// Create a new album -$album = $root->create_album() +print "Create a tag
"; +$tag = $tags->create() + ->set_value("name", "My Tag") + ->save(); + +print "Create a new album
"; +$album = $root->create() + ->set_value("type", "album") ->set_value("name", "Sample Album") ->set_value("title", "This is my Sample Album") ->save(); -// Upload a new photo -$photo = $album->create_photo() +print "Upload a photo
"; +$photo = $album->create() + ->set_value("type", "photo") ->set_value("name", "Sample Photo") ->set_value("title", "Sample Photo") ->set_file("/tmp/foo.jpg") ->save(); -// Look up the album and modify it. +print "Tag the photo
"; +$tag->create() + ->set_value("url", $photo->url) + ->save(); + +print "Modify the album
"; $album = $root->get("Sample-Album") ->set_value("title", "This is my title") ->save(); // Now delete the album +print "Delete the album
"; $album->delete(); + +print "Done!
"; ?> \ No newline at end of file