Author: chabotc
Date: Thu Jun 25 09:52:15 2009
New Revision: 788306
URL: http://svn.apache.org/viewvc?rev=788306&view=rev
Log:
Adding missing files from Album/Media item commit, doh
Added:
incubator/shindig/trunk/php/src/social/model/Album.php
incubator/shindig/trunk/php/src/social/service/AlbumHandler.php
incubator/shindig/trunk/php/src/social/service/MediaItemHandler.php
incubator/shindig/trunk/php/src/social/spi/AlbumService.php
incubator/shindig/trunk/php/src/social/spi/MediaItemService.php
Added: incubator/shindig/trunk/php/src/social/model/Album.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/model/Album.php?rev=788306&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/social/model/Album.php (added)
+++ incubator/shindig/trunk/php/src/social/model/Album.php Thu Jun 25 09:52:15
2009
@@ -0,0 +1,115 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ *
http://opensocial-resources.googlecode.com/svn/spec/0.9/OpenSocial-Specification.xml#opensocial.Album
+ */
+class Album {
+
+ public $id;
+ public $title;
+ public $description;
+ public $location;
+ public $mediaItemCount;
+ public $ownerId;
+ public $thumbnailUrl;
+ public $mediaMimeType;
+ public $mediaType;
+
+ public function __construct($id, $ownerId) {
+ $this->setId($id);
+ $this->setOwnerId($ownerId);
+ }
+
+ public function getId() {
+ return $this->id;
+ }
+
+ public function setId($id) {
+ $this->id = $id;
+ }
+
+ public function getTitle() {
+ return $this->title;
+ }
+
+ public function setTitle($title) {
+ $this->title = $title;
+ }
+
+ public function getDescription() {
+ return $this->description;
+ }
+
+ public function setDescription($description) {
+ $this->description = $description;
+ }
+
+ public function getLocation() {
+ return $this->location;
+ }
+
+ public function setLocation($location) {
+ $this->location = $location;
+ }
+
+ public function getMediaItemCount() {
+ return $this->mediaItemCount;
+ }
+
+ public function setMediaItemCount($mediaItemCount) {
+ $this->mediaItemCount = $mediaItemCount > 0 ? $mediaItemCount : 0;
+ }
+
+ public function getOwnerId() {
+ return $this->ownerId;
+ }
+
+ public function setOwnerId($ownerId) {
+ $this->ownerId = $ownerId;
+ }
+
+ public function getThumbnailUrl() {
+ return $this->thumbnailUrl;
+ }
+
+ public function setThumbnailUrl($thumbnailUrl) {
+ $this->thumbnailUrl = $thumbnailUrl;
+ }
+
+ public function getMediaMimeType() {
+ return $this->mediaMimeType;
+ }
+
+ public function setMediaMimeType($mediaMimeType) {
+ $this->mediaMimeType = $mediaMimeType;
+ }
+
+ public function getMediaType() {
+ return $this->mediaType;
+ }
+
+ public function setMediaType($mediaType) {
+ if (!in_array($mediaType, MediaItem::$TYPES)) {
+ throw new Exception("Invalid Media type");
+ }
+ $this->mediaType = $mediaType;
+ }
+}
Added: incubator/shindig/trunk/php/src/social/service/AlbumHandler.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/service/AlbumHandler.php?rev=788306&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/social/service/AlbumHandler.php (added)
+++ incubator/shindig/trunk/php/src/social/service/AlbumHandler.php Thu Jun 25
09:52:15 2009
@@ -0,0 +1,126 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * AlbumHandler checks POST/PUT/GET/DELETE requests params and call the album
service.
+ */
+class AlbumHandler extends DataRequestHandler {
+ private static $ALBUM_PATH = "/albums/{userId}/{groupId}/{albumId}";
+ private $service;
+
+ public function __construct() {
+ try {
+ $service = Config::get('album_service');
+ } catch (ConfigException $e) {
+ // Do nothing. If album_service is not specified in the config file.
+ // All the requests to album handler will throw not implemented
exception.
+ }
+ if ($service) {
+ $this->service = new $service();
+ }
+ }
+
+ /**
+ * Deletes the album. The URI structure: /{userId}/{groupId}/{albumId}
+ */
+ public function handleDelete(RequestItem $requestItem) {
+ $this->checkService();
+ $requestItem->applyUrlTemplate(self::$ALBUM_PATH);
+
+ $userIds = $requestItem->getUsers();
+ $groupId = $requestItem->getGroup();
+ $albumIds = $requestItem->getListParameter('albumId');
+
+ HandlerPreconditions::requireSingular($userIds, "userId must be singular
value.");
+ HandlerPreconditions::requireNotEmpty($groupId, "groupId must be
specified.");
+ HandlerPreconditions::requireSingular($albumIds, "albumId must singular
value.");
+
+ $this->service->deleteAlbum($userIds[0], $groupId, $albumIds[0],
$requestItem->getToken());
+ }
+
+ /**
+ * Gets the albums. The URI structure: /{userId}/{groupId}/{albumId}+.
+ */
+ public function handleGet(RequestItem $requestItem) {
+ $this->checkService();
+ $requestItem->applyUrlTemplate(self::$ALBUM_PATH);
+
+ $userIds = $requestItem->getUsers();
+ $groupId = $requestItem->getGroup();
+
+ HandlerPreconditions::requireSingular($userIds, "userId must be singular
value.");
+ HandlerPreconditions::requireNotEmpty($groupId, "groupId must be
specified.");
+
+ $options = new CollectionOptions($requestItem);
+ $fields = $requestItem->getFields();
+
+ $albumIds = $requestItem->getListParameter('albumId');
+
+ return $this->service->getAlbums($userIds[0], $groupId, $albumIds,
$options, $fields, $requestItem->getToken());
+ }
+
+ /**
+ * Creates an album. The URI structure: /{userId}/{groupId}.
+ */
+ public function handlePost(RequestItem $requestItem) {
+ $this->checkService();
+ $requestItem->applyUrlTemplate(self::$ALBUM_PATH);
+
+ $userIds = $requestItem->getUsers();
+ $groupId = $requestItem->getGroup();
+ $album = $requestItem->getParameter('album');
+
+ HandlerPreconditions::requireSingular($userIds, "userId must be of
singular value");
+ HandlerPreconditions::requireNotEmpty($groupId, "groupId must be
specified.");
+ HandlerPreconditions::requireNotEmpty($album, "album must be specified.");
+
+ return $this->service->createAlbum($userIds[0], $groupId, $album,
$requestItem->getToken());
+ }
+
+ /**
+ * Updates the album. The URI structure: /{userId}/{groupId}/{albumId}
+ */
+ public function handlePut(RequestItem $requestItem) {
+ $this->checkService();
+ $requestItem->applyUrlTemplate(self::$ALBUM_PATH);
+ $userIds = $requestItem->getUsers();
+ $groupId = $requestItem->getGroup();
+ $albumIds = $requestItem->getListParameter('albumId');
+ $album = $requestItem->getParameter('album');
+
+ HandlerPreconditions::requireSingular($userIds, "userId must be singular
value");
+ HandlerPreconditions::requireNotEmpty($groupId, "groupId must be
specified.");
+ HandlerPreconditions::requireSingular($albumIds, "albumId must be singular
value.");
+ HandlerPreconditions::requireNotEmpty($album, "album must be specified.");
+
+ $album['id'] = $albumIds[0];
+
+ return $this->service->updateAlbum($userIds[0], $groupId, $album,
$requestItem->getToken());
+ }
+
+ /**
+ * Checks whether the service is initialized.
+ */
+ private function checkService() {
+ if (!$this->service) {
+ throw new SocialSpiException("Not Implemented.",
ResponseError::$NOT_IMPLEMENTED);
+ }
+ }
+}
Added: incubator/shindig/trunk/php/src/social/service/MediaItemHandler.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/service/MediaItemHandler.php?rev=788306&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/social/service/MediaItemHandler.php (added)
+++ incubator/shindig/trunk/php/src/social/service/MediaItemHandler.php Thu Jun
25 09:52:15 2009
@@ -0,0 +1,128 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+class MediaItemHandler extends DataRequestHandler {
+ private static $MEDIA_ITEM_PATH =
"/mediaitems/{userId}/{groupId}/{albumId}/{mediaItemId}";
+
+ public function __construct() {
+ try {
+ $service = Config::get('media_item_service');
+ } catch (ConfigException $e) {
+ // Do nothing. If album_service is not specified in the config file.
+ // All the requests to album handler will throw not implemented
exception.
+ }
+ if ($service) {
+ $this->service = new $service();
+ }
+ }
+
+ /**
+ * Deletes the media items. The URI structure:
/{userId}/{groupId}/{albumId}/{mediaItemId}+
+ */
+ public function handleDelete(RequestItem $requestItem) {
+ $this->checkService();
+ $requestItem->applyUrlTemplate(self::$MEDIA_ITEM_PATH);
+
+ $userIds = $requestItem->getUsers();
+ $groupId = $requestItem->getGroup();
+ $albumIds = $requestItem->getListParameter('albumId');
+ $mediaItemIds = $requestItem->getListParameter('mediaItemId');
+
+ HandlerPreconditions::requireSingular($userIds, "userId must be singular
value.");
+ HandlerPreconditions::requireNotEmpty($groupId, "groupId must be
specified.");
+ HandlerPreconditions::requireSingular($albumIds, "albumId must be singular
value.");
+
+ $this->service->deleteMediaItems($userIds[0], $groupId, $albumIds[0],
$mediaItemIds, $requestItem->getToken());
+ }
+
+ /**
+ * Gets the media items. The URI structure:
/{userId}/{groupId}/{albumId}/{mediaItemId}+
+ */
+ public function handleGet(RequestItem $requestItem) {
+ $this->checkService();
+ $requestItem->applyUrlTemplate(self::$MEDIA_ITEM_PATH);
+
+ $userIds = $requestItem->getUsers();
+ $groupId = $requestItem->getGroup();
+ $albumIds = $requestItem->getListParameter("albumId");
+ $mediaItemIds = $requestItem->getListParameter("mediaItemId");
+
+ HandlerPreconditions::requireSingular($userIds, "userId must be singular
value.");
+ HandlerPreconditions::requireNotEmpty($groupId, "groupId must be
specified.");
+ HandlerPreconditions::requireSingular($albumIds, "albumId must be singular
value.");
+
+ $options = new CollectionOptions($requestItem);
+ $fields = $requestItem->getFields();
+
+ return $this->service->getMediaItems($userIds[0], $groupId, $albumIds[0],
$mediaItemIds, $options, $fields, $requestItem->getToken());
+ }
+
+ /**
+ * Creates the media item. The URI structure: /{userId}/{groupId}/{albumId}.
+ */
+ public function handlePost(RequestItem $requestItem) {
+ $this->checkService();
+ $requestItem->applyUrlTemplate(self::$MEDIA_ITEM_PATH);
+
+ $userIds = $requestItem->getUsers();
+ $groupId = $requestItem->getGroup();
+ $albumIds = $requestItem->getListParameter('albumId');
+ $mediaItem = $requestItem->getParameter('mediaItem');
+
+ HandlerPreconditions::requireSingular($userIds, "userId must be of
singular value");
+ HandlerPreconditions::requireNotEmpty($groupId, "groupId must be
specified.");
+ HandlerPreconditions::requireSingular($albumIds, "albumId must be sigular
value.");
+ HandlerPreconditions::requireNotEmpty($mediaItem, "mediaItem must be
specified.");
+
+ // The null param is the content data(image, video and audio binaries)
uploaded by the user.
+ return $this->service->createMediaItem($userIds[0], $groupId, $mediaItem,
null, $requestItem->getToken());
+ }
+
+ /**
+ * Updates the mediaItem. The URI structure:
/{userId}/{groupId}/{albumId}/{mediaItemId}
+ */
+ public function handlePut(RequestItem $requestItem) {
+ $this->checkService();
+ $requestItem->applyUrlTemplate(self::$MEDIA_ITEM_PATH);
+
+ $userIds = $requestItem->getUsers();
+ $groupId = $requestItem->getGroup();
+ $albumIds = $requestItem->getListParameter('albumId');
+ $mediaItemIds = $requestItem->getListParameter('mediaItemId');
+ $mediaItem = $requestItem->getParameter('mediaItem');
+
+ HandlerPreconditions::requireSingular($userIds, "userId must be singular
value.");
+ HandlerPreconditions::requireNotEmpty($groupId, "groupId must be
specified.");
+ HandlerPreconditions::requireSingular($albumIds, "albumId must be sigular
value.");
+ HandlerPreconditions::requireSingular($mediaItemIds, "mediaItemId must be
sigular value.");
+ HandlerPreconditions::requireNotEmpty($mediaItem, "mediaItem must be
specified.");
+
+ $mediaItem['id'] = $mediaItemIds[0];
+ $mediaItem['albumId'] = $albumIds[0];
+ // The null param is the content data(image, video and audio binaries)
uploaded by the user.
+ return $this->service->updateMediaItem($userIds[0], $groupId, $mediaItem,
null, $requestItem->getToken());
+ }
+
+ private function checkService() {
+ if (!$this->service) {
+ throw new SocialSpiException("Not Implemented.",
ResponseError::$NOT_IMPLEMENTED);
+ }
+ }
+}
Added: incubator/shindig/trunk/php/src/social/spi/AlbumService.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/spi/AlbumService.php?rev=788306&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/social/spi/AlbumService.php (added)
+++ incubator/shindig/trunk/php/src/social/spi/AlbumService.php Thu Jun 25
09:52:15 2009
@@ -0,0 +1,73 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * The interface to access albums.
+ */
+interface AlbumService {
+
+ /**
+ * Returns a list of Albums that correspond to the passed in User/GroupId
+ *
+ * @param userId ID of the user to indicate the requestor
+ * @param groupId Albums for all of the people in the specific group.
+ * @param albumIds album Ids to fetch. Fetch all albums if this is empty
+ * @param collectionOptions options for sorting, pagination etc
+ * @param fields fields to fetch
+ * @param token The gadget token
+ * @return a list of albums
+ */
+ public function getAlbums($userId, $groupId, $albumIds, $collectionOptions,
$fields, $token);
+
+ /**
+ * Creates an album for a user. An Album ID is created and provided back in
+ * the returned album.
+ *
+ * @param userId id of the user for whom an album is to be created
+ * @param groupId group id for this request
+ * @param album album with fields set for a create request. id field is
ignored.
+ * @param token security token to authorize this request
+ * @return the created album with album id set in it
+ */
+ public function createAlbum($userId, $groupId, $album, $token);
+
+ /**
+ * Updates an album for the fields set in album.
+ *
+ * @param userId id of user whose album is to be updated
+ * @param groupId group id for this request
+ * @param album album with id and fields to be updated.
+ * @param token security token to authorize this request
+ * @return updated album
+ */
+ public function updateAlbum($userId, $groupId, $album, $token);
+
+ /**
+ * Deletes an album.
+ *
+ * @param userId id of owner of album
+ * @param groupId group id of owner of album
+ * @param albumId id of album to be deleted
+ * @param token security token to authorize this request
+ * @return void on completion
+ */
+ public function deleteAlbum($userId, $groupId, $albumId, $token);
+
+}
\ No newline at end of file
Added: incubator/shindig/trunk/php/src/social/spi/MediaItemService.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/spi/MediaItemService.php?rev=788306&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/social/spi/MediaItemService.php (added)
+++ incubator/shindig/trunk/php/src/social/spi/MediaItemService.php Thu Jun 25
09:52:15 2009
@@ -0,0 +1,76 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Media Service exposes an interface to access the media items.
+ */
+interface MediaItemService {
+
+ /**
+ * Returns mediaItems from an album
+ *
+ * @param userId The id of the person whose album to fetch
+ * @param groupId The group Id
+ * @param albumId The id of the album to fetch
+ * @param mediaItemIds MediaItemIds to fetch. Fetch all mediaItems if this
is empty
+ * @param collectionOptions options for sorting, pagination etc
+ * @param fields fields to fetch
+ * @param token The gadget token
+ * @return a list of media items
+ */
+ public function getMediaItems($userId, $groupId, $albumId, $mediaItemIds,
$collectionOptions, $fields, $token);
+
+ /**
+ * Creates a media item in a specified album. The album-id is taken from the
+ * albumMediaItem object. id of the media item object should not be set.
+ *
+ * @param userId id of the user for whom a media item is to be created
+ * @param groupId group id
+ * @param mediaItem specifies album-id and media item fields
+ * @param data the image binary data to be uploaded
+ * @param token security token to authorize this request
+ * @return the created media item
+ */
+ public function createMediaItem($userId, $groupId, $mediaItem, $data,
$token);
+
+ /**
+ * Updates a media item in an album. Album id and media item id is taken in
+ * from albumMediaItem.
+ *
+ * @param userId id of user whose media item is to be updated
+ * @param groupId group id
+ * @param mediaItem specifies album id, media-item id, fields to update
+ * @param token security token
+ * @return updated album media item
+ */
+ public function updateMediaItem($userId, $groupId, $mediaItem, $data,
$token);
+
+ /**
+ * Deletes an album media item.
+ *
+ * @param id id of user whose media item is to be deleted
+ * @param groupId group id
+ * @param albumId id of album to update
+ * @param mediaItemIds ids of media item to update
+ * @param token security token to authorize this update request
+ * @return void on successful completion
+ */
+ public function deleteMediaItems($userId, $groupId, $albumId, $mediaItemIds,
$token);
+}