Explorar o código

Make API-related method names consistent

Thomas Dy %!s(int64=10) %!d(string=hai) anos
pai
achega
5b362bf4e3
Modificáronse 3 ficheiros con 41 adicións e 39 borrados
  1. 20 21
      lib/cloudflare.js
  2. 11 11
      lib/stores.js
  3. 10 7
      lib/ui/RecordList.jsx

+ 20 - 21
lib/cloudflare.js

@@ -2,10 +2,18 @@ var reqwest = require('reqwest');
 var assign = require('react/lib/Object.assign');
 
 function makeCall(path) {
-  return function(options) {
+  return function() {
+    var domain = null;
+    var options = {};
+    if(arguments.length > 0) {
+      domain = arguments[0];
+    }
+    if(arguments.length > 1) {
+      options = arguments[1];
+    }
     return reqwest({
       url: '/api',
-      data: assign({a: path}, options),
+      data: assign({a: path, z: domain}, options),
       method: 'POST'
     });
   };
@@ -13,26 +21,17 @@ function makeCall(path) {
 
 module.exports = {
   domains: makeCall('zone_load_multi'),
-  settings: function(domain) {
-    return makeCall('zone_settings')({z: domain});
+  settings: makeCall('zone_settings'),
+  records: makeCall('rec_load_all'),
+  recordAdd: makeCall('rec_new'),
+  recordEdit: makeCall('rec_edit'),
+  recordDelete: function(domain, id) {
+    return makeCall('rec_delete')(domain, {id: id});
   },
-  set_devmode: function(domain, toggle) {
-    return makeCall('devmode')({z: domain, v: toggle ? 1 : 0});
+  setDevelopmentMode: function(domain, toggle) {
+    return makeCall('devmode')(domain, {v: toggle ? 1 : 0});
   },
-  purge_cache: function(domain) {
-    return makeCall('fpurge_ts')({z: domain, v: 1});
-  },
-  records: function(domain) {
-    return makeCall('rec_load_all')({z: domain});
-  },
-  record_add: function(domain, options) {
-    return makeCall('rec_new')(assign({z: domain, ttl: 1}, options));
-  },
-  record_edit: function(domain, options) {
-    return makeCall('rec_edit')(assign({z: domain, ttl: 1}, options));
-  },
-  record_delete: function(domain, id) {
-    return makeCall('rec_delete')({z: domain, id: id});
+  purgeCache: function(domain) {
+    return makeCall('fpurge_ts')(domain, {v: 1});
   }
 };
-

+ 11 - 11
lib/stores.js

@@ -29,16 +29,16 @@ function loadSettings(name) {
   });
 }
 
-function addRecord(name, record) {
-  return cloudflare.record_add(name, record).then(function(data) {
+function recordAdd(name, record) {
+  return cloudflare.recordAdd(name, record).then(function(data) {
     if(data.result === 'success') {
       findDomain(name).records.push(data.response.rec.obj);
     }
   });
 }
 
-function editRecord(name, record) {
-  return cloudflare.record_edit(name, record).then(function(data) {
+function recordEdit(name, record) {
+  return cloudflare.recordEdit(name, record).then(function(data) {
     if(data.result === 'success') {
       var domain = findDomain(name);
       var oldRecord = domain.records.find(function(r) {
@@ -49,8 +49,8 @@ function editRecord(name, record) {
   });
 }
 
-function deleteRecord(name, id) {
-  return cloudflare.record_delete(name, id).then(function(data) {
+function recordDelete(name, id) {
+  return cloudflare.recordDelete(name, id).then(function(data) {
     if(data.result === 'success') {
       var domain = findDomain(name);
       var oldRecord = domain.records.find(function(r) {
@@ -62,7 +62,7 @@ function deleteRecord(name, id) {
 }
 
 function setDevelopmentMode(name, value) {
-  return cloudflare.set_devmode(name, value).then(function(data) {
+  return cloudflare.setDevelopmentMode(name, value).then(function(data) {
     if(data.result === 'success') {
       findDomain(name).settings.dev_mode.set(data.response.expires_on || 0);
     }
@@ -70,7 +70,7 @@ function setDevelopmentMode(name, value) {
 }
 
 function purgeCache(name) {
-  return cloudflare.purge_cache(name);
+  return cloudflare.purgeCache(name);
 }
 
 cloudflare.domains().then(function(data) {
@@ -84,9 +84,9 @@ cloudflare.domains().then(function(data) {
 module.exports = {
   Domains: {
     find: findDomain,
-    add: addRecord,
-    edit: editRecord,
-    remove: deleteRecord,
+    recordAdd: recordAdd,
+    recordEdit: recordEdit,
+    recordDelete: recordDelete,
     setDevelopmentMode: setDevelopmentMode,
     purgeCache: purgeCache,
     loadRecords: loadRecords,

+ 10 - 7
lib/ui/RecordList.jsx

@@ -40,9 +40,10 @@ var RecordCreate = React.createClass({
     var newRecord = {
       type: this.refs.type.getDOMNode().value,
       name: this.refs.name.getDOMNode().value.trim(),
-      content: this.refs.value.getDOMNode().value.trim()
+      content: this.refs.value.getDOMNode().value.trim(),
+      ttl: 1
     };
-    this.finishSave(DomainStore.add(this.props.domain, newRecord));
+    this.finishSave(DomainStore.recordAdd(this.props.domain, newRecord));
   },
   render: function() {
     var className = this.state.saving ? 'saving' : '';
@@ -85,7 +86,7 @@ var Record = React.createClass({
   commitDelete: function() {
     this.setState({saving: true});
     var record = this.props.record;
-    DomainStore.remove(record.zone_name.val(), record.rec_id.val());
+    DomainStore.recordDelete(record.zone_name.val(), record.rec_id.val());
   },
   commitEdit: function() {
     this.setState({saving: true});
@@ -94,12 +95,13 @@ var Record = React.createClass({
       id: record.rec_id.val(),
       type: record.type.val(),
       name: this.refs.name.getDOMNode().value.trim(),
-      content: this.refs.value.getDOMNode().value.trim()
+      content: this.refs.value.getDOMNode().value.trim(),
+      ttl: 1
     };
     if(record.service_mode.val()) {
       newRecord.service_mode = record.service_mode.val();
     }
-    DomainStore.edit(record.zone_name.val(), newRecord);
+    DomainStore.recordEdit(record.zone_name.val(), newRecord);
   },
   toggleProxy: function() {
     this.setState({saving: true});
@@ -109,9 +111,10 @@ var Record = React.createClass({
       type: record.type.val(),
       name: record.name.val(),
       content: record.content.val(),
-      service_mode: record.service_mode.val() === "1" ? "0" : "1"
+      service_mode: record.service_mode.val() === "1" ? "0" : "1",
+      ttl: 1
     };
-    DomainStore.edit(record.zone_name.val(), newRecord);
+    DomainStore.recordEdit(record.zone_name.val(), newRecord);
   },
   render: function() {
     var record = this.props.record;