Permalink
Browse files

Merged pull request #1 from clayhinson/master.

unread message sync
  • Loading branch information...
2 parents 2a8a96a + 3106f5b commit e5bc971dfc5804163c6cf45d807658bc4ef9a402 @funkatron funkatron committed Apr 26, 2011
Showing with 172 additions and 1 deletion.
  1. +111 −0 custom/Action/Unreadsync.php
  2. +1 −0 custom/AllFiles.php
  3. +38 −1 custom/Config/actions.xml
  4. +22 −0 custom/Model/Spaz/UnreadSync.php
@@ -0,0 +1,111 @@
+<?php
+
+/**
+ * Action Unreadsync
+ *
+ * Sync unread message status
+ *
+ * @link http://getfrapi.com
+ * @author Frapi <frapi@getfrapi.com>
+ * @link /sync
+ */
+class Action_Unreadsync extends Frapi_Action implements Frapi_Action_Interface
+{
+
+ /**
+ * Required parameters
+ *
+ * @var An array of required parameters.
+ */
+ protected $requiredParams = array('timeline', 'replies', 'messages', 'key', 'service', 'userid', 'client');
+
+ /**
+ * The data container to use in toArray()
+ *
+ * @var A container of data to fill and return in toArray()
+ */
+ private $data = array();
+
+ /**
+ * To Array
+ *
+ * This method returns the value found in the database
+ * into an associative array.
+ *
+ * @return array
+ */
+ public function toArray()
+ {
+ return $this->data;
+ }
+
+ /**
+ * Default Call Method
+ *
+ * This method is called when no specific request handler has been found
+ *
+ * @return array
+ */
+ public function executeAction()
+ {
+ throw new Frapi_Error('NOT_IMPLEMENTED');
+ }
+
+ /**
+ * Get Request Handler
+ *
+ * This method is called when a request is a GET
+ *
+ * @return array
+ */
+ public function executeGet()
+ {
+ $this->requiredParams = array('service', 'userid');
+ $valid = $this->hasRequiredParameters($this->requiredParams);
+ if ($valid instanceof Frapi_Error) {
+ return $valid;
+ }
+
+ $service = $this->getParam('service', self::TYPE_STRING);
+ $userid = $this->getParam('userid', self::TYPE_STRING);
+
+ $sm = new SpazUnreadSync();
+ $sync = $sm->retrieve($service, $userid);
+
+ if(!$sync) {
+ throw new Frapi_Error('ERROR_RETRIEVING_SYNC');
+ }
+
+ return $sync;
+ }
+
+ /**
+ * Post Request Handler
+ *
+ *
+ *
+ * @return array
+ */
+ public function executePost()
+ {
+ $valid = $this->hasRequiredParameters($this->requiredParams);
+ if ($valid instanceof Frapi_Error) {
+ return $valid;
+ }
+ $syncParams = array();
+ foreach($this->requiredParams as $param) {
+ $syncParams[$param] = $this->getParam($param, self::TYPE_STRING);
+ }
+
+ $sm = new SpazUnreadSync();
+ $sync = $sm->sync($syncParams);
+
+ if (!$sync) {
+ throw new Frapi_Error('ERROR_SAVING_SYNC');
+ }
+
+ return $this->toArray();
+ }
+
+}
+
View
@@ -6,5 +6,6 @@
// Use the constant CUSTOM_MODEL to access the custom model directory
require CUSTOM_MODEL . '/Spaz/Url.php';
require CUSTOM_MODEL . '/Spaz/Avatar.php';
+require CUSTOM_MODEL . '/Spaz/UnreadSync.php';
require dirname(__FILE__) . DIRECTORY_SEPARATOR.'helpers.php';
View
@@ -67,7 +67,6 @@
<name>Avatar</name>
<enabled>1</enabled>
<public>1</public>
- <description></description>
<route>/avatar/:service/:userid</route>
<hash>6b3886e90fdc939f0d4525409995ece59b7fffe5</hash>
<parameters>
@@ -81,5 +80,43 @@
</parameter>
</parameters>
</action>
+ <action>
+ <name>Unreadsync</name>
+ <enabled>1</enabled>
+ <public>1</public>
+ <description>Sync unread message status</description>
+ <route>/sync</route>
+ <hash>d31eba41d3c31653ae1b26d18e8a10dd7d266253</hash>
+ <parameters>
+ <parameter>
+ <name>timeline</name>
+ <required>1</required>
+ </parameter>
+ <parameter>
+ <name>replies</name>
+ <required>1</required>
+ </parameter>
+ <parameter>
+ <name>key</name>
+ <required>1</required>
+ </parameter>
+ <parameter>
+ <name>service</name>
+ <required>1</required>
+ </parameter>
+ <parameter>
+ <name>userid</name>
+ <required>1</required>
+ </parameter>
+ <parameter>
+ <name>messages</name>
+ <required>1</required>
+ </parameter>
+ <parameter>
+ <name>client</name>
+ <required>1</required>
+ </parameter>
+ </parameters>
+ </action>
</actions>
</frapi-config>
@@ -0,0 +1,22 @@
+<?php
+
+class SpazUnreadSync
+{
+ function __construct()
+ {
+ $this->cache = Frapi_Cache::getInstance('apc');
+ }
+
+ public function sync($params)
+ {
+ $ck = "sync_".$params['service']."_".$params['userid'];
+ return $this->cache->add($ck, $params);
+ }
+
+ public function retrieve($service, $userid)
+ {
+ $ck = "sync_{$service}_{$userid}";
+ $sync = $this->cache->get($ck);
+ return $sync;
+ }
+}

0 comments on commit e5bc971

Please sign in to comment.