npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fantasy-client

v1.0.0

Published

Official Fantasy RMT API Client for Node JS

Downloads

9

Readme

Fantasy Client - Node JS

NPM

npm version Build Status NPM download/month NPM download total

Fantasy RMT ❤️ Node JS!

This is the Official Node JS API client/library for Fantasy RMT API. Visit https://rmtid.xyz. More information about the product and see documentation at http://docs.rmtid.xyz for more technical details.

1. Installation

1.a Using NPM

npm install --save fantasy-client

1.b Manual Installation

If you are not using NPM, you can clone or download this repository. Then require from index.js file.

let fantasyClient = require('./fantasy-client/index.js');

2. Usage

2.1 Choose Product

We currently have 1 fire product you can use:

Choose one that you think best for your unique needs.

2.2 Client Initialization and Configuration

Get your client key from Fantasy Shop Dashboard

Create API client object

const fantasyClient = require('fantasy-client');
// Create Core API instance
let whatsaAppApi = new fantasyClient.WhatsApp({
  whatsAppKey : 'YOUR_WHATSAPP_KEY'
});

You can also re-set config using whatsaAppApi.apiConfig.set( ... ) example:

const fantasyClient = require('fantasy-client');

// Create WhatsApp API instance, empty config
let whatsaAppApi = new fantasyClient.WhatsApp({
  whatsAppKey : 'YOUR_WHATSAPP_KEY'
});

// You don't have to re-set using all the options, 
// i.e. set whatsAppKey only
whatsaAppApi.apiConfig.set({whatsAppKey : 'YOUR_WHATSAPP_KEY'});

You can also set config directly from attribute

const fantasyClient = require('fantasy-client');

// Create WhatsApp API instance, empty config
let whatsaAppApi = new fantasyClient.WhatsApp();

whatsaAppApi.apiConfig.whatsAppKey = 'YOUR_WHATSAPP_KEY';

2.2.A WhatsApp

You can see WhatsApp example here.

Available methods for WhatsApp class

// return WhatsApp API /status response as Promise of Object
status()

// return WhatsApp API /statusKey for whatsAppKey as Promise of Object
statusKey()

// return WhatsApp API /sendMessage response as Promise of Object
sendMessage(phoneNumber, message)

phoneNumber & message is an object JSON of WhatsApp Parameter

3. Handling Error / Exception

When using function that result in WhatsApp API call e.g: whatsAppApi.sendMessage(...) there's a chance it may throw error (FantasyError object), the error object will contains below properties that can be used as information to your error handling logic:

whatsAppApi.sendMessage(phoneNumber, message)
.then((res)=>{
  ///
})
.catch((e)=>{
  e.message // basic error message string
  e.httpStatusCode // HTTP status code e.g: 400, 401, etc.
  e.ApiResponse // JSON of the API response 
  e.rawHttpClientData // raw Axios response object
})

4. Advanced Usage

Custom Http Client Config

Under the hood this API wrapper is using Axios as http client. You can override the default config.

You can set via the value of this <api-client-instance>.httpClient.http_client.defaults object, like described in Axios guide. e.g:

// create instance of api client
let whatsaAppApi = new fantasyClient.WhatsApp({
  whatsAppKey : 'YOUR_WHATSAPP_KEY'
});

// set Axios timeout config to 2500
whatsaAppApi.httpClient.http_client.defaults.timeout = 2500; 

// set custom HTTP header for every request from this instance
whatsaAppApi.httpClient.http_client.defaults.headers.common['My-Header'] = 'my-custom-value';

Custom Http Client Interceptor

As Axios also support interceptor, you can also apply it here. e.g:

// Add a request interceptor
whatsaAppApi.httpClient.http_client.interceptors.request.use(function (config) {
  // Do something before request is sent
  return config;
}, function (error) {
  // Do something with request error
  return Promise.reject(error);
});

It can be used for example to customize/manipulate http request's body, header, etc. before it got sent to the destination API url.

Examples

Examples are available on /examples folder. There are:

Notes

Not Designed for Frontend Usage

This library/package is mainly NOT FOR FRONTEND (Browser's javascript) usage, but for backend (Node JS server) usage:

  • This is mainly for backend usage, to do secure server-to-server/backend-to-backend API call.
  • You may/will encounter CORS issue if you are using this to do API request from frontend.
  • Your API WhatsAppKey may also be exposed to public if you are using this on frontend.

Get help