superagent
Advanced tools
Comparing version 0.9.9 to 0.9.10
@@ -456,5 +456,5 @@ ;(function(){ | ||
* Default MIME type map. | ||
* | ||
* | ||
* superagent.types.xml = 'application/xml'; | ||
* | ||
* | ||
*/ | ||
@@ -472,7 +472,7 @@ | ||
* Default serialization map. | ||
* | ||
* | ||
* superagent.serialize['application/xml'] = function(obj){ | ||
* return 'generated xml here'; | ||
* }; | ||
* | ||
* | ||
*/ | ||
@@ -487,7 +487,7 @@ | ||
* Default parsers. | ||
* | ||
* | ||
* superagent.parse['application/xml'] = function(str){ | ||
* return { object parsed from str }; | ||
* }; | ||
* | ||
* | ||
*/ | ||
@@ -703,2 +703,16 @@ | ||
/** | ||
* Return an `Error` representative of this response. | ||
* | ||
* @return {Error} | ||
* @api public | ||
*/ | ||
Response.prototype.toError = function(){ | ||
var msg = 'got ' + this.status + ' response'; | ||
var err = new Error(msg); | ||
err.status = this.status; | ||
return err; | ||
}; | ||
/** | ||
* Expose `Response`. | ||
@@ -720,2 +734,3 @@ */ | ||
Emitter.call(this); | ||
this._query = this._query || []; | ||
this.method = method; | ||
@@ -794,3 +809,3 @@ this.url = url; | ||
* .end(callback); | ||
* | ||
* | ||
* request.post('/') | ||
@@ -812,15 +827,18 @@ * .type('application/xml') | ||
/** | ||
* Add `obj` to the query-string, later formatted | ||
* in `.end()`. | ||
* | ||
* @param {Object} obj | ||
* @return {Request} for chaining | ||
* @api public | ||
*/ | ||
* Add query-string `val`. | ||
* | ||
* Examples: | ||
* | ||
* request.get('/shoes') | ||
* .query('size=10') | ||
* .query({ color: 'blue' }) | ||
* | ||
* @param {Object|String} val | ||
* @return {Request} for chaining | ||
* @api public | ||
*/ | ||
Request.prototype.query = function(obj){ | ||
this._query = this._query || {}; | ||
for (var key in obj) { | ||
this._query[key] = obj[key]; | ||
} | ||
Request.prototype.query = function(val){ | ||
if ('string' != typeof val) val = serialize(val); | ||
this._query.push(val); | ||
return this; | ||
@@ -851,3 +869,3 @@ }; | ||
* .end(callback) | ||
* | ||
* | ||
* // auto json | ||
@@ -857,3 +875,3 @@ * request.post('/user') | ||
* .end(callback) | ||
* | ||
* | ||
* // manual x-www-form-urlencoded | ||
@@ -864,3 +882,3 @@ * request.post('/user') | ||
* .end(callback) | ||
* | ||
* | ||
* // auto x-www-form-urlencoded | ||
@@ -923,3 +941,3 @@ * request.post('/user') | ||
var xhr = this.xhr = getXHR(); | ||
var query = this._query; | ||
var query = this._query.join('&'); | ||
var data = this._data; | ||
@@ -1002,3 +1020,3 @@ | ||
* @param {String} url | ||
* @param {Mixed} data | ||
* @param {Mixed|Function} data or fn | ||
* @param {Function} fn | ||
@@ -1021,3 +1039,3 @@ * @return {Request} | ||
* @param {String} url | ||
* @param {Mixed} data | ||
* @param {Mixed|Function} data or fn | ||
* @param {Function} fn | ||
@@ -1063,2 +1081,3 @@ * @return {Request} | ||
var req = request('PATCH', url); | ||
if ('function' == typeof data) fn = data, data = null; | ||
if (data) req.send(data); | ||
@@ -1081,2 +1100,3 @@ if (fn) req.end(fn); | ||
var req = request('POST', url); | ||
if ('function' == typeof data) fn = data, data = null; | ||
if (data) req.send(data); | ||
@@ -1091,3 +1111,3 @@ if (fn) req.end(fn); | ||
* @param {String} url | ||
* @param {Mixed} data | ||
* @param {Mixed|Function} data or fn | ||
* @param {Function} fn | ||
@@ -1100,2 +1120,3 @@ * @return {Request} | ||
var req = request('PUT', url); | ||
if ('function' == typeof data) fn = data, data = null; | ||
if (data) req.send(data); | ||
@@ -1115,3 +1136,7 @@ if (fn) req.end(fn); | ||
require.alias("superagent/lib/client.js", "superagent/index.js"); | ||
window.superagent = require("superagent"); | ||
if ("undefined" == typeof module) { | ||
window.superagent = require("superagent"); | ||
} else { | ||
module.exports = require("superagent"); | ||
} | ||
})(); |
@@ -5,3 +5,3 @@ { | ||
"description": "awesome http requests", | ||
"version": "0.9.9", | ||
"version": "0.9.10", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "http", |
0.9.10 / 2012-11-14 | ||
================== | ||
* fix client-side .query(str) support | ||
0.9.9 / 2012-11-14 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -392,2 +392,3 @@ | ||
Emitter.call(this); | ||
this._query = this._query || []; | ||
this.method = method; | ||
@@ -483,15 +484,18 @@ this.url = url; | ||
/** | ||
* Add `obj` to the query-string, later formatted | ||
* in `.end()`. | ||
* | ||
* @param {Object} obj | ||
* @return {Request} for chaining | ||
* @api public | ||
*/ | ||
* Add query-string `val`. | ||
* | ||
* Examples: | ||
* | ||
* request.get('/shoes') | ||
* .query('size=10') | ||
* .query({ color: 'blue' }) | ||
* | ||
* @param {Object|String} val | ||
* @return {Request} for chaining | ||
* @api public | ||
*/ | ||
Request.prototype.query = function(obj){ | ||
this._query = this._query || {}; | ||
for (var key in obj) { | ||
this._query[key] = obj[key]; | ||
} | ||
Request.prototype.query = function(val){ | ||
if ('string' != typeof val) val = serialize(val); | ||
this._query.push(val); | ||
return this; | ||
@@ -591,3 +595,3 @@ }; | ||
var xhr = this.xhr = getXHR(); | ||
var query = this._query; | ||
var query = this._query.join('&'); | ||
var data = this._data; | ||
@@ -594,0 +598,0 @@ |
@@ -263,6 +263,11 @@ /*! | ||
/** | ||
* Add `obj` to the query-string, later formatted | ||
* in `.end()`. | ||
* Add query-string `val`. | ||
* | ||
* @param {Object} obj | ||
* Examples: | ||
* | ||
* request.get('/shoes') | ||
* .query('size=10') | ||
* .query({ color: 'blue' }) | ||
* | ||
* @param {Object|String} val | ||
* @return {Request} for chaining | ||
@@ -272,7 +277,7 @@ * @api public | ||
Request.prototype.query = function(obj){ | ||
Request.prototype.query = function(val){ | ||
var req = this.request(); | ||
var query = qs.stringify(obj); | ||
if (!query.length) return this; | ||
req.path += (~req.path.indexOf('?') ? '&' : '?') + query; | ||
if ('string' != typeof val) val = qs.stringify(val); | ||
if (!val.length) return this; | ||
req.path += (~req.path.indexOf('?') ? '&' : '?') + val; | ||
return this; | ||
@@ -279,0 +284,0 @@ }; |
{ | ||
"name": "superagent", | ||
"version": "0.9.9", | ||
"version": "0.9.10", | ||
"description": "elegant & feature rich browser / node HTTP with a fluent API", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
88486
23
2968