All files / src requester.js

100% Statements 6/6
77.78% Branches 7/9
100% Functions 2/2
100% Lines 6/6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36                          41x 41x               41x   41x 1x     40x              
 
/**
 * Module dependencies.
 */
 
import { get } from 'lodash';
 
/**
 * Export Requester class.
 */
 
export default class Requester {
  constructor({ methods = {}, version } = {}) {
    this.methods = methods;
    this.version = version;
  }
 
  /**
  * Prepare rpc request.
  */
 
  prepare({ method, parameters = [], suffix }) {
    method = method.toLowerCase();
 
    if (this.version && !get(this.methods[method], 'supported', false)) {
      throw new Error(`Method "${method}" is not supported by version "${this.version}"`);
    }
 
    return {
      id: `${Date.now()}${suffix !== undefined ? `-${suffix}` : ''}`,
      method,
      params: parameters
    };
  }
}