Quellcode durchsuchen

revert versions

yangck vor 6 Jahren
Ursprung
Commit
571d45bf2c
21 geänderte Dateien mit 367 neuen und 875 gelöschten Zeilen
  1. 1 0
      README.md
  2. 1 1
      const/result.js
  3. 35 2
      lib/apis.js
  4. 108 9
      lib/chatroom.js
  5. 48 0
      lib/group.js
  6. 2 1
      lib/index.js
  7. 35 24
      lib/message.js
  8. 30 14
      lib/rongrequest.js
  9. 36 17
      lib/user.js
  10. 28 1
      lib/util.js
  11. 30 0
      lib/wordfilter.js
  12. 13 4
      package.json
  13. BIN
      test/cn_lesson1_1.amr
  14. 0 21
      test/config.js
  15. BIN
      test/raindrop.jpg
  16. 0 87
      test/test.chatroom.js
  17. 0 107
      test/test.group.js
  18. 0 410
      test/test.message.js
  19. 0 177
      test/test.user.js
  20. BIN
      test/testvoice.amr
  21. BIN
      test/testvoice.mp3

+ 1 - 0
README.md

@@ -83,6 +83,7 @@ Since most of the time the user won't be using the components for testing(they a
 
 ```bash
 $ npm install
+$ npm installTestModules
 $ npm test
 ```
 

+ 1 - 1
const/result.js

