node-easypost
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -84,19 +84,19 @@ "use strict"; | ||
var request_options = { | ||
host: 'api.easypost.com', | ||
port: '443', | ||
// host: 'localhost', | ||
// port: '5000', | ||
path: path, | ||
method: method, | ||
headers: { | ||
'Authorization': auth, | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
'Content-Length': requestData.length | ||
} | ||
}; | ||
host: 'api.easypost.com', | ||
port: '443', | ||
// host: 'localhost', | ||
// port: '5000', | ||
path: path, | ||
method: method, | ||
headers: { | ||
'Authorization': auth, | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
'Content-Length': requestData.length | ||
} | ||
}; | ||
var req = https.request(request_options); | ||
// var req = http.request(request_options); | ||
this.responseListener(req, callback); | ||
this.responseListener(req, callback); | ||
req.write(requestData); | ||
@@ -263,2 +263,16 @@ req.end(); | ||
easypost.Address.prototype.constructor = easypost.Address; | ||
easypost.Address.create_and_verify = function(params, cb) { | ||
var args = normalizeArgs(arguments); | ||
var url = easypost.Resource.classUrl('address') + '/create_and_verify'; | ||
if (args.params['address'] === undefined || args.params['address'] === null) { | ||
var temp = args.params; | ||
args.params = {}; | ||
args.params['address'] = temp; | ||
} | ||
var requestor = new Requestor(args.params.apiKey); | ||
requestor.request('post', url, args.params, args.cb); | ||
} | ||
easypost.Address.prototype.verify = function(params, cb) { | ||
@@ -332,2 +346,16 @@ var args = normalizeArgs(arguments); | ||
} | ||
easypost.Shipment.prototype.label = function(params, cb) { | ||
var args = normalizeArgs(arguments); | ||
var url = this.instanceUrl() + '/label'; | ||
var requestor = new Requestor(this.apiKey); | ||
requestor.request('get', url, args.params, args.cb); | ||
} | ||
easypost.Shipment.prototype.insure = function(params, cb) { | ||
var args = normalizeArgs(arguments); | ||
var url = this.instanceUrl() + '/insure'; | ||
var requestor = new Requestor(this.apiKey); | ||
requestor.request('post', url, args.params, args.cb); | ||
} | ||
easypost.Shipment.prototype.lowestRate = function(carriers, services) { | ||
@@ -409,8 +437,8 @@ carriers = null; | ||
var url = easypost.Resource.classUrl('batch'); | ||
var url = easypost.Resource.classUrl('batch') + '/create_and_buy'; | ||
if (args.params[cls] === undefined || args.params[cls] === null) { | ||
if (args.params['batch'] === undefined || args.params['batch'] === null) { | ||
var temp = args.params; | ||
args.params = {}; | ||
args.params[cls] = temp; | ||
args.params['batch'] = temp; | ||
} | ||
@@ -417,0 +445,0 @@ |
{ | ||
"name": "node-easypost", | ||
"description": "EasyPost Node Client Library", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"author": "Sawyer Bateman <contact@easypost.com>", | ||
@@ -6,0 +6,0 @@ "homepage": "https://easypost.com", |
@@ -16,23 +16,13 @@ var vows = require('vows'), | ||
'Address': { | ||
topic: function() { | ||
easypost.Address.create({ | ||
name: 'Jon Calhoun', | ||
street1: '388 Townsend St.', | ||
city: 'San Francisco', | ||
state: 'CA', | ||
zip: '94107', | ||
country: 'US'}, this.callback); | ||
}, | ||
'should return an address' : function(err, response) { | ||
assert.isNull(err); | ||
assert.isDefined(response); | ||
assert.equal(response.object, 'Address'); | ||
assert.isDefined(response.id); | ||
assert.instanceOf(response, easypost.Address); | ||
}, | ||
'should be retrieveable' : { | ||
topic: function(err, response) { | ||
easypost.Address.retrieve(response.id, this.callback); | ||
'standard create': { | ||
topic: function() { | ||
easypost.Address.create({ | ||
name: 'Jon Calhoun', | ||
street1: '388 Townsend St.', | ||
city: 'San Francisco', | ||
state: 'CA', | ||
zip: '94107', | ||
country: 'US'}, this.callback); | ||
}, | ||
'retrieved object is an address': function(err, response) { | ||
'should return an address' : function(err, response) { | ||
assert.isNull(err); | ||
@@ -43,13 +33,46 @@ assert.isDefined(response); | ||
assert.instanceOf(response, easypost.Address); | ||
}, | ||
'should be retrieveable' : { | ||
topic: function(err, response) { | ||
easypost.Address.retrieve(response.id, this.callback); | ||
}, | ||
'retrieved object is an address': function(err, response) { | ||
assert.isNull(err); | ||
assert.isDefined(response); | ||
assert.equal(response.object, 'Address'); | ||
assert.isDefined(response.id); | ||
assert.instanceOf(response, easypost.Address); | ||
} | ||
}, | ||
'should be verifyable': { | ||
topic: function(err, response) { | ||
response.verify(this.callback); | ||
}, | ||
'should return an address and a message': function(err, response) { | ||
assert.isNull(err); | ||
assert.isDefined(response); | ||
assert.isDefined(response.address); | ||
assert.isDefined(response.message); | ||
assert.equal(response.address.object, 'Address'); | ||
} | ||
} | ||
}, | ||
'should be verifyable': { | ||
topic: function(err, response) { | ||
response.verify(this.callback); | ||
'create and verify': { | ||
topic: function() { | ||
try { | ||
easypost.Address.create_and_verify({ | ||
name: 'Jon Calhoun', | ||
street1: '388 Townsend St.', | ||
city: 'San Francisco', | ||
state: 'CA', | ||
zip: '94107', | ||
country: 'US'}, this.callback); | ||
} catch(e) { | ||
console.log(e); | ||
} | ||
}, | ||
'should return an address and a message': function(err, response) { | ||
'should return a verified address with message': function(err, response) { | ||
assert.isNull(err); | ||
assert.isDefined(response); | ||
assert.isDefined(response.address); | ||
assert.isDefined(response.message); | ||
assert.isDefined(response.message) | ||
assert.equal(response.address.object, 'Address'); | ||
@@ -80,3 +103,4 @@ } | ||
zip: '94107', | ||
country: 'US' | ||
country: 'US', | ||
phone: '415-456-7890' | ||
}; | ||
@@ -117,3 +141,2 @@ var parcel = { | ||
'shipment is valid and contains international rates': function(err, response) { | ||
console.log(response); | ||
assert.isNull(err); | ||
@@ -123,2 +146,15 @@ assert.isDefined(response); | ||
assert.instanceOf(response.rates, Array); | ||
}, | ||
'buy shipment with insurance': { | ||
topic: function(err, response) { | ||
response.buy({rate: response.lowestRate(), insurance: 249.99}, this.callback); | ||
}, | ||
'purchase with insurance successful': function(err, response) { | ||
assert.isNull(err); | ||
assert.isDefined(response.postage_label); | ||
assert.isDefined(response.postage_label.label_url); | ||
assert.isDefined(response.insurance); | ||
assert.isDefined(response.tracking_code); | ||
assert.equal(response.insurance, '249.99'); | ||
} | ||
} | ||
@@ -125,0 +161,0 @@ } |
Sorry, the diff of this file is not supported yet
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
32621
659