Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

optimization/http method registration simplification #60

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2014​, salesforce.com, inc.
* Copyright (c) 2015​, salesforce.com, inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
Expand Down
66 changes: 15 additions & 51 deletions lib/fuel-rest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2014​, salesforce.com, inc.
* Copyright (c) 2015​, salesforce.com, inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
Expand All @@ -23,17 +23,18 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
'use strict';

var version = require('../package.json').version;
var helpers = require('./helpers');
var request = require('request');
var _ = require('lodash');
var FuelAuth = require('fuel-auth');
var helpers = require('./helpers');
var Promiser = (typeof Promise === 'undefined') ? require('bluebird') : Promise;
var request = require('request');
var version = require('../package.json').version;

var FuelRest = function(options) {
'use strict';
var methods = ['get', 'post', 'put', 'patch', 'delete'];

var FuelRest = function(options) {
var authOptions = options && options.auth || {};

// use fuel auth instance if applicable
Expand All @@ -60,8 +61,6 @@ var FuelRest = function(options) {
};

FuelRest.prototype.apiRequest = function(options, callback) {
'use strict';

var self = this;

// we need options
Expand Down Expand Up @@ -144,49 +143,14 @@ FuelRest.prototype.apiRequest = function(options, callback) {
});
};

FuelRest.prototype.get = function(options, callback) {
'use strict';

options.method = 'GET';
options.retry = true;

return this.apiRequest(options, callback);
};

FuelRest.prototype.post = function(options, callback) {
'use strict';

options.method = 'POST';
options.retry = true;
// setup simple http methods
methods.forEach(function(method) {
FuelRest.prototype[method] = function(options, callback) {
options.method = method.toUpperCase();
options.retry = true;

return this.apiRequest(options, callback);
};

FuelRest.prototype.put = function(options, callback) {
'use strict';

options.method = 'PUT';
options.retry = true;

return this.apiRequest(options, callback);
};

FuelRest.prototype.patch = function(options, callback) {
'use strict';

options.method = 'PATCH';
options.retry = true;

return this.apiRequest(options, callback);
};

FuelRest.prototype.delete = function(options, callback) {
'use strict';

options.method = 'DELETE';
options.retry = true;

return this.apiRequest(options, callback);
};
return this.apiRequest(options, callback);
};
});

module.exports = FuelRest;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Node library for performing REST API calls to Salesforce Marketing Cloud (formerly ExactTarget).",
"main": "./lib/fuel-rest.js",
"scripts": {
"test": "grunt && ./node_modules/mocha/bin/mocha --reporter=spec test/specs/*.js"
"test": "grunt && node ./node_modules/mocha/bin/mocha --reporter=spec test/specs/*.js"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion test/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2014​, salesforce.com, inc.
* Copyright (c) 2015​, salesforce.com, inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
Expand Down
2 changes: 1 addition & 1 deletion test/mock-server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2014​, salesforce.com, inc.
* Copyright (c) 2015​, salesforce.com, inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
Expand Down
2 changes: 1 addition & 1 deletion test/sample-responses.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2014​, salesforce.com, inc.
* Copyright (c) 2015​, salesforce.com, inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
Expand Down
2 changes: 1 addition & 1 deletion test/specs/fn-apiRequest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2014​, salesforce.com, inc.
* Copyright (c) 2015​, salesforce.com, inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
Expand Down
2 changes: 1 addition & 1 deletion test/specs/fn-http-methods.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2014​, salesforce.com, inc.
* Copyright (c) 2015​, salesforce.com, inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
Expand Down
2 changes: 1 addition & 1 deletion test/specs/general-tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2014​, salesforce.com, inc.
* Copyright (c) 2015​, salesforce.com, inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
Expand Down
2 changes: 1 addition & 1 deletion test/specs/helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2014​, salesforce.com, inc.
* Copyright (c) 2015​, salesforce.com, inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
Expand Down