Source: models/users/remote.js

  1. "use strict";
  2. /**
  3. * Construct a new Remote user.
  4. * @constructor
  5. * @param {string} identifier The unique ID for this user.
  6. * @param {Object=} data The serialized key-value data object to assign to this user.
  7. * @throws If identifier is not supplied.
  8. */
  9. function RemoteUser(identifier, data) {
  10. if (!identifier) {
  11. throw new Error("Missing identifier");
  12. }
  13. this.id = identifier;
  14. this.data = data || {};
  15. }
  16. /**
  17. * Get the Remote user's ID.
  18. * @return {string} Their ID.
  19. */
  20. RemoteUser.prototype.getId = function() {
  21. return this.id;
  22. };
  23. /**
  24. * Serialize all the data about this user, excluding their remote ID.
  25. * @return {Object} The serialised data
  26. */
  27. RemoteUser.prototype.serialize = function() {
  28. return this.data;
  29. }
  30. /**
  31. * Get the data value for the given key.
  32. * @param {string} key An arbitrary bridge-specific key.
  33. * @return {*} Stored data for this key. May be undefined.
  34. */
  35. RemoteUser.prototype.get = function(key) {
  36. return this.data[key];
  37. };
  38. /**
  39. * Set an arbitrary bridge-specific data value for this user.
  40. * @param {string} key The key to store the data value under.
  41. * @param {*} val The data value. This value should be serializable via
  42. * <code>JSON.stringify(data)</code>.
  43. */
  44. RemoteUser.prototype.set = function(key, val) {
  45. this.data[key] = val;
  46. };
  47. /** The Remote user class. */
  48. module.exports = RemoteUser;