Comparing version 0.2.0 to 0.2.1
@@ -13,2 +13,3 @@ var _ = require('lodash'); | ||
password: null, | ||
passwordHash: null, | ||
wsdl: 'https://webapi.allegro.pl/service.php?wsdl', | ||
@@ -19,3 +20,3 @@ countryId: Country.POLAND | ||
var _validateOptions = function (options) { | ||
if (_.isUndefined(options)) { | ||
if (!options) { | ||
options = {}; | ||
@@ -38,4 +39,4 @@ } | ||
if (!options.password) { | ||
throw new Error('No password provided'); | ||
if (!options.password && !options.passwordHash) { | ||
throw new Error('No password or password hash provided'); | ||
} | ||
@@ -51,3 +52,3 @@ | ||
} catch (e) { | ||
return e; | ||
return callback(e); | ||
} | ||
@@ -64,3 +65,4 @@ | ||
'login': options.login, | ||
'password': options.password | ||
'password': options.password, | ||
'passwordHash': options.passwordHash | ||
})); | ||
@@ -67,0 +69,0 @@ } |
@@ -23,5 +23,8 @@ (function () { | ||
this._login = options.login; | ||
this._passwordHash = hasher.generatePasswordHash(options.password); | ||
this._countryId = options.countryId; | ||
this._localVersion = '1378200949'; | ||
if (options.password) { | ||
this._passwordHash = hasher.generatePasswordHash(options.password); | ||
} else { | ||
this._passwordHash = options.passwordHash; | ||
} | ||
@@ -36,11 +39,19 @@ var sessionHandle = null; | ||
} else { | ||
self._soapClient.doLoginEnc({ | ||
'userLogin': self._login, | ||
'userHashPassword': self._passwordHash, | ||
'countryCode': self._countryId, | ||
'webapiKey': self._key, | ||
'localVersion': self._localVersion | ||
self._soapClient.doQuerySysStatus({ | ||
'sysvar': 3, | ||
'countryId': self._countryId, | ||
'webapiKey': self._key | ||
}, function (err, result) { | ||
sessionHandle = result.sessionHandlePart; | ||
callback(err, result); | ||
if (!err) { | ||
self._soapClient.doLoginEnc({ | ||
'userLogin': self._login, | ||
'userHashPassword': self._passwordHash, | ||
'countryCode': self._countryId, | ||
'webapiKey': self._key, | ||
'localVersion': result.verKey | ||
}, function (err, result) { | ||
sessionHandle = result.sessionHandlePart; | ||
callback(err, result); | ||
}); | ||
} | ||
}); | ||
@@ -47,0 +58,0 @@ } |
{ | ||
"name": "allegro", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Allegro.pl WebAPI client", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
# allegro.js | ||
Allegro.pl [WebAPI](http://allegro.pl/webapi/) client for Node.js. | ||
[![Build Status](https://travis-ci.org/mthenw/allegro.js.png)](https://travis-ci.org/mthenw/allegro.js) | ||
[![Build Status](https://travis-ci.org/mthenw/allegro.js.png)](https://travis-ci.org/mthenw/allegro.js) [![NPM version](https://badge.fury.io/js/allegro.png)](http://badge.fury.io/js/allegro) | ||
@@ -23,3 +24,3 @@ # Installation | ||
# Documentation | ||
# API | ||
@@ -34,17 +35,21 @@ ## allegro | ||
* ```countryId``` - country code, default: 1 (Poland) | ||
* ```login``` - user login, credentials are needed to call some of methods (I don't know why but even for those not related to My Allegro) so, in most cases you should provide them, | ||
* ```password``` - user password. | ||
* ```login```, ```passwords``` - credentials are needed to call some of methods (I don't know why but even for those not related to My Allegro) so, in most cases you should provide them. ```password``` can be replaced with ```passwordHash``` which is encoded in base64 sha-256 hash from password (base64(sha256(password))). | ||
```callback``` gets two arguments: | ||
Callback function gets two arguments: | ||
* ```error``` - Error instance if error occured, | ||
* ```client``` - [Client](#client) instance | ||
* ```error``` - [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) instance if error occured, | ||
* ```client``` - [Client](#client) instance. | ||
#### Example | ||
Example: | ||
``` | ||
var allegro = require('allegro'); | ||
var key = 'your_webapi_key'; | ||
allegro.createClient({ key: 'your_webapi_key'}, function (error, client) { | ||
var options = { | ||
key: 'your_webapi_key', | ||
login: 'foo', | ||
password: 'bar' | ||
}; | ||
allegro.createClient(options, function (error, client) { | ||
... | ||
@@ -58,6 +63,4 @@ }); | ||
Get [Category](#category) instance by id and pass to callback. | ||
Get [Category](#category) instance. Example: | ||
#### Example | ||
``` | ||
@@ -74,6 +77,4 @@ allegro.createClient({ … }, function (error, client) { | ||
Get [Item](#item) instance by id and pass to callback. | ||
Get [Item](#item) instance. Example: | ||
#### Example | ||
``` | ||
@@ -90,6 +91,4 @@ allegro.createClient({ … }, function (error, client) { | ||
Get [User](#user) instance by id and pass to callback. | ||
Get [User](#user) instance. Example: | ||
#### Example | ||
``` | ||
@@ -104,7 +103,18 @@ allegro.createClient({ … }, function (error, client) { | ||
### Events | ||
* **buynow** (itemId) - item is bought by 'Buy Now'. Example: | ||
``` | ||
client.on('buynow', function (itemId) { | ||
console.log('Getting item:' + itemId | ||
}); | ||
``` | ||
## Category | ||
### Proporties: | ||
Returned by [```client.getCategory```](#getcategorycategoryid-callback). | ||
### Proporties | ||
* ```id``` int, | ||
@@ -115,10 +125,12 @@ * ```name``` string. | ||
### Proporties: | ||
Returned by [```client.getItem```](#getitemitemid-callback). | ||
### Proporties | ||
* ```id``` int, | ||
* ```name``` string. | ||
### Methods: | ||
### Methods | ||
* ```getSeller(callback)``` get [User](#user) instance of seller. ```callback``` gets error and [User](#user) instance. Example: | ||
* ```getSeller(callback)``` get [User](#user) instance of seller. Callback function gets [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) and [User](#user) instance. Example: | ||
@@ -135,8 +147,8 @@ ``` | ||
## User | ||
Returned by [```client.getUser```](#getuseruserid-callback). | ||
## User | ||
### Proporties | ||
### Proporties: | ||
* ```id``` int, | ||
@@ -143,0 +155,0 @@ * ```login``` string, |
@@ -8,28 +8,43 @@ require('should'); | ||
it('should return an error if no api key provided for creating client', function () { | ||
it('should create client instance', function (done) { | ||
allegro.createClient({ | ||
key: 'key', | ||
login: 'login', | ||
password: 'password', | ||
wsdl: __dirname + '/webapi.wsdl' | ||
}, function (err, client) { | ||
client.should.be.an.instanceOf(Client); | ||
done(); | ||
}); | ||
}); | ||
it('should create client instance if password hash provided', function (done) { | ||
allegro.createClient({ | ||
key: 'key', | ||
login: 'login', | ||
passwordHash: 'passwordHash', | ||
wsdl: __dirname + '/webapi.wsdl' | ||
}, function (err, client) { | ||
client.should.be.an.instanceOf(Client); | ||
done(); | ||
}); | ||
}); | ||
it('should return an error if no api key provided for creating client', function (done) { | ||
allegro.createClient(null, function (err) { | ||
err.should.be.an.instanceOf(Error); | ||
done(); | ||
}); | ||
}); | ||
it('should return an error if no login provided for creating client', function () { | ||
it('should return an error if no login provided for creating client', function (done) { | ||
allegro.createClient({key: 'key'}, function (err) { | ||
err.should.be.an.instanceOf(Error); | ||
done(); | ||
}); | ||
}); | ||
it('should return an error if no password provided for creating client', function () { | ||
it('should return an error if no password provided for creating client', function (done) { | ||
allegro.createClient({key: 'key', login: 'login'}, function (err) { | ||
err.should.be.an.instanceOf(Error); | ||
}); | ||
}); | ||
it('should create client instance', function (done) { | ||
allegro.createClient({ | ||
key: 'key', | ||
login: 'login', | ||
password: 'password', | ||
wsdl: __dirname + '/webapi.wsdl' | ||
}, function (err, client) { | ||
client.should.be.an.instanceOf(Client); | ||
done(); | ||
@@ -39,7 +54,8 @@ }); | ||
it('should return an error when creating soap client failed', function () { | ||
it('should return an error when creating soap client failed', function (done) { | ||
allegro.createClient({key: 'key', wsdl: 'dontexists'}, function (err) { | ||
err.should.be.an.instanceOf(Error); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -34,8 +34,4 @@ require('should'); | ||
soap.createClient(__dirname + '/webapi.wsdl', function (err, soapClient) { | ||
var doLoginEncStub = sinon.stub(soapClient, 'doLoginEnc'); | ||
doLoginEncStub.callsArgWith(1, null, { | ||
'sessionHandlePart': 'session1', | ||
'userId': 1 | ||
}); | ||
_getDoQuerySysStatusStub(soapClient); | ||
var doLoginEncStub = _getDoLoginEncStub(soapClient); | ||
var doShowItemInfoExtStub = sinon.stub(soapClient, 'doShowItemInfoExt'); | ||
@@ -64,3 +60,3 @@ doShowItemInfoExtStub.callsArgWith(1, null, { | ||
webapiKey: 'key', | ||
localVersion: '1378200949' | ||
localVersion: 123456 | ||
}).should.equal(true); | ||
@@ -74,8 +70,4 @@ done(); | ||
soap.createClient(__dirname + '/webapi.wsdl', function (err, soapClient) { | ||
var doLoginEncStub = sinon.stub(soapClient, 'doLoginEnc'); | ||
doLoginEncStub.callsArgWith(1, null, { | ||
sessionHandlePart: 'session1', | ||
userId: 100 | ||
}); | ||
_getDoQuerySysStatusStub(soapClient); | ||
_getDoLoginEncStub(soapClient); | ||
var doShowItemInfoExtStub = sinon.stub(soapClient, 'doShowItemInfoExt'); | ||
@@ -110,8 +102,4 @@ doShowItemInfoExtStub.callsArgWith(1, null, { | ||
soap.createClient(__dirname + '/webapi.wsdl', function (err, soapClient) { | ||
var doLoginEncStub = sinon.stub(soapClient, 'doLoginEnc'); | ||
doLoginEncStub.callsArgWith(1, null, { | ||
'sessionHandlePart': 'session1', | ||
'userId': 1 | ||
}); | ||
_getDoQuerySysStatusStub(soapClient); | ||
var doLoginEncStub = _getDoLoginEncStub(soapClient); | ||
var doGetCategoryPathStub = sinon.stub(soapClient, 'doGetCategoryPath'); | ||
@@ -141,3 +129,3 @@ doGetCategoryPathStub.callsArgWith(1, null, { | ||
webapiKey: 'key', | ||
localVersion: '1378200949' | ||
localVersion: 123456 | ||
}).should.equal(true); | ||
@@ -151,8 +139,4 @@ done(); | ||
soap.createClient(__dirname + '/webapi.wsdl', function (err, soapClient) { | ||
var doLoginEncStub = sinon.stub(soapClient, 'doLoginEnc'); | ||
doLoginEncStub.callsArgWith(1, null, { | ||
'sessionHandlePart': 'session1', | ||
'userId': 1 | ||
}); | ||
_getDoQuerySysStatusStub(soapClient); | ||
_getDoLoginEncStub(soapClient); | ||
var doGetCategoryPathStub = sinon.stub(soapClient, 'doGetCategoryPath'); | ||
@@ -189,8 +173,4 @@ doGetCategoryPathStub.callsArgWith(1, null, { | ||
soap.createClient(__dirname + '/webapi.wsdl', function (err, soapClient) { | ||
var doLoginEncStub = sinon.stub(soapClient, 'doLoginEnc'); | ||
doLoginEncStub.callsArgWith(1, null, { | ||
'sessionHandlePart': 'session1', | ||
'userId': 1 | ||
}); | ||
_getDoQuerySysStatusStub(soapClient); | ||
_getDoLoginEncStub(soapClient); | ||
var doGetSiteJournalStub = sinon.stub(soapClient, 'doGetSiteJournal'); | ||
@@ -234,8 +214,4 @@ doGetSiteJournalStub.callsArgWith(1, null, { | ||
soap.createClient(__dirname + '/webapi.wsdl', function (err, soapClient) { | ||
var doLoginEncStub = sinon.stub(soapClient, 'doLoginEnc'); | ||
doLoginEncStub.callsArgWith(1, null, { | ||
'sessionHandlePart': 'session1', | ||
'userId': 1 | ||
}); | ||
_getDoQuerySysStatusStub(soapClient); | ||
var doLoginEncStub = _getDoLoginEncStub(soapClient); | ||
var doShowItemInfoExtStub = sinon.stub(soapClient, 'doShowItemInfoExt'); | ||
@@ -260,2 +236,77 @@ doShowItemInfoExtStub.callsArgWith(1, null, {itemListInfoExt: {itId: 1, itName: 'Item'}}); | ||
}); | ||
it('should login with password hash', function (done) { | ||
soap.createClient(__dirname + '/webapi.wsdl', function (err, soapClient) { | ||
_getDoQuerySysStatusStub(soapClient); | ||
var doLoginEncStub = _getDoLoginEncStub(soapClient); | ||
var doShowItemInfoExtStub = sinon.stub(soapClient, 'doShowItemInfoExt'); | ||
doShowItemInfoExtStub.callsArgWith(1, null, {itemListInfoExt: {itId: 1, itName: 'Item'}}); | ||
var client = new Client({ | ||
soapClient: soapClient, | ||
key: 'key', | ||
countryId: 1, | ||
login: 'testuser', | ||
passwordHash: 'passwordHash' | ||
}); | ||
client.getItem(1, function () { | ||
doLoginEncStub.calledWith({ | ||
userLogin: 'testuser', | ||
userHashPassword: 'passwordHash', | ||
countryCode: 1, | ||
webapiKey: 'key', | ||
localVersion: 123456 | ||
}).should.equal(true); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('should get sys status before login', function (done) { | ||
soap.createClient(__dirname + '/webapi.wsdl', function (err, soapClient) { | ||
var doQuerySysStatusStub = _getDoQuerySysStatusStub(soapClient); | ||
var doLoginEncStub = _getDoLoginEncStub(soapClient); | ||
var doShowItemInfoExtStub = sinon.stub(soapClient, 'doShowItemInfoExt'); | ||
doShowItemInfoExtStub.callsArgWith(1, null, {itemListInfoExt: {itId: 1, itName: 'Item'}}); | ||
var client = new Client({ | ||
soapClient: soapClient, | ||
key: 'key', | ||
countryId: 1, | ||
login: 'testuser', | ||
passwordHash: 'passwordHash' | ||
}); | ||
client.getItem(1, function () { | ||
doQuerySysStatusStub.calledOnce.should.be.equal(true); | ||
doLoginEncStub.calledWith({ | ||
userLogin: 'testuser', | ||
userHashPassword: 'passwordHash', | ||
countryCode: 1, | ||
webapiKey: 'key', | ||
localVersion: 123456 | ||
}).should.equal(true); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
var _getDoQuerySysStatusStub = function (soapClient) { | ||
var doQuerySysStatusStub = sinon.stub(soapClient, 'doQuerySysStatus'); | ||
doQuerySysStatusStub.callsArgWith(1, null, { | ||
info: '1.0.0', | ||
verKey: 123456 | ||
}); | ||
return doQuerySysStatusStub; | ||
}; | ||
var _getDoLoginEncStub = function (soapClient) { | ||
var doLoginEncStub = sinon.stub(soapClient, 'doLoginEnc'); | ||
doLoginEncStub.callsArgWith(1, null, { | ||
'sessionHandlePart': 'session1', | ||
'userId': 1 | ||
}); | ||
return doLoginEncStub; | ||
}; | ||
}); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
276522
675
151
0