Comparing version 0.0.2 to 0.0.3
31
index.js
@@ -33,4 +33,4 @@ /** | ||
*/ | ||
Unirest = function (method, uri) { | ||
var unirest = function (uri, callback) { | ||
Unirest = function (method, uri, headers, body) { | ||
var unirest = function (uri, headers, body, callback) { | ||
var $this = { | ||
@@ -99,4 +99,6 @@ /** | ||
field: function (name, value) { | ||
if (is(name).a(Object)) for (var key in name) $this.attach(key, name[key]); | ||
else { | ||
if (is(name).a(Object)) { | ||
for (var key in name) | ||
$this.attach(key, name[key]); | ||
} else { | ||
$this._multipart.push({ | ||
@@ -120,4 +122,6 @@ name: name, | ||
attach: function (name, path) { | ||
if (is(name).a(Object)) for (var key in name) $this.attach(key, name[key]); | ||
else { | ||
if (is(name).a(Object)) { | ||
for (var key in name) | ||
$this.attach(key, name[key]); | ||
} else { | ||
$this._multipart.push({ | ||
@@ -164,3 +168,3 @@ name: name, | ||
for (var key in field) | ||
$this.header(field, value); | ||
$this.header(key, field[key]); | ||
@@ -429,3 +433,3 @@ return $this; | ||
// Keeping node happy | ||
stream.req = Request; | ||
stream.req = Request.req; | ||
@@ -448,3 +452,2 @@ // Make sure we emit prior to processing | ||
if (!decoder) return stream.emit('data', buffer); | ||
var string = decoder.write(buffer); | ||
@@ -521,3 +524,11 @@ if (string.length) stream.emit('data', string); | ||
} | ||
if (headers && typeof headers === 'function') | ||
callback = headers, headers = null; | ||
else if (body && typeof body === 'function') | ||
callback = body, body = null; | ||
if (headers) $this.set(headers); | ||
if (body) $this.send(body); | ||
return callback ? $this.end(callback) : $this; | ||
@@ -524,0 +535,0 @@ }; |
{ | ||
"name": "unirest", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Lightweight HTTP Request library.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
# Unirest for Node.js | ||
# Unirest for Node.js [![Build Status](https://travis-ci.org/Mashape/unirest-nodejs.png?branch=master)](https://travis-ci.org/Mashape/unirest-nodejs) | ||
@@ -586,15 +586,15 @@ Unirest is a set of lightweight HTTP libraries available in multiple languages. | ||
### Request.complete | ||
#### Request.complete | ||
**Alias** for `Request.end()` | ||
### Request.as.json | ||
#### Request.as.json | ||
**Alias** for `Request.end()` | ||
### Request.as.binary | ||
#### Request.as.binary | ||
**Alias** for `Request.end()` | ||
### Request.as.string | ||
#### Request.as.string | ||
@@ -651,2 +651,2 @@ **Alias** for `Request.end()` | ||
}); | ||
``` | ||
``` |
@@ -15,3 +15,3 @@ var should = require("should"); | ||
it('should correctly parse GZIPPED data.', function (done) { | ||
unirest.get('http://httpbin.org/gzip').end(function (response) { | ||
unirest.get('http://httpbin.org/gzip').set('Accept', 'gzip').end(function (response) { | ||
should(response.status).equal(200); | ||
@@ -32,3 +32,3 @@ should(response.body).have.type('object'); | ||
it('should correctly handle timeouts.', function (done) { | ||
unirest.get('http://httpbin.org/redirect/23').timeout(200).end(function (response) { | ||
unirest.get('http://httpbin.org/redirect/3').timeout(20).end(function (response) { | ||
response.error.should.exist; | ||
@@ -57,2 +57,10 @@ response.error.code.should.equal('ETIMEDOUT'); | ||
}); | ||
it('should be able to look like unirest-php', function (done) { | ||
unirest.get('http://httpbin.org/gzip', { 'Accept': 'gzip' }, 'Hello World', function (response) { | ||
should(response.status).equal(200); | ||
should(response.body).have.type('object'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -59,0 +67,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44516
8
766
651