4.0.2 • Published 7 years ago

@tempicolabs/tmlabs v4.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

Moved to @tempicolabs/sdk

TmLabs is a SDK for TempicoLabs API using in node.js and the browser. It is written in clean ES6 Javascript.

Install

To install TmLabs for use in node or the browser with require('@tempicolabs/tmlabs'), run:

npm i @tempicolabs/tmlabs --save

Or alternatively using Yarn, run:

yarn add @tempicolabs/tmlabs

SDK contain:

dist/tmlabs.umd.js - Standard package for node.js

dist/tmlabs.es.js - ES6 Package for node.js using import

dist/tmlabs.js - Unminified browser version

dist/tmlabs.min.js - Minified browser version

src/* - Sources. Javascript ES2016

TmLabs API Documentation

Read SDK Documentation.

Read the full API Documentation.

Usage

Read Usage Guide.

TmLabs is the wrapper for API. It uses fetch-ponyfill for HTTP requests.

In the browser

<script src="https://cdn.jsdelivr.net/npm/@tempicolabs/tmlabs@latest/dist/tmlabs.min.js"></script>
<script>
    var TmLabs = new TmLabs.default(); // or new TmLabs.TmLabs()
    TmLabs.on('error', function(error, command){
      console.error('[ SDK ERROR ]', error);
    });
    TmLabs.on('response', function(command, response){
      console.info('response', response);
      console.log('balanceRemaining', command.balanceRemaining); // return Remaining Balance
    });
    TmLabs.on('command', function(args, command){ // on command start 
      console.log('command', command)
    });
    TmLabs.fetch('dns', {
      domain: 'google.com'
    }).then(function(answer){
      var ip = answer.content[Object.keys(answer.content)[0]];// because response will be in 'google.com' key
      console.log('History after DNS command', TmLabs.history) // get array of one completed command
      return TmLabs.fetch('ip', {
        ip: ip
      })
    }).then(function(answer){
      console.info('google ip info', answer.content) // get info about google ip address
      console.log('History after IP command', TmLabs.history) // get array of two completed commands
    });
    console.log('History with pending requests', TmLabs.history) // get array of two pending commands
</script>

In Node.js

TmLabs also works in node.js, using the same npm package!

  var TmLabs = require('@tempicolabs/tmlabs').default
  
  TmLabs.on('error', function (error, command) {
    console.error(error);
  });
  TmLabs.on('response', function (response, command) {
    console.log('response', response);
    console.log('balanceRemaining', command.balanceRemaining); // return Remaining Balance
  });
  TmLabs.fetch('dns', {
    domain: 'google.com'
  }).then(function (response) {
    console.log('after then response', response)
  })

** You can use bundled version dist/tmlabs.umd.js

Package also contain FetchCommand Class for customizing fetch data from API. For example in ES6:

  import { FetchCommand } from '@tempicolabs/tmlabs'
  
  (async function() {
    
    const command = new FetchCommand({
      method: 'ip'
    })
    command.on('error', (error, command) => {
      console.error(error);
    });
    command.on('response', (response, command) => {
      console.log('response object', response);
      console.log('response code', command.status); // same as response.status. return status code, for example 200
    });
    const response = await command.run({ // this response also goes to command.on('response') EventHandler if no error exists
      ipaddr: '173.194.122.233' // google ip address. using alias(ipaddr)
    })
    console.log(response) // API response. same as command.content
    
  })();

** You can use bundled version in dist/tmlabs.es.js for ES6

More examples you can find here

License

MIT. Copyright (c) Maxim Maximov and TempicoLabs, LLC.