@@ -12,4 +12,4 @@ define( 'INVALID_CHATROOMID_MSG', 'Invalid chat room id! Space, tab and new line
 
 
 define( 'INVALID_GROUPID', 2000 );
-define( 'INVALID_GROUPID_MSG', 'Invalid group id! Space, tab and new line are not allowed in group id!' );
+define( 'INVALID_GROUPID_MSG', 'Invalid group id! Space, tab and new line are not allowed in group id!' );

+ 35 - 2
lib/apis.js

@@ -42,14 +42,47 @@ define( 'group', {
   'create'  : '/group/create',
   'quit'    : '/group/quit',
   'dismiss' : '/group/dismiss',
-  'refresh' : '/group/refresh'
+  'refresh' : '/group/refresh',
+  'user' : {
+    'query' : '/group/user/query',
+    'gag' : {
+      'add' : '/group/user/gag/add',
+      'rollback' : '/group/user/gag/rollback',
+      'list' : '/group/user/gag/list'
+    }
+  }
 } );
 
 define( 'chatroom', {
   'create'  : '/chatroom/create',
   'destroy' : '/chatroom/destroy',
   'query'   : '/chatroom/query',
+  'join'    : '/chatroom/join',
   'user'    : {
-    'query' : '/chatroom/user/query'
+    'query' : '/chatroom/user/query',
+    'gagAdd' : '/chatroom/user/gag/add',
+    'gagRollback' : '/chatroom/user/gag/rollback',
+    'gagList' : '/chatroom/user/gag/list',
+    'blockAdd' : '/chatroom/user/block/add',
+    'blockRollback' : '/chatroom/user/block/rollback',
+    'blockList' : '/chatroom/user/block/list'
+  },
+  'message' : {
+    'stop' : '/chatroom/message/stopDistribution',
+    'resume' : '/chatroom/message/resumeDistribution'
   }
+
+} );
+
+define( 'wordfilter', {
+  'add'    : '/wordfilter/add',
+  'delete' : '/wordfilter/delete',
+  'list'   : '/wordfilter/list'
+} );
+
+define( 'sms', {
+  'send'       : '/send',
+  'sendCode'   : '/sendCode',
+  'verifyCode' : '/verifyCode',
+  'getImgCode' : '/getImgCode'
 } );

+ 108 - 9
lib/chatroom.js

@@ -5,25 +5,34 @@ var rcResult 	= require( '../const' ).result;
 
 exports.create = function( chatRoomIDNamePairs, format, callback ) {
 	var params = {};
-	var chatRoomId;
+	var chatroomId;
 	var validChatRoomId = true;
 	for( var i=0; i<chatRoomIDNamePairs.length; ++i ) {
-		chatRoomId = chatRoomIDNamePairs[i].id;
-		if( !util.validateId( chatRoomId ) ) {
+		chatroomId = chatRoomIDNamePairs[i].id;
+		if( !util.validateId( chatroomId ) ) {
 			validChatRoomId = false;
 			break;
 		}
-		var key = 'chatroom[' + chatRoomId + ']';
+		var key = 'chatroom[' + chatroomId + ']';
 		params[ key ] = chatRoomIDNamePairs[i].name;
 	}
 	if( validChatRoomId ) {
-		rongrequest.request( apis['chatroom']['create'], params, format, callback );	
+		rongrequest.request( apis['chatroom']['create'], params, format, callback );
 	}
 	else {
 		return callback( { code : rcResult.INVALID_CHATROOMID, message : rcResult.INVALID_CHATROOMID_MSG }, null );
 	}
 }
 
+exports.join = function(chatroomId,userId,format,callback){
+	util.check(['string','string','string','function'],[chatroomId,userId,format,callback],'chatroom.join');
+	rongrequest.request(apis['chatroom']['join'],
+	{
+		chatroomId : chatroomId,
+		userId : userId
+	},format,callback);
+}
+
 exports.destroy = function( chatRoomIDs, format, callback ) {
 	if( 'object' == typeof chatRoomIDs && chatRoomIDs.length ) {
 		if( !util.validateIDs( chatRoomIDs ) ) {
@@ -56,21 +65,111 @@ exports.query = function( chatRoomIDs, format, callback ) {
 		}
 		rongrequest.request( apis['chatroom']['query'], { chatroomId : chatRoomIDs }, format, callback );
 	}
-	
+
 }
 
 exports.user = {};
-exports.user.query = function( chatRoomId, format, callback ) {
-  if( !util.validateId( chatRoomId ) ) {
+exports.message = {};
+
+exports.user.query = function( chatroomId, count, order, format, callback ) {
+  if( !util.validateId( chatroomId ) ) {
 	  return callback( { code : rcResult.INVALID_CHATROOMID, message : rcResult.INVALID_CHATROOMID_MSG }, null );
   }
   rongrequest.request( apis['chatroom']['user']['query'], {
-    chatroomId : chatRoomId
+    chatroomId : chatroomId,
+		count:count,
+		order:order
   }, format, function( err, resultText ) {
     return callback( err, resultText );
   } );
 }
 
+exports.user.gagAdd = function(chatroomId,userId,minute,format,callback){
+	util.check(['string','string','number','string','function'],[chatroomId,userId,minute,format,callback],'chatroom.user.gag.add');
+	rongrequest.request(apis['chatroom']['user']['gagAdd'],
+			{
+				chatroomId : chatroomId,
+				userId:userId,
+				minute:minute
+			},format,callback);
+}
+
+exports.user.gagRollback = function(chatroomId,userId,format,callback){
+	util.check(['string','string','string','function'],[chatroomId,userId,format,callback],'chatroom.user.gag.rollback');
+	rongrequest.request(apis['chatroom']['user']['gagRollback'],
+			{
+				chatroomId : chatroomId,
+				userId:userId
+			},format,function(err,resultText){
+					return callback(err,resultText);
+			});
+}
+
+exports.user.gagList = function(chatroomId,format,callback){
+	util.check(['string','string','function'],[chatroomId,format,callback],'chatroom.user.gag.list');
+	rongrequest.request(apis['chatroom']['user']['gagList'],
+			{
+				chatroomId : chatroomId
+			},format,function(err,resultText){
+					return callback(err,resultText);
+			});
+}
+
+exports.user.blockAdd = function(chatroomId,userId,minute,format,callback){
+	util.check(['string','string','number','string','function'],[chatroomId,userId,minute,format,callback],'chatroom.user.block.add');
+	rongrequest.request(apis['chatroom']['user']['blockAdd'],
+			{
+				chatroomId : chatroomId,
+				userId:userId,
+				minute:minute
+			},format,function(err,resultText){
+					return callback(err,resultText);
+			});
+}
+
+exports.user.blockRollback = function(chatroomId,userId,format,callback){
+	util.check(['string','string','string','function'],[chatroomId,userId,format,callback],'chatroom.user.block.rollback');
+	rongrequest.request(apis['chatroom']['user']['blockRollback'],
+			{
+				chatroomId : chatroomId,
+				userId:userId
+			},format,function(err,resultText){
+					return callback(err,resultText);
+			});
+}
+
+exports.user.blockList = function(chatroomId,format,callback){
+	util.check(['string','string','function'],[chatroomId,format,callback],'chatroom.user.block.list');
+	rongrequest.request(apis['chatroom']['user']['blockList'],
+			{
+				chatroomId : chatroomId
+			},format,function(err,resultText){
+					return callback(err,resultText);
+			});
+}
+
+exports.message.stopDistribution = function(chatroomId,format,callback){
+		util.check(['string','string','function'],[chatroomId,format,callback],'chatroom.message.stopDistribution');
+		rongrequest.request(apis['chatroom']['message']['stop'],
+			{
+				chatroomId : chatroomId
+			},
+			format,function(err,resultText){
+					return callback(err,resultText);
+			});
+}
+
+exports.message.resumeDistribution = function(chatroomId,format,callback){
+		util.check(['string','string','function'],[chatroomId,format,callback],'chatroom.message.resumeDistribution');
+		rongrequest.request(apis['chatroom']['message']['resume'],
+			{
+				chatroomId : chatroomId
+			},
+			format,function(err,resultText){
+					return callback(err,resultText);
+			});
+}
+
 exports.queryAll = function( format, callback ) {
 	rongrequest.requestWithSameFields( apis['chatroom']['query'], {}, [], format, callback );
 }

+ 48 - 0
lib/group.js

@@ -91,3 +91,51 @@ function createGroup( userIDs, groupId, groupName, format, callback ) {
 
 exports.create = createGroup;
 exports.join   = createGroup;
+
+
+exports.user = {};
+exports.user.query = function( groupId, format, callback ) {
+	if( !util.validateId( groupId ) ) {
+		return callback( { code : rcResult.INVALID_GROUPID, message : rcResult.INVALID_GROUPID_MSG }, null );
+	}
+
+	var params = { groupId : groupId };
+	rongrequest.request( apis['group']['user']['query'], params, format, function( err, result ) {
+		return callback( err, result );
+	} );
+}
+
+
+exports.user.gag = {};
+exports.user.gag.add = function( userId, groupId, minute, format, callback ) {
+	if( !util.validateId( groupId ) ) {
+		return callback( { code : rcResult.INVALID_GROUPID, message : rcResult.INVALID_GROUPID_MSG }, null );
+	}
+
+	var params = { userId : userId, groupId : groupId, minute : minute };
+	rongrequest.request( apis['group']['user']['gag']['add'], params, format, function( err, result ) {
+		return callback( err, result );
+	} );
+}
+
+exports.user.gag.rollback = function( userId, groupId, format, callback ) {
+	if( !util.validateId( groupId ) ) {
+		return callback( { code : rcResult.INVALID_GROUPID, message : rcResult.INVALID_GROUPID_MSG }, null );
+	}
+
+	var params = { userId : userId, groupId : groupId };
+	rongrequest.request( apis['group']['user']['gag']['rollback'], params, format, function( err, result ) {
+		return callback( err, result );
+	} );
+}
+
+exports.user.gag.list = function( groupId, format, callback ) {
+	if( !util.validateId( groupId ) ) {
+		return callback( { code : rcResult.INVALID_GROUPID, message : rcResult.INVALID_GROUPID_MSG }, null );
+	}
+
+	var params = { groupId : groupId };
+	rongrequest.request( apis['group']['user']['gag']['list'], params, format, function( err, result ) {
+		return callback( err, result );
+	} );
+}

+ 2 - 1
lib/index.js

@@ -4,7 +4,8 @@ exports.user 	 = require( './user' );
 exports.message  = require( './message' );
 exports.group 	 = require( './group' );
 exports.chatroom = require( './chatroom' );
-exports.sms = require( './sms' );
+exports.wordfilter = require( './wordfilter' );
+exports.sms 	 = require( './sms' );
 
 
 exports.init 			  = rongrequest.init;

+ 35 - 24
lib/message.js

@@ -5,10 +5,10 @@ exports.private = {};
 
 exports.private.publish = exports.publish = function( fromUserId, toUserId, objectName, content, pushContent, pushData, format, callback ) {
   var requestParams = {
-		fromUserId : fromUserId,
-		toUserId   : toUserId,
-		objectName : objectName,
-		content    : content
+    fromUserId : fromUserId,
+    toUserId   : toUserId,
+    objectName : objectName,
+    content    : typeof content === 'object' ? JSON.stringify(content) : content
   }
 
   var f = arguments[ arguments.length - 2 ];
@@ -25,16 +25,16 @@ exports.private.publish = exports.publish = function( fromUserId, toUserId, obje
     }
   }
 
-	rongrequest.request( apis['message']['publish'], requestParams, formatSpecified ? f : 'json', function( err, resultText ) {
-		return callback( err, resultText );
-	} );
+  rongrequest.request( apis['message']['private']['publish'], requestParams, formatSpecified ? f : 'json', function( err, resultText ) {
+    return callback( err, resultText );
+  } );
 }
 
 exports.private.publish_template = function( fromUserId, toUserIDs, objectName, content, values, pushContent, pushData, format, callback ) {
   var requestParams = {
     fromUserId  : fromUserId,
     objectName  : objectName,
-    content     : content,
+    content     : typeof content === 'object' ? JSON.stringify(content) : content,
     toUserId    : toUserIDs,
     values      : values,
     pushContent : pushContent,
@@ -52,7 +52,7 @@ exports.system.publish = function( fromUserId, toUserIDs, objectName, content, p
   var requestParams = {
     fromUserId  : fromUserId,
     objectName  : objectName,
-    content     : content
+    content     : typeof content === 'object' ? JSON.stringify(content) : content
   }
 
   var f = arguments[ arguments.length - 2 ];
@@ -74,13 +74,19 @@ exports.system.publish = function( fromUserId, toUserIDs, objectName, content, p
   } );
 }
 
+
+//exports.system.publish_template = function( fromUserId, toUserIDs, objectName, values, content, pushContent, pushData, format, callback ) {
+//
+//}
+
 exports.group = {};
+
 exports.group.publish = function( fromUserId, toGroupId, objectName, content, pushContent, pushData, format, callback ) {
   var requestParams = {
     fromUserId  : fromUserId,
     toGroupId   : toGroupId,
     objectName  : objectName,
-    content     : content
+    content     : typeof content === 'object' ? JSON.stringify(content) : content
   }
 
   var f = arguments[ arguments.length - 2 ];
@@ -103,12 +109,13 @@ exports.group.publish = function( fromUserId, toGroupId, objectName, content, pu
 }
 
 exports.chatroom = {};
+
 exports.chatroom.publish = function( fromUserId, toChatroomId, objectName, content, pushContent, pushData, format, callback ) {
   var requestParams = {
     fromUserId   : fromUserId,
     toChatroomId : toChatroomId,
     objectName   : objectName,
-    content      : content
+    content      : typeof content === 'object' ? JSON.stringify(content) : content
   }
 
   var f = arguments[ arguments.length - 2 ];
@@ -130,15 +137,20 @@ exports.chatroom.publish = function( fromUserId, toChatroomId, objectName, conte
   } );
 }
 
+//exports.discussion = {};
+//exports.discussion.publish = function( fromUserId, toDiscussionId, objectName, content, pushContent, pushData, format, callback ) {
+//
+//}
+
 /**
- * 
+ *
  */
 exports.broadcast = function( fromUserId, objectName, content, pushContent, pushData, format, callback ) {
   var requestParams = {
-		fromUserId  : fromUserId,
-		objectName  : objectName,
-		content     : content
-	}
+    fromUserId  : fromUserId,
+    objectName  : objectName,
+    content     : typeof content === 'object' ? JSON.stringify(content) : content
+  }
 
   var f = arguments[ arguments.length - 2 ];
   var formatSpecified = f === 'json' || f === 'xml';
@@ -154,16 +166,15 @@ exports.broadcast = function( fromUserId, objectName, content, pushContent, push
     }
   }
 
-	rongrequest.request( apis['message']['broadcast'], requestParams, formatSpecified ? f : 'json', function( err, resultText ) {
-		return callback( err, resultText );
-	} );
+  rongrequest.request( apis['message']['broadcast'], requestParams, formatSpecified ? f : 'json', function( err, resultText ) {
+    return callback( err, resultText );
+  } );
 }
 
 exports.history = function( dateString, format, callback ) {
-	rongrequest.request( apis['message']['history'], {
+  rongrequest.request( apis['message']['history'], {
     date : dateString
-	}, format, function( err, resultText ) {
-		return callback( err, resultText );
-	} );
+  }, format, function( err, resultText ) {
+    return callback( err, resultText );
+  } );
 }
-

+ 30 - 14
lib/rongrequest.js

@@ -1,9 +1,8 @@
-
 var superagent = require( 'superagent' );
-// require('superagent-proxy')(superagent);
-var sha1	   = require( 'sha1' );
+var sha1 = require('./util').sha1;
 
-var BASEURL	  = 'https://api.cn.rong.io';
+var BASEURL	  = 'http://api.cn.ronghub.com';
+var BASEURL_SMS	  = 'http://api.sms.ronghub.com';
 var APPKEY 	  = undefined;
 var APPSECRET = undefined;
 var TIMESTAMP = undefined;
@@ -12,25 +11,29 @@ var NONCE 	  = undefined;
 var HEADERS	  = {};
 
 var FORMAT 	  = 'json';
-// var proxy = process.env.http_proxy
 
 exports.init = function( appKey, appSecret ) {
 	APPKEY 	  = appKey;
 	APPSECRET = appSecret;
 	NONCE	    = parseInt( Math.random() * 0xffffff );
 	TIMESTAMP = Date.parse( new Date() )/1000;
-	SIGNATURE = sha1( APPSECRET + NONCE + TIMESTAMP  );
+    SIGNATURE = sha1( APPSECRET + NONCE + TIMESTAMP  );
 
 	HEADERS['App-Key'] 	 	= APPKEY;
 	HEADERS['Nonce'] 		= NONCE;
 	HEADERS['Timestamp']	= TIMESTAMP;
 	HEADERS['Signature']	= SIGNATURE;
+}
 
-	HEADERS['Content-Type'] = 'application/x-www-form-urlencoded';	
+exports.request = function( api, params, format, callback ) {
+	return requestWithDomain( BASEURL, api, params, format, callback );
 }
 
+exports.requestSMS = function( api, params, format, callback ) {
+	return requestWithDomain( BASEURL_SMS, api, params, format, callback );
+}
 
-exports.request = function( api, params, format, callback ) {
+requestWithDomain = function( base_url, api, params, format, callback ) {
 	var f = 'json';
 	if( (typeof format ) == 'function' ) { // Use default format 'json'
 		callback = format;
@@ -41,12 +44,13 @@ exports.request = function( api, params, format, callback ) {
 
 
 	superagent.agent()
-	.post( BASEURL + api + '.' + f )
+	.post( base_url + api + '.' + f )
 	.set( HEADERS )
+	.type( 'form' )
 	.send( params )
 	.end( function( err, result ) {
 		if( err ) {
-			return callback( err, null );
+			return callback( err, result ? result.text : null );
 		}
 		else {
 			return callback( null, result.text );
@@ -54,7 +58,6 @@ exports.request = function( api, params, format, callback ) {
 	} );
 }
 
-
 exports.requestWithSameFields = function( api, params, fieldAndValues, format, callback ) {
 	var f = 'json';
 	if( (typeof format ) == 'function' ) { // Use default format 'json'
@@ -66,7 +69,6 @@ exports.requestWithSameFields = function( api, params, fieldAndValues, format, c
 
 	var agent = superagent.agent()
 	.post( BASEURL + api + '.' + f )
-  	// .proxy(proxy)
 	.set( HEADERS );
 
 	for( var i=0; i<fieldAndValues.length; ++i ) {
@@ -83,7 +85,7 @@ exports.requestWithSameFields = function( api, params, fieldAndValues, format, c
 
   agent.end( function( err, result ) {
 		if( err ) {
-			return callback( err, null );
+			return callback( err, result ? result.text : null );
 		}
 		else {
 			return callback( null, result.text );
@@ -117,7 +119,21 @@ exports.requestWithHeaders = function( api, params, format, headers, callback )
 	.send( params )
 	.end( function( err, result ) {
 		if( err ) {
-			return callback( err, null );
+			return callback( err, result ? result.text : null );
+		}
+		else {
+			return callback( null, result.text );
+		}
+	} );
+}
+
+exports.get = function( api, params, callback ) {
+	superagent.agent()
+	.get( BASEURL_SMS + api + '.json' )
+	.query( params )
+	.end( function( err, result ) {
+		if( err ) {
+			return callback( err, result ? result.text : null );
 		}
 		else {
 			return callback( null, result.text );

+ 36 - 17
lib/user.js

@@ -12,11 +12,30 @@ exports.getToken = function( userId, name, portraitUri, format, callback ) {
 }
 
 exports.refresh = function( userId, name, portraitUri, format, callback ) {
-	rongrequest.request( apis['user']['refresh'], {
-		userId 		: userId,
-		name   		: name,
-		portraitUri : portraitUri
-	}, format, function( err, result ) {
+	var params
+
+	if(name && portraitUri)
+		params = {
+			userId: userId,
+			name: name,
+			portraitUri: portraitUri
+		}
+	else if(name && !portraitUri)
+		params = {
+			userId: userId,
+			name: name
+		}
+	else if(!name && portraitUri)
+		params = {
+			userId: userId,
+			portraitUri: portraitUri
+		}
+	else
+		params = {
+			userId: userId
+		}
+
+	rongrequest.request( apis['user']['refresh'], params, format, function( err, result ) {
 		return callback( err, result );
 	} );
 }
@@ -32,19 +51,19 @@ exports.checkOnline = function( userId, format, callback ) {
 
 
 exports.block = function( userId, numMinutes, format, callback ) {
-  numMinutes = parseInt( numMinutes );
+	numMinutes = parseInt( numMinutes );
 
-  if( numMinutes <= 0 ) { // Don't need to call the API.
-    return callback( null, '{"code":200}' );
-  }
+	if( numMinutes <= 0 ) { // Don't need to call the API.
+		return callback( null, '{"code":200}' );
+	}
 
-  if( numMinutes > 43200 ) {
-    numMinutes = 43200;
-  }
+	if( numMinutes > 43200 ) {
+		numMinutes = 43200;
+	}
 
 	rongrequest.request( apis['user']['block'], {
 		userId 		: userId,
-    minute    : numMinutes
+		minute    : numMinutes
 	}, format, function( err, result ) {
 		return callback( err, result );
 	} );
@@ -71,7 +90,7 @@ exports.blacklist = {};
 exports.blacklist.add = function( userId, blackUserId, format, callback ) {
 	rongrequest.request( apis['user']['addToBlackList'], {
 		userId 		  : userId,
-    blackUserId : blackUserId
+		blackUserId : blackUserId
 	}, format, function( err, result ) {
 		return callback( err, result );
 	} );
@@ -80,7 +99,7 @@ exports.blacklist.add = function( userId, blackUserId, format, callback ) {
 exports.blacklist.remove = function( userId, blackUserId, format, callback ) {
 	rongrequest.request( apis['user']['removeFromBlacklist'], {
 		userId 		  : userId,
-    blackUserId : blackUserId
+		blackUserId : blackUserId
 	}, format, function( err, result ) {
 		return callback( err, result );
 	} );
@@ -88,8 +107,8 @@ exports.blacklist.remove = function( userId, blackUserId, format, callback ) {
 
 exports.blacklist.query = function( userId, format, callback ) {
 	rongrequest.request( apis['user']['queryBlacklist'], {
-    userId : userId
-  }, format, function( err, result ) {
+		userId : userId
+	}, format, function( err, result ) {
 		return callback( err, result );
 	} );
 }

+ 28 - 1
lib/util.js

@@ -1,9 +1,31 @@
+var crypto = require('crypto');
+var formatFactory = {json:'json',xml:'xml'};
 
+Number.isInteger = Number.isInteger || function(value) {
+    return typeof value === "number" &&
+        isFinite(value) &&
+        Math.floor(value) === value;
+};
 
 function validateId( id ) {
+	if( Number.isInteger( id ) )
+		id = id.toString()
 	return ( id.indexOf( ' ' ) == -1 && id.indexOf( '\t' ) == -1 && id.indexOf( '\n' ) == -1 && id.indexOf( '\r' ) == -1 && id.indexOf( '\r\n' ) == -1  );
 }
 
+
+exports.validateFormat = function(format){
+  return format in formatFactory;
+}
+
+exports.check = function(opts,vals,position){
+    for (var i = 0,len = opts.length; i < len; i++) {
+        if (opts[i] != typeof vals[i]) {
+            throw new Error("The index of " + i + " parameter was wrong type " + opts[i] +" [" + typeof vals[i] + "],position -> " + position);
+        }
+    }
+}
+
 exports.validateIDs = function( IDs ) {
 	var valid = true;
 	for( var i=0; i<IDs.length; ++i ) {
@@ -15,4 +37,9 @@ exports.validateIDs = function( IDs ) {
 	return valid;
 }
 
-exports.validateId = validateId;
+exports.validateId = validateId;
+exports.sha1 = function(input){
+    var shasum = crypto.createHash('sha1');
+    shasum.update(input);
+	return shasum.digest('hex');
+}

+ 30 - 0
lib/wordfilter.js

@@ -0,0 +1,30 @@
+var apis 		= require( './apis' );
+var rongrequest = require( './rongrequest' );
+
+exports.add = function( word, format, callback ) {
+    if( word === '' || word === null || word === undefined ) {
+        return callback( 'Empty word' );
+    }
+
+    var params = { word : word };
+    rongrequest.request( apis['wordfilter']['add'], params, format, function( err, result ) {
+        return callback( err, result );
+    } );
+}
+
+exports.delete = function( word, format, callback ) {
+    if( word === '' || word === null || word === undefined ) {
+        return callback( 'Empty word' );
+    }
+
+    var params = { word : word };
+    rongrequest.request( apis['wordfilter']['delete'], params, format, function( err, result ) {
+        return callback( err, result );
+    } );
+}
+
+exports.list = function( format, callback ) {
+    rongrequest.request( apis['wordfilter']['list'], {}, format, function( err, result ) {
+        return callback( err, result );
+    } );
+}

+ 13 - 4
package.json

@@ -4,7 +4,8 @@
   "description": "The Server SDK of RongCloud",
   "main": "index.js",
   "scripts": {
-    "test": "cnpm install async@1.2.1 mocha@2.2.5 should@6.0.3 underscore@1.8.3 xml2js@0.4.9 && cd test && mocha ."
+    "installTestModules": "npm install async@1.2.1 mocha@2.2.5 should@6.0.3 underscore@1.8.3 xml2js@0.4.9",
+    "test": "cd test && mocha ."
   },
   "repository": {
     "type": "git",
@@ -17,7 +18,7 @@
     "sdk"
   ],
   "dependencies": {
-    "sha1": ">=1.1.0",
+    "bluebird": "^3.3.1",
     "superagent": ">=0.21.0"
   },
   "author": "RongCloud",
@@ -31,5 +32,13 @@
   "bugs": {
     "url": "https://github.com/rongcloud/server-sdk-nodejs/issues"
   },
-  "homepage": "http://rongcloud.cn"
-}
+  "homepage": "http://rongcloud.cn",
+  "devDependencies": {
+    "async": "^1.5.2",
+    "should": "^8.0.2",
+    "underscore": "^1.8.3",
+    "xml2js": "^0.4.15"
+  },
+  "_from": "rongcloud-sdk@git+https://github.com/rongcloud/server-sdk-nodejs.git",
+  "_resolved": "https://github.com/rongcloud/server-sdk-nodejs.git#master"
+}

BIN
test/cn_lesson1_1.amr


+ 0 - 21
test/config.js

@@ -1,21 +0,0 @@
-module.exports = {
-	appKey 		: 'mgb7ka1nbs3wg',
-	appSecret 	: 'm1Rv2MHHND',
-	token : {
-		userId 		: '0001',
-		name   		: 'TestUser',
-		portraitUri : 'http://rongcloud.cn/images/logo.png'
-	},
-	message : {
-		fromUserId  : '546eb521c613156d331e91bb',
-		toUserId	: '5460603c1002a6e311f89e7f',
-		textMsg		: 'Hello, world!'
-	},
-	group : {
-		userId : '5460603c1002a6e311f89e7f',
-		groupIdNamePairs : { 'ProgrammerGroup1' : '程序猿交流群1', 'DriverGroup1' : '赛车手爱好者2群' }
-	},
-	chatroom : {
-		chatroomIdNamePairs : { 'EatingFans' : '吃货大本营', 'ProCylcing' : '骑行专家', 'DriodGeek' : '手机极客', 'HackerHome' : '黑客之家' }
-	}
-}

BIN
test/raindrop.jpg


+ 0 - 87
test/test.chatroom.js

@@ -1,87 +0,0 @@
-var should 		= require( 'should' );
-var _ 			= require( 'underscore' );
-
-var testConfig  = require( './config' );
-var rongSDK 	= require( '../index' );
-
-var chatroomIDs   = _.keys( testConfig.chatroom.chatroomIdNamePairs );
-var chatroomNames = _.values( testConfig.chatroom.chatroomIdNamePairs );
-
-describe( 'Chatroom Test', function() {
-	before( function( done ) {
-		// Init the SDK before testing.
-		rongSDK.init( testConfig.appKey, testConfig.appSecret );
-		done();
-	} );
-
-	after( function( done ) {
-		done();
-	} );
-
-	describe( 'Create Chatroom', function() {
-		it( 'Create chatroom: should return OK', function( done ) {
-			var chatroomIdNamePairsArray = [];
-			_.each( chatroomIDs, function( chatroomId ) {
-				chatroomIdNamePairsArray.push( { id : chatroomId, name : testConfig.chatroom.chatroomIdNamePairs[ chatroomId ] } );
-			} );
-			rongSDK.chatroom.create( chatroomIdNamePairsArray , function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-				done();				
-			} );
-		} );
-	} );
-
-	describe( 'Destroy Chatroom', function() {
-		it( 'Destroy a single chatroom: should return OK', function( done ) {
-			rongSDK.chatroom.destroy( chatroomIDs.pop(), function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-				done();
-			} );
-		} );
-
-		it( 'Destroy chatrooms: should return OK', function( done ) {
-			rongSDK.chatroom.destroy( chatroomIDs.splice( 0, 2 ), function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-				done();
-			} );
-		} );
-
-	} );
-
-
-	describe( 'Query Chatroom', function() {
-		it( 'Query a single chatroom: should return OK', function( done ) {
-			rongSDK.chatroom.query( chatroomIDs[0], function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-				var found = _.findWhere( result.chatRooms, { chrmId : chatroomIDs[0] } );
-				found.should.not.be.undefined;
-				found.should.have.property( 'chrmId', chatroomIDs[0] );				
-				done();
-			} );
-		} );
-
-	} );
-
-	describe( 'Query Chatroom Users', function() {
-		it( 'Query the users of a chatroom: should return OK', function( done ) {
-			rongSDK.chatroom.user.query( chatroomIDs[0], function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-				done();
-			} );
-		} );
-
-	} );
-
-
-
-} );

+ 0 - 107
test/test.group.js

@@ -1,107 +0,0 @@
-var should 		= require( 'should' );
-var _ 			= require( 'underscore' );
-
-var testConfig  = require( './config' );
-var rongSDK 	= require( '../index' );
-
-var groupIDs 	= _.keys( testConfig.group.groupIdNamePairs );
-var groupNames 	= _.values( testConfig.group.groupIdNamePairs );
-
-describe( 'Group Test', function() {
-	before( function( done ) {
-		// Init the SDK before testing.
-		rongSDK.init( testConfig.appKey, testConfig.appSecret );
-		done();
-	} );
-
-	after( function( done ) {
-		done();
-	} );
-
-	describe( 'Sync Group', function() {
-		it( 'Synchornize group: should return OK', function( done ) {
-			rongSDK.group.sync( testConfig.group.userId, testConfig.group.groupIdNamePairs, function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-				done();
-			} );
-		} );
-	} );
-
-	describe( 'Quit Group', function() {
-		it( 'Quit group: should return OK', function( done ) {
-			rongSDK.group.quit( testConfig.group.userId, groupIDs[0], function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-				done();
-			} );
-		} );
-	} );
-
-	describe( 'Create/Join Group', function() {
-		it( 'Create/Join group with a single user: should return OK', function( done ) {
-			rongSDK.group.create( testConfig.group.userId, 'MyGroupID', 'MyGroupName' , function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-				done();
-			} );
-		} );
-
-		it( 'Create/Join group with multiple users: should return OK', function( done ) {
-			rongSDK.group.join( [ testConfig.message.fromUserId, testConfig.message.toUserId ], 'MyGroupID', 'MyGroupName' , function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-				done();
-			} );
-		} );
-	} );
-
-	describe( 'Dissmiss Group', function() {
-		it( 'Dismiss group(' + groupNames[0] + '): should return OK', function( done ) {
-			rongSDK.group.dismiss( testConfig.group.userId, groupIDs[0], function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-				done();
-			} );
-		} );
-
-		it( 'Dismiss group(' + groupNames[1] + '): should return OK', function( done ) {
-			rongSDK.group.dismiss( testConfig.group.userId, groupIDs[1], function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-				done();
-			} );
-		} );
-
-		it( 'Dismiss group(MyGroupName): should return OK', function( done ) {
-			rongSDK.group.dismiss( testConfig.group.userId, 'MyGroupID', function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-				done();
-			} );
-		} );
-
-	} );
-
-
-	describe( 'Refresh Group', function() {
-    var newGroupName = groupNames[0];
-		it( 'Refresh group(' + groupNames[0] + ') to be ' + newGroupName + ': should return OK', function( done ) {
-			rongSDK.group.refresh( groupIDs[0], newGroupName, function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-				done();
-			} );
-		} );
-  });
-
-
-} );

+ 0 - 410
test/test.message.js

@@ -1,410 +0,0 @@
-var async       = require( 'async' );
-var parseString = require( 'xml2js' ).parseString;
-var fs 			    = require( 'fs' );
-var should 		  = require( 'should' );
-
-var testConfig  = require( './config' );
-var rongSDK 	  = require( '../index' );
-
-var base64Voice	= new Buffer( fs.readFileSync( './testvoice.amr' ) ).toString( 'base64' );
-var base64Image	= new Buffer( fs.readFileSync( './raindrop.jpg' ) ).toString( 'base64' );
-
-var optionalArgs = [ 'push content', 'push data' ];
-
-describe( 'Message Test', function() {
-	before( function( done ) {
-		// Init the SDK before testing.
-		rongSDK.init( testConfig.appKey, testConfig.appSecret );
-		done();
-	} );
-
-	after( function( done ) {
-		done();
-	} );
-
-	describe( 'Publish Message', function() {
-		it( 'Text message: should return OK', function( done ) {
-			var textMessageObject = { content : testConfig.message.textMsg };
-      // Testing for all the situations of arguments.
-      var args = [ testConfig.message.fromUserId, testConfig.message.toUserId, 'RC:TxtMsg', JSON.stringify( textMessageObject ) ];
-
-      var argsArray = [];
-      for( var i=0; i<3; ++i ) {
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ) ) );
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ), 'json' ) );
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ), 'xml' ) );
-      }
-
-      async.each( argsArray, function( _args, cb ) {
-        rongSDK.message.publish.apply( this, _args.concat( function( err, resultText ) {
-          if( _args[ _args.length - 1 ] === 'xml' ) {
-            should.not.exists( err );
-            parseString( resultText, function( err, result ) {
-              parseInt( result.xml.code[0] ).should.equal( 200 );
-              cb();
-            } );
-          }
-          else {
-            should.not.exists( err );
-            var result = JSON.parse( resultText );
-            result.code.should.equal( 200 );
-            cb();
-          }
-        } ) );
-      }, function() {
-        done();
-      } );
-
-		} );
-
-		it( 'Image message: should return OK', function( done ) {
-			var imageMessageObject = { content : base64Image, imageUrl : 'http://lanceju-com.qiniudn.com/raindrop.jpg' };
-			var args = [ testConfig.message.fromUserId, testConfig.message.toUserId, 'RC:ImgMsg', JSON.stringify( imageMessageObject ) ];
-
-      var argsArray = [];
-      for( var i=0; i<3; ++i ) {
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ) ) );
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ), 'json' ) );
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ), 'xml' ) );
-      }
-
-      async.each( argsArray, function( _args, cb ) {
-        rongSDK.message.publish.apply( this, _args.concat( function( err, resultText ) {
-          if( _args[ _args.length - 1 ] === 'xml' ) {
-            should.not.exists( err );
-            parseString( resultText, function( err, result ) {
-              parseInt( result.xml.code[0] ).should.equal( 200 );
-              cb();
-            } );
-          }
-          else {
-            should.not.exists( err );
-            var result = JSON.parse( resultText );
-            result.code.should.equal( 200 );
-            cb();
-          }
-        } ) );
-      }, function() {
-        done();
-      } );
-
-
-		} );
-
-		it( 'Voice message: should return OK', function( done ) {
-
-			var voiceMessageObject = { content : base64Voice, duration : 4 };
-			var args = [testConfig.message.fromUserId, testConfig.message.toUserId, 'RC:VcMsg', JSON.stringify( voiceMessageObject ) ];
-
-      var argsArray = [];
-      for( var i=0; i<3; ++i ) {
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ) ) );
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ), 'json' ) );
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ), 'xml' ) );
-      }
-
-      async.each( argsArray, function( _args, cb ) {
-        rongSDK.message.publish.apply( this, _args.concat( function( err, resultText ) {
-          if( _args[ _args.length - 1 ] === 'xml' ) {
-            should.not.exists( err );
-            parseString( resultText, function( err, result ) {
-              parseInt( result.xml.code[0] ).should.equal( 200 );
-              cb();
-            } );
-          }
-          else {
-            should.not.exists( err );
-            var result = JSON.parse( resultText );
-            result.code.should.equal( 200 );
-            cb();
-          }
-        } ) );
-      }, function() {
-        done();
-      } );
-
-		} );
-
-
-		it( 'Image Text message: should return OK', function( done ) {
-			var imageTextMessageObject = { title : 'hellotitle', content : 'hello', imageUrl : 'http://lanceju-com.qiniudn.com/raindrop.jpg', extra : 'image from a user' };
-
-			var args = [testConfig.message.fromUserId, testConfig.message.toUserId, 'RC:ImgTextMsg', JSON.stringify( imageTextMessageObject ) ];
-
-      var argsArray = [];
-      for( var i=0; i<3; ++i ) {
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ) ) );
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ), 'json' ) );
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ), 'xml' ) );
-      }
-
-      async.each( argsArray, function( _args, cb ) {
-        rongSDK.message.publish.apply( this, _args.concat( function( err, resultText ) {
-          if( _args[ _args.length - 1 ] === 'xml' ) {
-            should.not.exists( err );
-            parseString( resultText, function( err, result ) {
-              parseInt( result.xml.code[0] ).should.equal( 200 );
-              cb();
-            } );
-          }
-          else {
-            should.not.exists( err );
-            var result = JSON.parse( resultText );
-            result.code.should.equal( 200 );
-            cb();
-          }
-        } ) );
-      }, function() {
-        done();
-      } );
-
-		} );
-
-		it( 'Location message: should return OK', function( done ) {
-			var locationMessageObject = { content : 'You got a location message', latitude : 24.114, longitude : 334.221, poi : '北京市朝阳区北苑路北辰泰岳大厦', extra : 'The location of rong cloud' };
-
-			var args = [testConfig.message.fromUserId, testConfig.message.toUserId, 'RC:LBSMsg', JSON.stringify( locationMessageObject ) ];
-
-      var argsArray = [];
-      for( var i=0; i<3; ++i ) {
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ) ) );
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ), 'json' ) );
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ), 'xml' ) );
-      }
-
-      async.each( argsArray, function( _args, cb ) {
-        rongSDK.message.private.publish.apply( this, _args.concat( function( err, resultText ) {
-          if( _args[ _args.length - 1 ] === 'xml' ) {
-            should.not.exists( err );
-            parseString( resultText, function( err, result ) {
-              parseInt( result.xml.code[0] ).should.equal( 200 );
-              cb();
-            } );
-          }
-          else {
-            should.not.exists( err );
-            var result = JSON.parse( resultText );
-            result.code.should.equal( 200 );
-            cb();
-          }
-        } ) );
-      }, function() {
-        done();
-      } );
-
-		} );
-
-		it( 'ContactNtf message: should return OK', function( done ) {
-			var contactNtfMessageObject = { operation:"op1",sourceUserId:"24",targetUserId:"21",message:"haha",extra:"helloExtra"};
-			var args = [testConfig.message.fromUserId, testConfig.message.toUserId, 'RC:ContactNtf', JSON.stringify( contactNtfMessageObject ) ];
-
-      var argsArray = [];
-      for( var i=0; i<3; ++i ) {
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ) ) );
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ), 'json' ) );
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ), 'xml' ) );
-      }
-
-      async.each( argsArray, function( _args, cb ) {
-        rongSDK.message.private.publish.apply( this, _args.concat( function( err, resultText ) {
-          if( _args[ _args.length - 1 ] === 'xml' ) {
-            should.not.exists( err );
-            parseString( resultText, function( err, result ) {
-              parseInt( result.xml.code[0] ).should.equal( 200 );
-              cb();
-            } );
-          }
-          else {
-            should.not.exists( err );
-            var result = JSON.parse( resultText );
-            result.code.should.equal( 200 );
-            cb();
-          }
-        } ) );
-      }, function() {
-        done();
-      } );
-
-		} );
-
-	} );
-
-
-	describe( 'Publish Template Message', function() {
-		it( 'Send template message: should return OK', function( done ) {
-
-      var content = JSON.stringify( { content : "aa{c}{e}{d}", extra : "bb" } );
-      var values  = [ { "{c}":"1","{d}":"2","{e}":"3"} ];
-
-      /*
-			rongSDK.message.private.publish_template( testConfig.message.fromUserId, [testConfig.message.toUserId], 'RC:TxtMsg', content, values, [ 'push content for user' ], ['push data for user'], function( err, resultText ) {
-        return done();
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-				done();
-			} );
-      */
-
-			var args = [testConfig.message.fromUserId, [testConfig.message.toUserId], 'RC:TxtMsg', content, values, [ 'push content for user' ], ['push data for user'] ];
-
-      var argsArray = [];
-      argsArray.push( args.concat() );
-      argsArray.push( args.concat( 'json' ) );
-      argsArray.push( args.concat( 'xml' ) );
-
-      async.each( argsArray, function( _args, cb ) {
-        rongSDK.message.private.publish_template.apply( this, _args.concat( function( err, resultText ) {
-          if( _args[ _args.length - 1 ] === 'xml' ) {
-            should.not.exists( err );
-            parseString( resultText, function( err, result ) {
-              parseInt( result.xml.code[0] ).should.equal( 200 );
-              cb();
-            } );
-          }
-          else {
-            should.not.exists( err );
-            var result = JSON.parse( resultText );
-            result.code.should.equal( 200 );
-            cb();
-          }
-        } ) );
-      }, function() {
-        done();
-      } );
-
-
-
-		} );
-
-		it( 'Send system message: should return OK', function( done ) {
-
-			var args = [testConfig.message.fromUserId, [testConfig.message.toUserId], 'RC:TxtMsg', JSON.stringify( { content : 'Hello, world!' } )];
-
-      var argsArray = [];
-      for( var i=0; i<3; ++i ) {
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ) ) );
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ), 'json' ) );
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ), 'xml' ) );
-      }
-
-      async.each( argsArray, function( _args, cb ) {
-        rongSDK.message.system.publish.apply( this, _args.concat( function( err, resultText ) {
-          if( _args[ _args.length - 1 ] === 'xml' ) {
-            should.not.exists( err );
-            parseString( resultText, function( err, result ) {
-              parseInt( result.xml.code[0] ).should.equal( 200 );
-              cb();
-            } );
-          }
-          else {
-            should.not.exists( err );
-            var result = JSON.parse( resultText );
-            result.code.should.equal( 200 );
-            cb();
-          }
-        } ) );
-      }, function() {
-        done();
-      } );
-
-		} );
-
-    it( 'Send group message before joining the group: should return error', function( done ) {
-      rongSDK.message.group.publish( testConfig.message.fromUserId, 'ProgrammerGroup1', 'RC:TxtMsg', JSON.stringify( { content : 'Hello, world!' } ), null, null, function( err, resultText ) {
-        should.exists( err );
-        // Joining the group
-        rongSDK.group.join( testConfig.message.fromUserId, 'ProgrammerGroup1', 'Programmers group', function( err, resultText ) {
-          should.not.exists( err );
-          var result = JSON.parse( resultText );
-          result.code.should.equal( 200 );
-          done();
-        } );
-
-      } );
-    } );
-
-    it( 'Send group message after joining the group: should return OK', function( done ) {
-      var args = [testConfig.message.fromUserId, 'ProgrammerGroup1', 'RC:TxtMsg', JSON.stringify( { content : 'Hello, world!' } )];
-
-      var argsArray = [];
-      for( var i=0; i<3; ++i ) {
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ) ) );
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ), 'json' ) );
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ), 'xml' ) );
-      }
-
-      async.each( argsArray, function( _args, cb ) {
-        rongSDK.message.group.publish.apply( this, _args.concat( function( err, resultText ) {
-          if( _args[ _args.length - 1 ] === 'xml' ) {
-            should.not.exists( err );
-            parseString( resultText, function( err, result ) {
-              parseInt( result.xml.code[0] ).should.equal( 200 );
-              cb();
-            } );
-          }
-          else {
-            should.not.exists( err );
-            var result = JSON.parse( resultText );
-            result.code.should.equal( 200 );
-            cb();
-          }
-        } ) );
-      }, function() {
-        // Dismiss the group after testing.
-        rongSDK.group.quit( testConfig.message.fromUserId, 'ProgrammerGroup1', function( err, resultText ) {
-          should.not.exists( err );
-          var result = JSON.parse( resultText );
-          result.code.should.equal( 200 );
-          done();
-        } );
-      } );
-
-    } );
-
-		it( 'Send chatroom message: should return OK', function( done ) {
-			var args = [testConfig.message.fromUserId, 'my chatroom', 'RC:TxtMsg', JSON.stringify( { content : 'Hello, world!' } ) ];
-      var argsArray = [];
-      for( var i=0; i<3; ++i ) {
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ) ) );
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ), 'json' ) );
-        argsArray.push( args.concat( optionalArgs.slice( 0, i ), 'xml' ) );
-      }
-
-      async.each( argsArray, function( _args, cb ) {
-        rongSDK.message.chatroom.publish.apply( this, _args.concat( function( err, resultText ) {
-          if( _args[ _args.length - 1 ] === 'xml' ) {
-            should.not.exists( err );
-            parseString( resultText, function( err, result ) {
-              parseInt( result.xml.code[0] ).should.equal( 200 );
-              cb();
-            } );
-          }
-          else {
-            should.not.exists( err );
-            var result = JSON.parse( resultText );
-            result.code.should.equal( 200 );
-            cb();
-          }
-        } ) );
-      }, function() {
-        done();
-      } );
-		} );
-
-  } );
-
-
-  // Since this API is a charing service, make sure your appKey&appSecret is from an charged account.
-	// describe( 'Broadcast Message', function() {
-	// 	it( 'Should return OK', function( done ) {
-	// 		rongSDK.message.broadcast( testConfig.message.fromUserId, 'RC:TxtMsg', testConfig.message.textMsg, function( err, resultText ) {
-	// 			should.not.exists( err );
-	// 			var result = JSON.parse( resultText );
-	// 			result.code.should.equal( 200 );
-	// 			done();
-	// 		} );
-	// 	} );
-	// } );
-
-} );

