index.js
function NfieldClient (defOptions) {
  
  var defaultRequestCliOptions = {
    baseUrl : 'https://api.nfieldmr.com/'
  };
  
  extend(true, defaultRequestCliOptions, defOptions);
  
  /**
   * Sign In api method provided strait with NfieldCliend instance because it doesn't need authentication
   */
  this.SignIn = API.signIn.bind(null, defaultRequestCliOptions);
  
  /**
   * Returns a new instance of NfieldClient with new request parameters
   */
  this.defaults = function defaults (options) {
    if (typeof options !== 'object') throw new TypeError('`options` must be an object with request parameters');
    return new NfieldClient(options);
  };
  
  /**
   * Connects NfieldClient to API
   * Returns ConnectedInstance
   */
  this.connect = function connect (credentials, callback) {
    
    var token = {};
    var promise;
    
    if (typeof credentials === 'function') callback = credentials;
    
    promise = API.signIn(defaultRequestCliOptions, credentials).then(function (data) {
      if (data[0].statusCode !== 200) {
        throw new Error(`${data[0].statusCode}: ${data[0].body.Message}`);
      } else {
        token = {
          AuthenticationToken : data[0].body.AuthenticationToken,
          Timestamp : Date.now()
        };
        return new ConnectedInstance(defaultRequestCliOptions, token, credentials);
      }
    }).nodeify(callback);
    
    return promise;
  };
  
}
function NfieldClient (defOptions) {
  
  var defaultRequestCliOptions = {
    baseUrl : 'https://api.nfieldmr.com/'
  };
  
  extend(true, defaultRequestCliOptions, defOptions);
  
  /**
   * Sign In api method provided strait with NfieldCliend instance because it doesn't need authentication
   */
  this.SignIn = API.signIn.bind(null, defaultRequestCliOptions);
  
  /**
   * Returns a new instance of NfieldClient with new request parameters
   */
  this.defaults = function defaults (options) {
    if (typeof options !== 'object') throw new TypeError('`options` must be an object with request parameters');
    return new NfieldClient(options);
  };
  
  /**
   * Connects NfieldClient to API
   * Returns ConnectedInstance
   */
  this.connect = function connect (credentials, callback) {
    
    var token = {};
    var promise;
    
    if (typeof credentials === 'function') callback = credentials;
    
    promise = API.signIn(defaultRequestCliOptions, credentials).then(function (data) {
      if (data[0].statusCode !== 200) {
        throw new Error(`${data[0].statusCode}: ${data[0].body.Message}`);
      } else {
        token = {
          AuthenticationToken : data[0].body.AuthenticationToken,
          Timestamp : Date.now()
        };
        return new ConnectedInstance(defaultRequestCliOptions, token, credentials);
      }
    }).nodeify(callback);
    
    return promise;
  };
  
}
function NfieldClient ( defOptions ) { var defaultRequestCliOptions = { baseUrl : 'https://api.nfieldmr.com/' } ; extend ( true , defaultRequestCliOptions , defOptions ) ; /**
   * Sign In api method provided strait with NfieldCliend instance because it doesn't need authentication
   */ this . SignIn = API . signIn . bind ( null , defaultRequestCliOptions ) ; /**
   * Returns a new instance of NfieldClient with new request parameters
   */ this . defaults = function defaults ( options ) { if ( typeof options !== 'object' ) throw new TypeError ( '`options` must be an object with request parameters' ) ; return new NfieldClient ( options ) ; } ; /**
   * Connects NfieldClient to API
   * Returns ConnectedInstance
   */ this . connect = function connect ( credentials , callback ) { var token = { } ; var promise ; if ( typeof credentials === 'function' ) callback = credentials ; promise = API . signIn ( defaultRequestCliOptions , credentials ) . then ( function ( data ) { if ( data [ 0 ] . statusCode !== 200 ) { throw new Error ( ` ${ data [ 0 ] . statusCode } ${ data [ 0 ] . body . Message } ` ) ; } else { token = { AuthenticationToken : data [ 0 ] . body . AuthenticationToken , Timestamp : Date . now ( ) } ; return new ConnectedInstance ( defaultRequestCliOptions , token , credentials ) ; } } ) . nodeify ( callback ) ; return promise ; } ; }
Creates NfieldClient object
@constructor
Creates NfieldClient object