Comparing version
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.10.0 | ||
// Generated by CoffeeScript 1.12.0 | ||
(function() { | ||
@@ -3,0 +3,0 @@ var api, slumber; |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.10.0 | ||
// Generated by CoffeeScript 1.12.0 | ||
(function() { | ||
@@ -3,0 +3,0 @@ var api, fs, slumber; |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.10.0 | ||
// Generated by CoffeeScript 1.12.0 | ||
(function() { | ||
@@ -3,0 +3,0 @@ var api, slumber; |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.10.0 | ||
// Generated by CoffeeScript 1.12.0 | ||
(function() { | ||
@@ -3,0 +3,0 @@ var api, slumber; |
@@ -1,5 +0,6 @@ | ||
// Generated by CoffeeScript 1.10.0 | ||
// Generated by CoffeeScript 1.12.0 | ||
(function() { | ||
var API, Serializer, append_slash, callable, debug, hasInsensitive, merge, querystring, ref, request, | ||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | ||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, | ||
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
@@ -18,3 +19,3 @@ querystring = require('querystring'); | ||
function _Class(base_url, opts1, fn) { | ||
var base, base1, base2, base3, base4; | ||
var base, base1, base2, base3, base4, base5; | ||
this.opts = opts1 != null ? opts1 : {}; | ||
@@ -45,11 +46,14 @@ if (fn == null) { | ||
} | ||
if ((base2 = this.opts).request_opts == null) { | ||
base2.request_opts = { | ||
if ((base2 = this.opts).http_client == null) { | ||
base2.http_client = 'request'; | ||
} | ||
if ((base3 = this.opts).request_opts == null) { | ||
base3.request_opts = { | ||
rejectUnauthorized: false | ||
}; | ||
} | ||
if ((base3 = this.opts).format == null) { | ||
base3.format = 'json'; | ||
if ((base4 = this.opts).format == null) { | ||
base4.format = 'json'; | ||
} | ||
this.serializer = (base4 = this.opts).serializer != null ? base4.serializer : base4.serializer = new Serializer(this.opts.format); | ||
this.serializer = (base5 = this.opts).serializer != null ? base5.serializer : base5.serializer = new Serializer(this.opts.format); | ||
if (this.opts.append_slash) { | ||
@@ -79,4 +83,4 @@ this.opts.base_url = append_slash(this.opts.base_url); | ||
_Class.prototype._try_to_serialize = function(response, body) { | ||
var content_type, e, error, stype; | ||
if (response.headers['content-type'] != null) { | ||
var content_type, e, stype; | ||
if ((response.headers != null) && (response.headers['content-type'] != null)) { | ||
content_type = response.headers['content-type'].split(';')[0].replace(/^\s*|\s*$/g, ''); | ||
@@ -95,3 +99,3 @@ try { | ||
_Class.prototype._construct_request = function(method, kwargs) { | ||
var base, defaultVersion, key, prop, ref1, ref2, request_options, value; | ||
var base, defaultVersion, key, prop, ref1, ref2, ref3, ref4, request_options, value, white_listed_headers; | ||
request_options = { | ||
@@ -132,3 +136,3 @@ url: this.base_url, | ||
} | ||
if (kwargs.formData != null) { | ||
if ((kwargs.formData != null) && method === 'POST') { | ||
request_options.formData = kwargs.formData; | ||
@@ -150,2 +154,12 @@ } | ||
} | ||
if (this.opts.http_client === 'xhr') { | ||
white_listed_headers = ['authorization', 'accept']; | ||
ref3 = request_options.headers; | ||
for (key in ref3) { | ||
value = ref3[key]; | ||
if (ref4 = key.toLowerCase(), indexOf.call(white_listed_headers, ref4) < 0) { | ||
delete request_options.headers[key]; | ||
} | ||
} | ||
} | ||
return request_options; | ||
@@ -158,3 +172,7 @@ }; | ||
debug("" + method, request_options.url); | ||
return req = request(request_options, fn); | ||
if (this.opts.http_client === 'xhr') { | ||
return req = require('browser-request')(request_options, fn); | ||
} else { | ||
return req = request(request_options, fn); | ||
} | ||
}; | ||
@@ -161,0 +179,0 @@ |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.10.0 | ||
// Generated by CoffeeScript 1.12.0 | ||
(function() { | ||
@@ -3,0 +3,0 @@ var API; |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.10.0 | ||
// Generated by CoffeeScript 1.12.0 | ||
(function() { | ||
@@ -101,3 +101,3 @@ var BaseSerializer, JsonSerializer, SERIALIZERS, YamlSerializer, debug, yamljs, | ||
SERIALIZERS.yaml = YamlSerializer; | ||
} catch (undefined) {} | ||
} catch (error) {} | ||
@@ -104,0 +104,0 @@ module.exports.Serializer = (function() { |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.10.0 | ||
// Generated by CoffeeScript 1.12.0 | ||
(function() { | ||
@@ -3,0 +3,0 @@ var debug, extend, |
{ | ||
"name": "slumber", | ||
"version": "0.10.1", | ||
"version": "0.11.0", | ||
"description": "Port of Python's slumber library -- A library that makes consuming a RESTful API easier and more convenient", | ||
@@ -21,2 +21,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"browser-request": "^0.3.3", | ||
"debug": "^2.2.0", | ||
@@ -23,0 +24,0 @@ "querystring": "^0.2.0", |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.10.0 | ||
// Generated by CoffeeScript 1.12.0 | ||
(function() { | ||
@@ -554,2 +554,14 @@ var CUSTOMERS, app, assert, base_url, bodyParser, express, freeport, querystring, slumber, url; | ||
describe('XHR', function() { | ||
return it('should throw since XMLHttpRequest is not defined', function() { | ||
var api; | ||
api = slumber.API(base_url, { | ||
http_client: 'xhr' | ||
}); | ||
return assert.throws((function() { | ||
return api('something').get(function() {}); | ||
}), /ReferenceError: XMLHttpRequest is not defined/); | ||
}); | ||
}); | ||
describe('Rare cases', function() { | ||
@@ -556,0 +568,0 @@ var api; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
75287
2.59%1213
2.45%5
25%+ Added
+ Added