API docs -> WS (#141)

* API docs -> WS

* API docs update

* HttpProvider -> WsProvider

* sub<something> -> subscribing

* Update dependencies

* Test message checks update
This commit is contained in:
Jaco Greeff
2018-08-28 14:51:16 +02:00
committed by GitHub
parent 94adfa3e61
commit c3065263fc
12 changed files with 87 additions and 45 deletions
+2 -2
View File
@@ -23,9 +23,9 @@ npm install --save @polkadot/api-provider
Initialisation -
```js
import HttpProvider from '@polkadot/api-provider/http';
import WsProvider from '@polkadot/api-provider/ws';
const provider = new HttpProvider('http://127.0.0.1:9933');
const provider = new WsProvider('http://127.0.0.1:9944');
const version = await provider.send('client_version', []);
console.log('clientVersion', version);
+3 -3
View File
@@ -35,9 +35,9 @@
"dependencies": {
"@babel/runtime": "^7.0.0-rc.1",
"@polkadot/storage": "^0.28.22",
"@polkadot/util": "^0.28.7",
"@polkadot/util-crypto": "^0.28.7",
"@polkadot/util-keyring": "^0.28.7",
"@polkadot/util": "^0.28.14",
"@polkadot/util-crypto": "^0.28.14",
"@polkadot/util-keyring": "^0.28.14",
"@types/nock": "^9.1.3",
"eventemitter3": "^3.1.0",
"isomorphic-fetch": "^2.2.1",
+2 -2
View File
@@ -31,13 +31,13 @@ describe('Http', () => {
it('does not (yet) support subscribe', () => {
return http.subscribe().catch((error) => {
expect(error.message).toMatch(/has not been implemented/);
expect(error.message).toMatch(/does not have subscriptions/);
});
});
it('does not (yet) support unsubscribe', () => {
return http.unsubscribe().catch((error) => {
expect(error.message).toMatch(/has not been implemented/);
expect(error.message).toMatch(/does not have subscriptions/);
});
});
});
+9 -3
View File
@@ -13,6 +13,8 @@ import logger from '@polkadot/util/logger';
import coder from '../coder/json';
const ERROR_SUBSCRIBE = 'HTTP Provider does not have subscriptions, use WebSockets instead';
export default class HttpProvider implements ProviderInterface {
private coder: RpcCoder;
private endpoint: string;
@@ -31,7 +33,7 @@ export default class HttpProvider implements ProviderInterface {
}
on (type: ProviderInterface$Emitted, sub: ProviderInterface$EmitCb): void {
this.l.error(`Provider does not have 'on' emitters for type '${type}'`);
this.l.error(`HTTP Provider does not have 'on' emitters, use WebSockets instead`);
}
async send (method: string, params: Array<any>): Promise<any> {
@@ -54,10 +56,14 @@ export default class HttpProvider implements ProviderInterface {
}
async subscribe (types: string, method: string, params: Array<any>, cb: ProviderInterface$Callback): Promise<number> {
throw new Error('Subscriptions has not been implemented');
this.l.error(ERROR_SUBSCRIBE);
throw new Error(ERROR_SUBSCRIBE);
}
async unsubscribe (type: string, method: string, id: number): Promise<boolean> {
throw new Error('Subscriptions has not been implemented');
this.l.error(ERROR_SUBSCRIBE);
throw new Error(ERROR_SUBSCRIBE);
}
}