Author: chabotc
Date: Sat Jul 19 16:27:34 2008
New Revision: 678240
URL: http://svn.apache.org/viewvc?rev=678240&view=rev
Log:
Adds support for Messages through the RESTful interface
Added:
incubator/shindig/trunk/php/src/social-api/dataservice/MessagesHandler.php
incubator/shindig/trunk/php/src/social-api/dataservice/MessagesService.php
incubator/shindig/trunk/php/src/social-api/samplecontainer/BasicMessagesService.php
Modified:
incubator/shindig/trunk/php/src/social-api/converters/InputAtomConverter.php
incubator/shindig/trunk/php/src/social-api/converters/InputConverter.php
incubator/shindig/trunk/php/src/social-api/converters/InputJsonConverter.php
incubator/shindig/trunk/php/src/social-api/converters/OutputAtomConverter.php
incubator/shindig/trunk/php/src/social-api/http/RestServlet.php
Modified:
incubator/shindig/trunk/php/src/social-api/converters/InputAtomConverter.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social-api/converters/InputAtomConverter.php?rev=678240&r1=678239&r2=678240&view=diff
==============================================================================
---
incubator/shindig/trunk/php/src/social-api/converters/InputAtomConverter.php
(original)
+++
incubator/shindig/trunk/php/src/social-api/converters/InputAtomConverter.php
Sat Jul 19 16:27:34 2008
@@ -71,4 +71,26 @@
}
return $data;
}
+
+ public function convertMessages($requestParam)
+ {
+ $xml = simplexml_load_string($requestParam, 'SimpleXMLElement',
LIBXML_NOCDATA);
+ $message = array();
+ if (!isset($xml->title) || !isset($xml->content)) {
+ throw new Exception("Invalid message structure");
+ }
+ $message['id'] = isset($xml->id) ? trim($xml->id) : null;
+ $message['title'] = trim($xml->title);
+ $message['body'] = trim($xml->content);
+ // retrieve recipients by looking at the osapi name space
+ $xml = simplexml_load_string($requestParam, 'SimpleXMLElement',
LIBXML_NOCDATA, "http://opensocial.org/2008/opensocialapi");
+ if (!isset($xml->recipient)) {
+ throw new Exception("Invalid message structure");
+ }
+ $message['recipients'] = array();
+ foreach ($xml->recipient as $recipient) {
+ $message['recipients'][] = trim($recipient);
+ }
+ return $message;
+ }
}
Modified:
incubator/shindig/trunk/php/src/social-api/converters/InputConverter.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social-api/converters/InputConverter.php?rev=678240&r1=678239&r2=678240&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social-api/converters/InputConverter.php
(original)
+++ incubator/shindig/trunk/php/src/social-api/converters/InputConverter.php
Sat Jul 19 16:27:34 2008
@@ -28,4 +28,5 @@
abstract public function convertPeople($requestParam);
abstract public function convertActivities($requestParam);
abstract public function convertAppData($requestParam);
+ abstract public function convertMessages($requestParam);
}
\ No newline at end of file
Modified:
incubator/shindig/trunk/php/src/social-api/converters/InputJsonConverter.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social-api/converters/InputJsonConverter.php?rev=678240&r1=678239&r2=678240&view=diff
==============================================================================
---
incubator/shindig/trunk/php/src/social-api/converters/InputJsonConverter.php
(original)
+++
incubator/shindig/trunk/php/src/social-api/converters/InputJsonConverter.php
Sat Jul 19 16:27:34 2008
@@ -53,4 +53,13 @@
}
return $ret;
}
+
+ public function convertMessages($requestParam)
+ {
+ $ret = json_decode($requestParam, true);
+ if ($ret == $requestParam) {
+ throw new Exception("Mallformed json batch string");
+ }
+ return $ret;
+ }
}
Modified:
incubator/shindig/trunk/php/src/social-api/converters/OutputAtomConverter.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social-api/converters/OutputAtomConverter.php?rev=678240&r1=678239&r2=678240&view=diff
==============================================================================
---
incubator/shindig/trunk/php/src/social-api/converters/OutputAtomConverter.php
(original)
+++
incubator/shindig/trunk/php/src/social-api/converters/OutputAtomConverter.php
Sat Jul 19 16:27:34 2008
@@ -31,7 +31,7 @@
//FIXME osearch fields break the validator ... remove option once i
know if they should be included or not
private static $includeOsearch = false;
// this maps the REST url to the atom content type
- private static $entryTypes = array('people' => 'person', 'appdata' =>
'appdata', 'activities' => 'activity');
+ private static $entryTypes = array('people' => 'person', 'appdata' =>
'appdata', 'activities' => 'activity', 'messages' => 'messages');
private $doc;
function outputResponse(ResponseItem $responseItem, RestRequestItem
$requestItem)
Added:
incubator/shindig/trunk/php/src/social-api/dataservice/MessagesHandler.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social-api/dataservice/MessagesHandler.php?rev=678240&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/social-api/dataservice/MessagesHandler.php
(added)
+++ incubator/shindig/trunk/php/src/social-api/dataservice/MessagesHandler.php
Sat Jul 19 16:27:34 2008
@@ -0,0 +1,57 @@
+<?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 MessagesHandler extends DataRequestHandler {
+
+ private static $MESSAGES_PATH = "/messages/{userId}/outbox/{msgId}";
+ private $service;
+
+ public function __construct()
+ {
+ $service = Config::get('messages_service');
+ $this->service = new $service();
+ }
+
+ public function handleDelete(RestRequestItem $requestItem)
+ {
+ return new ResponseItem(NOT_IMPLEMENTED, "You can't delete
messages", null);
+ }
+
+ public function handleGet(RestRequestItem $requestItem)
+ {
+ return new ResponseItem(NOT_IMPLEMENTED, "You can't retrieve
messages", null);
+ }
+
+ public function handlePost(RestRequestItem $requestItem)
+ {
+ return new ResponseItem(NOT_IMPLEMENTED, "You can't edit
messages", null);
+ }
+
+ /**
+ * /messages/{groupId}/outbox/{msgId}
+ *
+ * @param RestRequestItem $requestItem
+ * @return responseItem
+ */
+ public function handlePut(RestRequestItem $requestItem)
+ {
+ $requestItem->parseUrlWithTemplate(self::$MESSAGES_PATH);
+ return $this->service->createMessage($requestItem->getUser(),
$requestItem->getPostData(), $requestItem->getToken());
+ }
+}
Added:
incubator/shindig/trunk/php/src/social-api/dataservice/MessagesService.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social-api/dataservice/MessagesService.php?rev=678240&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/social-api/dataservice/MessagesService.php
(added)
+++ incubator/shindig/trunk/php/src/social-api/dataservice/MessagesService.php
Sat Jul 19 16:27:34 2008
@@ -0,0 +1,33 @@
+<?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.
+ */
+
+abstract class MessagesService {
+
+ /** $message is an array containing the following fields:
+ * [id] => {msgid}
+ * [title] => You have an invitation from Joe
+ * [body] => Click <a
href="http://app.example.org/invites/{msgid}">here</a> to review your
invitation.
+ * [recipients] => Array
+ * (
+ * [0] => example.org:AD38B3886625AAF
+ * [1] => example.org:997638BAA6F25AD
+ * )
+ */
+ abstract public function createMessage($userId, $message, SecurityToken
$token);
+}
Modified: incubator/shindig/trunk/php/src/social-api/http/RestServlet.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social-api/http/RestServlet.php?rev=678240&r1=678239&r2=678240&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social-api/http/RestServlet.php (original)
+++ incubator/shindig/trunk/php/src/social-api/http/RestServlet.php Sat Jul 19
16:27:34 2008
@@ -280,6 +280,9 @@
case 'appdata':
$class = 'AppDataHandler';
break;
+ case 'messages':
+ $class = 'MessagesHandler';
+ break;
//TODO add 'groups' and 'messages' here
default:
$response = new ResponseItem(NOT_IMPLEMENTED,
"{$path} is not implemented");
@@ -316,6 +319,9 @@
case 'activities':
$ret =
$inputConverter->convertActivities($requestParam);
break;
+ case 'messages':
+ $ret =
$inputConverter->convertMessages($requestParam);
+ break;
case 'appdata':
$ret =
$inputConverter->convertAppData($requestParam);
break;
Added:
incubator/shindig/trunk/php/src/social-api/samplecontainer/BasicMessagesService.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social-api/samplecontainer/BasicMessagesService.php?rev=678240&view=auto
==============================================================================
---
incubator/shindig/trunk/php/src/social-api/samplecontainer/BasicMessagesService.php
(added)
+++
incubator/shindig/trunk/php/src/social-api/samplecontainer/BasicMessagesService.php
Sat Jul 19 16:27:34 2008
@@ -0,0 +1,26 @@
+<?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 BasicMessagesService extends MessagesService {
+
+ public function createMessage($userId, $message, SecurityToken $token)
+ {
+ return new ResponseItem(NOT_IMPLEMENTED, "Not implemented",
null);
+ }
+}