cloudflare.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. var reqwest = require('reqwest');
  2. var assign = require('react/lib/Object.assign');
  3. function makeCall(method, path) {
  4. return function() {
  5. var localPath = path;
  6. var pathParams = null;
  7. var options = {};
  8. if(arguments.length > 0) {
  9. pathParams = arguments[0];
  10. }
  11. if(arguments.length > 1) {
  12. options = arguments[1];
  13. }
  14. if(typeof pathParams != "object") {
  15. pathParams = {zoneId: pathParams};
  16. }
  17. for(var key in pathParams) {
  18. localPath = localPath.replace(':'+key, pathParams[key]);
  19. }
  20. return reqwest({
  21. url: '/api'+localPath,
  22. data: method == 'GET' ? null : JSON.stringify(options),
  23. method: method,
  24. contentType: 'application/json'
  25. });
  26. };
  27. }
  28. module.exports = {
  29. domains: makeCall('GET', '/zones'),
  30. records: makeCall('GET', '/zones/:zoneId/dns_records'),
  31. recordAdd: makeCall('POST', '/zones/:zoneId/dns_records'),
  32. recordEdit: makeCall('PUT', '/zones/:zoneId/dns_records/:recId'),
  33. recordDelete: makeCall('DELETE', '/zones/:zoneId/dns_records/:recId'),
  34. settings: makeCall('GET', '/zones/:zoneId/settings'),
  35. settingChange: makeCall('PATCH', '/zones/:zoneId/settings/:setting'),
  36. purgeCache: makeCall('DELETE', '/zones/:zoneId/purge_cache')
  37. };