Guest User

Untitled

a guest
Apr 17th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. const request = require('request-promise-native');
  2.  
  3. const FOO = function(creds) {
  4. let self = this;
  5.  
  6. this.endpoint = creds.endpoint;
  7. this.username = creds.username;
  8. this.password = creds.password;
  9.  
  10. this.urlForPath = function(path) {
  11. return this.endpoint + '/' + path;
  12. }
  13.  
  14. this.login = function() {
  15. var options = {
  16. url: this.urlForPath('api/login'),
  17. formData: {
  18. username: this.username,
  19. password: this.password
  20. }
  21. };
  22. return request(options)
  23. .then(function(body) {
  24. self.cookie = JSON.parse(body).sess_id;
  25. });
  26. }
  27.  
  28. return this;
  29. }
  30.  
  31. module.exports = FOO;
Add Comment
Please, Sign In to add comment