user.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. rongrequest.request( apis['user']['refresh'], {
  14. userId : userId,
  15. name : name,
  16. portraitUri : portraitUri
  17. }, format, function( err, result ) {
  18. return callback( err, result );
  19. } );
  20. }
  21. exports.checkOnline = function( userId, format, callback ) {
  22. rongrequest.request( apis['user']['checkOnline'], {
  23. userId : userId
  24. }, format, function( err, result ) {
  25. return callback( err, result );
  26. } );
  27. }
  28. exports.block = function( userId, numMinutes, format, callback ) {
  29. numMinutes = parseInt( numMinutes );
  30. if( numMinutes <= 0 ) { // Don't need to call the API.
  31. return callback( null, '{"code":200}' );
  32. }
  33. if( numMinutes > 43200 ) {
  34. numMinutes = 43200;
  35. }
  36. rongrequest.request( apis['user']['block'], {
  37. userId : userId,
  38. minute : numMinutes
  39. }, format, function( err, result ) {
  40. return callback( err, result );
  41. } );
  42. }
  43. exports.unblock = function( userId, format, callback ) {
  44. rongrequest.request( apis['user']['unblock'], {
  45. userId : userId
  46. }, format, function( err, result ) {
  47. return callback( err, result );
  48. } );
  49. }
  50. exports.block.query = function( format, callback ) {
  51. rongrequest.request( apis['user']['queryBlocked'], {}, format, function( err, result ) {
  52. return callback( err, result );
  53. } );
  54. }
  55. exports.blacklist = {};
  56. exports.blacklist.add = function( userId, blackUserId, format, callback ) {
  57. rongrequest.request( apis['user']['addToBlackList'], {
  58. userId : userId,
  59. blackUserId : blackUserId
  60. }, format, function( err, result ) {
  61. return callback( err, result );
  62. } );
  63. }
  64. exports.blacklist.remove = function( userId, blackUserId, format, callback ) {
  65. rongrequest.request( apis['user']['removeFromBlacklist'], {
  66. userId : userId,
  67. blackUserId : blackUserId
  68. }, format, function( err, result ) {
  69. return callback( err, result );
  70. } );
  71. }
  72. exports.blacklist.query = function( userId, format, callback ) {
  73. rongrequest.request( apis['user']['queryBlacklist'], {
  74. userId : userId
  75. }, format, function( err, result ) {
  76. return callback( err, result );
  77. } );
  78. }