123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- var apis = require( './apis' );
- var rongrequest = require( './rongrequest' );
- 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 : typeof content === 'object' ? JSON.stringify(content) : content
- }
- var f = arguments[ arguments.length - 2 ];
- var formatSpecified = f === 'json' || f === 'xml';
- var indexOfLastParam = formatSpecified ? arguments.length - 3 : arguments.length - 2;
- callback = arguments[arguments.length - 1];
- var optionalArgs = { '4' : 'pushContent', '5' : 'pushData' };
- for( var i=4; i<=indexOfLastParam; ++i ) {
- if( optionalArgs[i] ) {
- requestParams[ optionalArgs[i] ] = arguments[i];
- }
- }
- 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 : typeof content === 'object' ? JSON.stringify(content) : content,
- toUserId : toUserIDs,
- values : values,
- pushContent : pushContent,
- pushData : pushData
- }
- rongrequest.requestWithHeaders( apis[ 'message']['private']['publish_template'], requestParams, format, { 'Content-Type' : 'application/json' }, function( err, resultText ) {
- return callback( err, resultText );
- } );
- }
- exports.system = {};
- exports.system.publish = function( fromUserId, toUserIDs, objectName, content, pushContent, pushData, format, callback ) {
- var requestParams = {
- fromUserId : fromUserId,
- objectName : objectName,
- content : typeof content === 'object' ? JSON.stringify(content) : content
- }
- var f = arguments[ arguments.length - 2 ];
- var formatSpecified = f === 'json' || f === 'xml';
- var indexOfLastParam = formatSpecified ? arguments.length - 3 : arguments.length - 2;
- callback = arguments[arguments.length - 1];
- var optionalArgs = { '4' : 'pushContent', '5' : 'pushData' };
- for( var i=4; i<=indexOfLastParam; ++i ) {
- if( optionalArgs[i] ) {
- requestParams[ optionalArgs[i] ] = arguments[i];
- }
- }
- rongrequest.requestWithSameFields( apis[ 'message']['system']['publish'], requestParams, [ { field : 'toUserId', values : toUserIDs } ], formatSpecified ? f : 'json', function( err, resultText ) {
- return callback( err, resultText );
- } );
- }
- //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 : typeof content === 'object' ? JSON.stringify(content) : content
- }
- var f = arguments[ arguments.length - 2 ];
- var formatSpecified = f === 'json' || f === 'xml';
- var indexOfLastParam = formatSpecified ? arguments.length - 3 : arguments.length - 2;
- callback = arguments[arguments.length - 1];
- var optionalArgs = { '4' : 'pushContent', '5' : 'pushData' };
- for( var i=4; i<=indexOfLastParam; ++i ) {
- if( optionalArgs[i] ) {
- requestParams[ optionalArgs[i] ] = arguments[i];
- }
- }
- rongrequest.request( apis[ 'message']['group']['publish'], requestParams, formatSpecified ? f : 'json', function( err, resultText ) {
- return callback( err, resultText );
- } );
- }
- exports.chatroom = {};
- exports.chatroom.publish = function( fromUserId, toChatroomId, objectName, content, pushContent, pushData, format, callback ) {
- var requestParams = {
- fromUserId : fromUserId,
- toChatroomId : toChatroomId,
- objectName : objectName,
- content : typeof content === 'object' ? JSON.stringify(content) : content
- }
- var f = arguments[ arguments.length - 2 ];
- var formatSpecified = f === 'json' || f === 'xml';
- var indexOfLastParam = formatSpecified ? arguments.length - 3 : arguments.length - 2;
- callback = arguments[arguments.length - 1];
- var optionalArgs = { '4' : 'pushContent', '5' : 'pushData' };
- for( var i=4; i<=indexOfLastParam; ++i ) {
- if( optionalArgs[i] ) {
- requestParams[ optionalArgs[i] ] = arguments[i];
- }
- }
- rongrequest.request( apis[ 'message']['chatroom']['publish'], requestParams, formatSpecified ? f : 'json', function( err, resultText ) {
- return callback( err, resultText );
- } );
- }
- //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 : typeof content === 'object' ? JSON.stringify(content) : content
- }
- var f = arguments[ arguments.length - 2 ];
- var formatSpecified = f === 'json' || f === 'xml';
- var indexOfLastParam = formatSpecified ? arguments.length - 3 : arguments.length - 2;
- callback = arguments[arguments.length - 1];
- var optionalArgs = { '3' : 'pushContent', '4' : 'pushData' };
- for( var i=4; i<=indexOfLastParam; ++i ) {
- if( optionalArgs[i] ) {
- requestParams[ optionalArgs[i] ] = arguments[i];
- }
- }
- 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'], {
- date : dateString
- }, format, function( err, resultText ) {
- return callback( err, resultText );
- } );
- }
|