user.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. var apis = require( './apis' );
  2. var rongrequest = require( './rongrequest' );
  3. exports.getToken = function( userId, name, portraitUri, format, callback ) {
  4. rongrequest.request( apis['user']['getToken'], {
  5. userId : userId,
  6. name : name,
  7. portraitUri : portraitUri
  8. }, format, function( err, result ) {
  9. return callback( err, result );
  10. } );
  11. }
  12. exports.refresh = function( userId, name, portraitUri, format, callback ) {
  13. var params
  14. if(name && portraitUri)
  15. params = {
  16. userId: userId,
  17. name: name,
  18. portraitUri: portraitUri
  19. }
  20. else if(name && !portraitUri)
  21. params = {
  22. userId: userId,
  23. name: name
  24. }
  25. else if(!name && portraitUri)
  26. params = {
  27. userId: userId,
  28. portraitUri: portraitUri
  29. }
  30. else
  31. params = {
  32. userId: userId
  33. }
  34. rongrequest.request( apis['user']['refresh'], params, format, function( err, result ) {
  35. return callback( err, result );
  36. } );
  37. }
  38. exports.checkOnline = function( userId, format, callback ) {
  39. rongrequest.request( apis['user']['checkOnline'], {
  40. userId : userId
  41. }, format, function( err, result ) {
  42. return callback( err, result );
  43. } );
  44. }
  45. exports.block = function( userId, numMinutes, format, callback ) {
  46. numMinutes = parseInt( numMinutes );
  47. if( numMinutes <= 0 ) { // Don't need to call the API.
  48. return callback( null, '{"code":200}' );
  49. }
  50. if( numMinutes > 43200 ) {
  51. numMinutes = 43200;
  52. }
  53. rongrequest.request( apis['user']['block'], {
  54. userId : userId,
  55. minute : numMinutes
  56. }, format, function( err, result ) {
  57. return callback( err, result );
  58. } );
  59. }
  60. exports.unblock = function( userId, format, callback ) {
  61. rongrequest.request( apis['user']['unblock'], {
  62. userId : userId
  63. }, format, function( err, result ) {
  64. return callback( err, result );
  65. } );
  66. }
  67. exports.block.query = function( format, callback ) {
  68. rongrequest.request( apis['user']['queryBlocked'], {}, format, function( err, result ) {
  69. return callback( err, result );
  70. } );
  71. }
  72. exports.blacklist = {};
  73. exports.blacklist.add = function( userId, blackUserId, format, callback ) {
  74. rongrequest.request( apis['user']['addToBlackList'], {
  75. userId : userId,
  76. blackUserId : blackUserId
  77. }, format, function( err, result ) {
  78. return callback( err, result );
  79. } );
  80. }
  81. exports.blacklist.remove = function( userId, blackUserId, format, callback ) {
  82. rongrequest.request( apis['user']['removeFromBlacklist'], {
  83. userId : userId,
  84. blackUserId : blackUserId
  85. }, format, function( err, result ) {
  86. return callback( err, result );
  87. } );
  88. }
  89. exports.blacklist.query = function( userId, format, callback ) {
  90. rongrequest.request( apis['user']['queryBlacklist'], {
  91. userId : userId
  92. }, format, function( err, result ) {
  93. return callback( err, result );
  94. } );
  95. }