Guest User

Untitled

a guest
Mar 31st, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. const axios = require('axios');
  2. const querystring = require('querystring');
  3.  
  4. /* eslint-disable no-unused-vars */
  5. class Service {
  6. constructor (options) {
  7. this.options = options || {};
  8. }
  9.  
  10. get (id, params) {
  11. const arcgis = this.options.arcgis;
  12.  
  13. // auth data
  14. const data = {
  15. f: 'json',
  16. client: 'referer',
  17. referer: this.options.host,
  18. request: 'getToken',
  19. expiration: arcgis.tokenExpires, // 60 minutes
  20. username: arcgis.username,
  21. password: arcgis.password
  22. };
  23.  
  24. // token url
  25. const url = arcgis.url + '/tokens/generateToken';
  26.  
  27. // some headers for passing form data
  28. const headers = {
  29. 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
  30. 'Accept': 'application/json'
  31. };
  32.  
  33. return axios.post(url, querystring.stringify(data), {
  34. headers
  35. }).then(result => {
  36. Object.assign(result.data, {
  37. server: arcgis.url + '/rest/services',
  38. ssl: true
  39. });
  40. return result.data;
  41. });
  42. }
  43. }
  44.  
  45. module.exports = function (options) {
  46. return new Service(options);
  47. };
  48.  
  49. module.exports.Service = Service;
Add Comment
Please, Sign In to add comment