jsforce
Version:
Salesforce API Library for JavaScript
134 lines (123 loc) • 4.22 kB
JavaScript
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self);var f=o;f=f.jsforce||(f.jsforce={}),f=f.modules||(f.modules={}),f=f.api||(f.api={}),f.Apex=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/**
* @file Manages Salesforce Apex REST endpoint calls
* @author Shinichi Tomita <shinichi.tomita@gmail.com>
*/
/**
* API class for Apex REST endpoint call
*
* @class
* @param {Connection} conn Connection
*/
var Apex = function(conn) {
this._conn = conn;
};
/**
* @private
*/
Apex.prototype._baseUrl = function() {
return this._conn.instanceUrl + "/services/apexrest";
};
/**
* @private
*/
Apex.prototype._createRequestParams = function(method, path, body) {
var params = {
method: method,
url: this._baseUrl() + path
};
if (!/^(GET|DELETE)$/i.test(method)) {
params.headers = {
"Content-Type" : "application/json"
};
}
if (body) {
params.body = JSON.stringify(body);
}
return params;
};
/**
* Call Apex REST service in GET request
*
* @param {String} path - URL path to Apex REST service
* @param {Callback.<Object>} [callback] - Callback function
* @returns {Promise.<Object>}
*/
Apex.prototype.get = function(path, callback) {
return this._conn._request(this._createRequestParams('GET', path)).thenCall(callback);
};
/**
* Call Apex REST service in POST request
*
* @param {String} path - URL path to Apex REST service
* @param {Object} [body] - Request body
* @param {Callback.<Object>} [callback] - Callback function
* @returns {Promise.<Object>}
*/
Apex.prototype.post = function(path, body, callback) {
if (typeof body === 'function') {
callback = body;
body = undefined;
}
var params = this._createRequestParams('POST', path, body);
return this._conn._request(params).thenCall(callback);
};
/**
* Call Apex REST service in PUT request
*
* @param {String} path - URL path to Apex REST service
* @param {Object} [body] - Request body
* @param {Callback.<Object>} [callback] - Callback function
* @returns {Promise.<Object>}
*/
Apex.prototype.put = function(path, body, callback) {
if (typeof body === 'function') {
callback = body;
body = undefined;
}
var params = this._createRequestParams('PUT', path, body);
return this._conn._request(params).thenCall(callback);
};
/**
* Call Apex REST service in PATCH request
*
* @param {String} path - URL path to Apex REST service
* @param {Object} [body] - Request body
* @param {Callback.<Object>} [callback] - Callback function
* @returns {Promise.<Object>}
*/
Apex.prototype.patch = function(path, body, callback) {
if (typeof body === 'function') {
callback = body;
body = undefined;
}
var params = this._createRequestParams('PATCH', path, body);
return this._conn._request(params).thenCall(callback);
};
/**
* Synonym of Apex#delete()
*
* @method Apex#del
*
* @param {String} path - URL path to Apex REST service
* @param {Object} [body] - Request body
* @param {Callback.<Object>} [callback] - Callback function
* @returns {Promise.<Object>}
*/
/**
* Call Apex REST service in DELETE request
*
* @method Apex#delete
*
* @param {String} path - URL path to Apex REST service
* @param {Object} [body] - Request body
* @param {Callback.<Object>} [callback] - Callback function
* @returns {Promise.<Object>}
*/
Apex.prototype.del =
Apex.prototype["delete"] = function(path, callback) {
return this._conn._request(this._createRequestParams('DELETE', path)).thenCall(callback);
};
module.exports = Apex;
},{}]},{},[1])(1)
});