Service.prototype.options = function(parse,handle){ var req = new request.Request('OPTIONS', this.target) applyOptions.call(this,req); req.end( function(res){ handle(res); parse(res); } ); }
_.defer(function () { request.end(function (response) { if (response.ok) { pending.resolve(response); } else { pending.reject(response); } }); });
function TwAgent(method, path) { var url = path.indexOf('http') === 0 ? path : path[0] === '/' ? rootUrl + path : rootUrl + '/' + path; Request.call(this, method, url); this._oauthParams = {}; this._params = {}; this.oauth('signature_method', 'HMAC-SHA1'); this.oauth('version', '1.0' ); }
Ajax = function (url, options) { var pending = Promise.pending(), promise = pending.promise, method = options.method, request = new Request(method, url), headers = options.headers, data = options.data, header; if (headers != null) { for (header in headers) { if (headers.hasOwnProperty(header)) { request.set(header, headers[header]); } } } if (data != null) { if (method === 'POST' || method === 'PUT' || method === 'PATCH') { request.send(data); } else { request.query(data); } } promise.request = request; _.defer(function () { request.end(function (response) { if (response.ok) { pending.resolve(response); } else { pending.reject(response); } }); }); return pending.promise; };
/** * Request object similar to superagent.Request, but with end() returning * a promise. */ function PromiseRequest() { superagent.Request.apply(this, arguments); }