Comparing version 0.0.1 to 0.1.1
42
index.js
@@ -19,4 +19,5 @@ 'use strict'; | ||
this.token = opts.token; | ||
this.requestUrl = this.apiUrl; | ||
this.requestBody = ''; | ||
this.result = null; | ||
@@ -66,3 +67,8 @@ this.rawResult = null; | ||
// Fire off the request to Stuller | ||
this.request(this.requestUrl, function(err, res, body) { | ||
this.request({ | ||
method: 'POST', | ||
url: that.requestUrl, | ||
body: that.requestBody, | ||
headers: { 'Content-Type': 'application/x-www-form-urlencoded'} | ||
}, function(err, res, body) { | ||
if (err) { | ||
@@ -83,3 +89,3 @@ console.log(err); | ||
StullerApi.prototype.addToken = function(callback) { | ||
this.requestUrl += '&DeveloperToken=' + this.stullerDeveloperToken; | ||
this.requestBody += '&DeveloperToken=' + this.stullerDeveloperToken; | ||
return this; | ||
@@ -92,3 +98,3 @@ }; | ||
StullerApi.prototype.isDevTokenSet = function() { | ||
return (/DeveloperToken/).test(this.requestUrl); | ||
return (/DeveloperToken/).test(this.requestBody); | ||
}; | ||
@@ -110,3 +116,3 @@ | ||
this.requestUrl += this.getQuery('ItemNumbers', numbers); | ||
this.requestBody += this.getQuery('ItemNumbers', numbers); | ||
@@ -131,3 +137,3 @@ return this; | ||
this.requestUrl += this.getQuery('ItemIDs', ids); | ||
this.requestBody += this.getQuery('ItemIDs', ids); | ||
@@ -146,3 +152,3 @@ return this; | ||
StullerApi.prototype.FetchItemInfoBySeries = function(ids) { | ||
this.format = this.formatArrayOfItem; | ||
@@ -153,3 +159,3 @@ | ||
this.requestUrl += this.getQuery('SeriesNumbers', ids); | ||
this.requestBody += this.getQuery('SeriesNumbers', ids); | ||
@@ -173,3 +179,3 @@ return this; | ||
this.requestUrl += this.getQuery('Items', numbers); | ||
this.requestBody += this.getQuery('Items', numbers); | ||
@@ -193,3 +199,3 @@ return this; | ||
this.requestUrl += this.getQuery('Items', ids); | ||
this.requestBody += this.getQuery('Items', ids); | ||
@@ -207,3 +213,3 @@ return this; | ||
StullerApi.prototype.FetchItemPriceOnHandBySeries = function(ids) { | ||
this.format = this.formatArrayItemPriceOnHand; | ||
@@ -214,3 +220,3 @@ | ||
this.requestUrl += this.getQuery('Items', ids); | ||
this.requestBody += this.getQuery('Items', ids); | ||
@@ -256,3 +262,3 @@ return this; | ||
// We want it to return ItemIDs | ||
this.requestUrl += ('type=' + type); | ||
this.requestBody += ('type=' + type); | ||
@@ -331,3 +337,3 @@ return this; | ||
StullerApi.prototype.formatArrayOfItemIdentifier = function(data) { | ||
var results = []; | ||
@@ -367,3 +373,3 @@ | ||
var item = {}; | ||
item.ItemNumber = String(items[i].ItemNumber); | ||
@@ -419,6 +425,6 @@ item.ItemID = Number(items[i].ItemID); | ||
item.Uom = String(items[i].Uom); | ||
// Grab the images from array | ||
item.Images = []; | ||
var images = items[i].Images['ItemImage'] || []; | ||
@@ -453,3 +459,3 @@ | ||
} | ||
results.push(item); | ||
@@ -456,0 +462,0 @@ } |
{ | ||
"name": "stuller", | ||
"version": "0.0.1", | ||
"version": "0.1.1", | ||
"description": "Interact with the Stuller API. Converts from XML to json", | ||
@@ -16,9 +16,13 @@ "main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/shanestillwell/stuller" | ||
"type": "git", | ||
"url": "https://github.com/shanestillwell/stuller" | ||
}, | ||
"devDependencies": { | ||
"chai": "~1.7.2", | ||
"mocha": "~1.9.0" | ||
"mocha": "~1.9.0", | ||
"grunt-bump": "0.0.13", | ||
"load-grunt-tasks": "~0.2.1", | ||
"grunt-contrib-watch": "~0.5.3", | ||
"grunt": "~0.4.2" | ||
} | ||
} |
@@ -49,3 +49,3 @@ 'use strict'; | ||
api.FetchItemInfo('123ABC'); | ||
expect(api.requestUrl).to.contain('123ABC'); | ||
expect(api.requestBody).to.contain('123ABC'); | ||
}); | ||
@@ -55,5 +55,5 @@ it('should accept an array', function() { | ||
api.FetchItemInfo(['FOO', 'BAR', 'F14.5:166316:P']); | ||
expect(api.requestUrl).to.contain('FOO'); | ||
expect(api.requestUrl).to.contain('BAR'); | ||
}); | ||
expect(api.requestBody).to.contain('FOO'); | ||
expect(api.requestBody).to.contain('BAR'); | ||
}); | ||
@@ -72,5 +72,5 @@ it('should correctly parse response', function(done) { | ||
}); | ||
}); | ||
@@ -82,3 +82,3 @@ | ||
api.FetchItemInfoByItemID('123'); | ||
expect(api.requestUrl).to.contain('123'); | ||
expect(api.requestBody).to.contain('123'); | ||
}); | ||
@@ -88,5 +88,5 @@ it('should accept an array', function() { | ||
api.FetchItemInfoByItemID(['123', '444', '21048']); | ||
expect(api.requestUrl).to.contain('123'); | ||
expect(api.requestUrl).to.contain('444'); | ||
}); | ||
expect(api.requestBody).to.contain('123'); | ||
expect(api.requestBody).to.contain('444'); | ||
}); | ||
@@ -112,3 +112,3 @@ it('should correctly parse response', function(done) { | ||
api.FetchItemInfoByItemID('123'); | ||
expect(api.requestUrl).to.contain('123'); | ||
expect(api.requestBody).to.contain('123'); | ||
}); | ||
@@ -118,5 +118,5 @@ it('should accept an array', function() { | ||
api.FetchItemInfoBySeries(['123', '444', '21048']); | ||
expect(api.requestUrl).to.contain('123'); | ||
expect(api.requestUrl).to.contain('444'); | ||
}); | ||
expect(api.requestBody).to.contain('123'); | ||
expect(api.requestBody).to.contain('444'); | ||
}); | ||
@@ -142,3 +142,3 @@ it('should correctly parse response', function(done) { | ||
api.FetchItemPriceOnHand('123'); | ||
expect(api.requestUrl).to.contain('123'); | ||
expect(api.requestBody).to.contain('123'); | ||
}); | ||
@@ -148,5 +148,5 @@ it('should accept an array', function() { | ||
api.FetchItemPriceOnHand(['123', '444', '21048']); | ||
expect(api.requestUrl).to.contain('123'); | ||
expect(api.requestUrl).to.contain('444'); | ||
}); | ||
expect(api.requestBody).to.contain('123'); | ||
expect(api.requestBody).to.contain('444'); | ||
}); | ||
@@ -171,3 +171,3 @@ it('should correctly parse response', function(done) { | ||
api.FetchItemPriceOnHandByItemID('123'); | ||
expect(api.requestUrl).to.contain('123'); | ||
expect(api.requestBody).to.contain('123'); | ||
}); | ||
@@ -177,5 +177,5 @@ it('should accept an array', function() { | ||
api.FetchItemPriceOnHandByItemID(['123', '444', '21048']); | ||
expect(api.requestUrl).to.contain('123'); | ||
expect(api.requestUrl).to.contain('444'); | ||
}); | ||
expect(api.requestBody).to.contain('123'); | ||
expect(api.requestBody).to.contain('444'); | ||
}); | ||
@@ -200,3 +200,3 @@ it('should correctly parse response', function(done) { | ||
api.FetchItemPriceOnHand('123'); | ||
expect(api.requestUrl).to.contain('123'); | ||
expect(api.requestBody).to.contain('123'); | ||
}); | ||
@@ -206,5 +206,5 @@ it('should accept an array', function() { | ||
api.FetchItemPriceOnHandBySeries(['123', '444', '21048']); | ||
expect(api.requestUrl).to.contain('123'); | ||
expect(api.requestUrl).to.contain('444'); | ||
}); | ||
expect(api.requestBody).to.contain('123'); | ||
expect(api.requestBody).to.contain('444'); | ||
}); | ||
@@ -256,3 +256,3 @@ it('should correctly parse response', function(done) { | ||
}); | ||
describe('addToken', function() { | ||
@@ -262,3 +262,3 @@ it('should add the developers token to the url', function() { | ||
api.addToken(); | ||
expect(api.requestUrl).to.contain('DeveloperToken='); | ||
expect(api.requestBody).to.contain('DeveloperToken='); | ||
}); | ||
@@ -282,4 +282,6 @@ }); | ||
// Stubbing request | ||
function request(url, callback) { | ||
function request(options, callback) { | ||
var url = options.url; | ||
var file = __dirname + '/fixtures/'; | ||
@@ -286,0 +288,0 @@ |
28598
11
618
6