Skip to content

Commit

Permalink
refactor of describe
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinohara80 committed Jan 21, 2014
1 parent 1bc3ca1 commit d637536
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
17 changes: 17 additions & 0 deletions examples/describe.js
@@ -0,0 +1,17 @@
var nforce = require('../');
var sfuser = process.env.SFUSER;
var sfpass = process.env.SFPASS;

var org = nforce.createConnection({
clientId: '3MVG9rFJvQRVOvk5nd6A4swCyck.4BFLnjFuASqNZmmxzpQSFWSTe6lWQxtF3L5soyVLfjV3yBKkjcePAsPzi',
clientSecret: '9154137956044345875',
redirectUri: 'http://localhost:3000/oauth/_callback'
});

org.authenticate({ username: sfuser, password: sfpass }, function(err, oauth) {
if(err) throw err;
org.getDescribe({ type: 'Account', oauth: oauth }, function(err, res) {
if(err) throw err;
console.log(res);
});
});
2 changes: 1 addition & 1 deletion examples/metadata.js
Expand Up @@ -13,5 +13,5 @@ org.authenticate({ username: sfuser, password: sfpass }, function(err, oauth) {
org.getMetadata({ type: 'Account', oauth: oauth }, function(err, res) {
if(err) throw err;
console.log(res);
})
});
});
26 changes: 5 additions & 21 deletions index.js
Expand Up @@ -283,27 +283,11 @@ Connection.prototype.getMetadata = function(data, callback) {
return this._apiRequest(opts, opts.callback);
}

Connection.prototype.getDescribe = function(data, oauth, callback) {
var uri, opts;

if(this.mode === 'single') {
var args = Array.prototype.slice.call(arguments);
oauth = this.oauth;
if(args.length == 2) callback = args[1];
}

if(!callback) callback = function(){}

if(typeof data !== 'string') {
return callback(new Error('Type must be in the form of a string'), null);
}

if(!util.validateOAuth(oauth)) return callback(new Error('Invalid oauth object argument'), null);

uri = oauth.instance_url + '/services/data/' + this.apiVersion + '/sobjects/' + data + '/describe';
opts = { uri: uri, method: 'GET' }

return this._apiRequest(opts, oauth, null, callback);
Connection.prototype.getDescribe = function(data, callback) {
var opts = this._getOpts(arguments);
opts.resource = '/sobjects/' + opts.type + '/describe';
opts.method = 'GET';
return this._apiRequest(opts, opts.callback);
}

Connection.prototype.insert = function(data, oauth, callback) {
Expand Down

0 comments on commit d637536

Please sign in to comment.