1
0

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.
This commit is contained in:
Bharat Mediratta 2010-01-04 21:49:40 -08:00
parent 2f60a0ef11
commit 96f9aa482d
2 changed files with 31 additions and 26 deletions

View File

@ -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;
}
/**

View File

@ -9,29 +9,44 @@ if (file_exists("local_config.php")) {
include("local_config.php");
}
// Connect to our Gallery
print "Connect to $SITE_URL <br/>";
$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 <br/>";
$tag = $tags->create()
->set_value("name", "My Tag")
->save();
print "Create a new album <br/>";
$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 <br/>";
$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 <br/>";
$tag->create()
->set_value("url", $photo->url)
->save();
print "Modify the album <br/>";
$album = $root->get("Sample-Album")
->set_value("title", "This is my title")
->save();
// Now delete the album
print "Delete the album <br/>";
$album->delete();
print "Done! <br/>";
?>