Skip to content
This repository has been archived by the owner on Jun 7, 2019. It is now read-only.

Commit

Permalink
Refactos API module for new API design
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Schwarz committed Aug 17, 2017
1 parent 1514b32 commit 23714f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 42 deletions.
29 changes: 9 additions & 20 deletions src/api/liskApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ LiskAPI.prototype.getStandbyDelegates = privateApi.wrapSendRequest(GET, 'delegat
* @return API object
*/

LiskAPI.prototype.searchDelegatesByUsername = privateApi.wrapSendRequest(GET, 'delegates/search', username => ({ username }));
LiskAPI.prototype.searchDelegatesByUsername = privateApi.wrapSendRequest(GET, 'delegates', search => ({ search }));

/**
* @method getBlocks
Expand Down Expand Up @@ -329,14 +329,14 @@ LiskAPI.prototype.getTransactions = privateApi.wrapSendRequest(GET, 'transaction

/**
* @method getTransaction
* @param id
* @param transactionId
* @param optionsOrCallback
* @param callbackIfOptions
*
* @return API object
*/

LiskAPI.prototype.getTransaction = privateApi.wrapSendRequest(GET, 'transactions/get', id => ({ id }));
LiskAPI.prototype.getTransaction = privateApi.wrapSendRequest(GET, 'transactions', transactionId => ({ transactionId }));

/**
* @method getVotes
Expand All @@ -347,40 +347,29 @@ LiskAPI.prototype.getTransaction = privateApi.wrapSendRequest(GET, 'transactions
* @return API object
*/

LiskAPI.prototype.getVotes = privateApi.wrapSendRequest(GET, 'accounts/delegates', address => ({ address }));
LiskAPI.prototype.getVotes = privateApi.wrapSendRequest(GET, 'votes', address => ({ address }));

/**
* @method getVoters
* @param publicKey
* @param username
* @param optionsOrCallback
* @param callbackIfOptions
*
* @return API object
*/

LiskAPI.prototype.getVoters = privateApi.wrapSendRequest(GET, 'delegates/voters', publicKey => ({ publicKey }));
LiskAPI.prototype.getVoters = privateApi.wrapSendRequest(GET, 'voters', username => ({ username }));

/**
* @method listMultisignatureTransactions
* @method getUnsignedMultisignatureTransactions
* @param data
* @param optionsOrCallback
* @param callbackIfOptions
*
* @return API object
*/

LiskAPI.prototype.getMultisignatureTransactions = privateApi.wrapSendRequest(GET, 'transactions/multisignatures', data => data);

/**
* @method getMultisignatureTransaction
* @param id
* @param optionsOrCallback
* @param callbackIfOptions
*
* @return API object
*/

LiskAPI.prototype.getMultisignatureTransaction = privateApi.wrapSendRequest(GET, 'transactions/multisignatures/get', id => ({ id }));
LiskAPI.prototype.getUnsignedMultisignatureTransactions = privateApi.wrapSendRequest(GET, 'transactions/unsigned', data => data);

/**
* @method sendLSK
Expand Down Expand Up @@ -412,7 +401,7 @@ LiskAPI.prototype.broadcastSignedTransaction = function broadcastSignedTransacti
) {
const request = {
requestMethod: POST,
requestUrl: `${privateApi.getFullUrl.call(this)}/peer/transactions`,
requestUrl: `${privateApi.getFullUrl.call(this)}/api/transactions`,
nethash: this.nethash,
requestParams: { transaction },
};
Expand Down
34 changes: 12 additions & 22 deletions test/api/liskApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ describe('Lisk.api()', () => {

describe('#searchDelegatesByUsername', () => {
it('should find delegates by name', () => {
const options = { username: 'oliver' };
const options = { search: 'oliver' };

LSK.searchDelegatesByUsername('oliver', callback);
(LSK.sendRequest.calledWithExactly(GET, 'delegates/search', options, callback)).should.be.true();
(LSK.sendRequest.calledWithExactly(GET, 'delegates', options, callback)).should.be.true();
});
});

Expand Down Expand Up @@ -330,11 +330,11 @@ describe('Lisk.api()', () => {
it('should get a defined transaction', () => {
const transactionId = '7520138931049441691';
const options = {
id: transactionId,
transactionId,
};

LSK.getTransaction(transactionId, callback);
(LSK.sendRequest.calledWithExactly(GET, 'transactions/get', options, callback)).should.be.true();
(LSK.sendRequest.calledWithExactly(GET, 'transactions', options, callback)).should.be.true();
});
});

Expand All @@ -346,19 +346,19 @@ describe('Lisk.api()', () => {
};

LSK.getVotes(address, callback);
(LSK.sendRequest.calledWithExactly(GET, 'accounts/delegates', options, callback)).should.be.true();
(LSK.sendRequest.calledWithExactly(GET, 'votes', options, callback)).should.be.true();
});
});

describe('#getVoters', () => {
it('should get voters of an account', () => {
const publicKey = '6a01c4b86f4519ec9fa5c3288ae20e2e7a58822ebe891fb81e839588b95b242a';
const username = 'lightcurve';
const options = {
publicKey,
username,
};

LSK.getVoters(publicKey, callback);
(LSK.sendRequest.calledWithExactly(GET, 'delegates/voters', options, callback)).should.be.true();
LSK.getVoters(username, callback);
(LSK.sendRequest.calledWithExactly(GET, 'voters', options, callback)).should.be.true();
});
});

Expand All @@ -374,20 +374,10 @@ describe('Lisk.api()', () => {
});
});

describe('#getMultisignatureTransactions', () => {
describe('#getUnsignedMultisignatureTransactions', () => {
it('should get all current unsigned multisignature transactions', () => {
LSK.getMultisignatureTransactions();
(LSK.sendRequest.calledWithExactly(GET, 'transactions/multisignatures', {}, undefined)).should.be.true();
});
});

describe('#getMultisignatureTransaction', () => {
it('should get a multisignature transaction by id', () => {
const address = '16010222169256538112L';
const options = { id: address };

LSK.getMultisignatureTransaction(address, callback);
(LSK.sendRequest.calledWithExactly(GET, 'transactions/multisignatures/get', options, callback)).should.be.true();
LSK.getUnsignedMultisignatureTransactions();
(LSK.sendRequest.calledWithExactly(GET, 'transactions/unsigned', {}, undefined)).should.be.true();
});
});

Expand Down

0 comments on commit 23714f2

Please sign in to comment.