+ 0 - 177
test/test.user.js

@@ -1,177 +0,0 @@
-
-var should 		= require( 'should' );
-var testConfig  = require( './config' );
-var rongSDK 	= require( '../index' );
-
-
-describe( 'User Test', function() {
-	before( function( done ) {
-		// Init the SDK before testing.
-		rongSDK.init( testConfig.appKey, testConfig.appSecret );
-		done();
-	} );
-
-	after( function( done ) {
-		done();
-	} );
-
-	describe( 'Get token', function() {
-		it( 'Should return OK', function( done ) {
-			rongSDK.user.getToken( testConfig.token.userId, testConfig.token.name, testConfig.token.portraitUri, function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-				done();
-			} );
-		} );
-	} );
-
-
-
-	describe( 'Refresh user info', function() {
-		it( 'Should return OK', function( done ) {
-			rongSDK.user.refresh( testConfig.token.userId, testConfig.token.name, testConfig.token.portraitUri, function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-				done();
-			} );
-		} );
-	} );
-
-	describe( 'Check user online status', function() {
-		it( 'Check a non-existing user, should return OK', function( done ) {
-			rongSDK.user.checkOnline( 'im not here', function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-        result.status.should.equal( '0' );  // Notice: the status is a string, not int.
-				done();
-			} );
-		} );
-	} );
-
-	describe( 'Block user', function() {
-		it( 'Block a user within 1 minute, should return OK', function( done ) {
-			rongSDK.user.block( testConfig.token.userId, 1, function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-
-        // Check if the user is in the blocked list.
-			  rongSDK.user.block.query ( function( err, resultText ) {
-          should.not.exists( err );
-          var result = JSON.parse( resultText );
-          result.code.should.equal( 200 );
-          should.exists( result.users );
-          var isUserBlocked = findUser( result.users, testConfig.token.userId );
-          isUserBlocked.should.equal( true );
-				  done();
-        } );
-
-			} );
-		} );
-	} );
-
-
-	describe( 'Unblock user', function() {
-		it( 'Unblock the previously blocked user, should return OK', function( done ) {
-			rongSDK.user.unblock( testConfig.token.userId, function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-
-        // Check if the user is in the blocked list.
-			  rongSDK.user.block.query( function( err, resultText ) {
-          should.not.exists( err );
-          var result = JSON.parse( resultText );
-          result.code.should.equal( 200 );
-          should.exists( result.users );
-          var isUserBlocked = findUser( result.users, testConfig.token.userId );
-          isUserBlocked.should.equal( false );
-				  done();
-        } );
-
-			} );
-		} );
-	} );
-
-
-	describe( 'Query blocked users', function() {
-		it( 'The test is obtained in the block/unblock user API tests', function( done ) {
-      done();
-		} );
-	} );
-
-	describe( 'Black list', function() {
-		it( 'Add a user to the black list, should return OK', function( done ) {
-			rongSDK.user.blacklist.add( testConfig.message.toUserId, testConfig.message.fromUserId, function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-        done();
-			} );
-		} );
-
-
-    // TODO Send a message from fromUserId to toUserId
-
-		it( 'Query a user\'s black list, should get the "Black User"', function( done ) {
-			rongSDK.user.blacklist.query( testConfig.message.toUserId, function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-        var isInBlacklist = findUserId( result.users, testConfig.message.fromUserId );
-        isInBlacklist.should.equal( true );
-				result.code.should.equal( 200 );
-        done();
-			} );
-		} );
-
-		it( 'Remove a user from the black list, should return OK', function( done ) {
-			rongSDK.user.blacklist.remove( testConfig.message.toUserId, testConfig.message.fromUserId, function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-				result.code.should.equal( 200 );
-        done();
-			} );
-		} );
-
-    // TODO Send a message from fromUserId to toUserId
-
-		it( 'Query a user\'s black list, should get not the "Black User"', function( done ) {
-			rongSDK.user.blacklist.query( testConfig.message.toUserId, function( err, resultText ) {
-				should.not.exists( err );
-				var result = JSON.parse( resultText );
-        var isInBlacklist = findUserId( result.users, testConfig.message.fromUserId );
-        isInBlacklist.should.equal( false );
-				result.code.should.equal( 200 );
-        done();
-			} );
-		} );
-
-	} );
-
-} );
-
-
-function findUser( users, userId ) {
-  var found = false;
-  for( var i=0; i<users.length; ++i ) {
-    if( users[i].userId === userId ) {
-      found = true;
-      break;
-    }
-  }
-  return found;
-}
-
-function findUserId( userIDs, userId ) {
-  var found = false;
-  for( var i=0; i<userIDs.length; ++i ) {
-    if( userIDs[i] === userId ) {
-      found = true;
-      break;
-    }
-  }
-  return found;
-}

BIN
test/testvoice.amr


BIN
test/testvoice.mp3