This package has been deprecated

Author message:

This package has been renamed to @exponential/apps

@exponential/consumer-utils

1.1.0 • Public • Published

consumer-utils


Quick Start:

Get the API key

Login at https://www.exponentialhost.com/ and get your API key at https://www.exponentialhost.com/my-apps. Put your API key in EXPONENTIAL_API_KEY environment variable.

export EXPONENTIAL_API_KEY=<your-exponential-api-key>

Installation:

npm install --save @exponential/consumer-utils

Start calling the exponential APIs

const exponential = require('@exponential/consumer-utils')(process.env.EXPONENTIAL_API_KEY);

exponential.call('website-screenshot-api', 'GET', '/', {
    params: {
        url: 'blog.exponentialhost.com'
    },
    responseType: 'stream'
});

exponential.call('tweet-image', 'POST', '/image', {
    headers: {
        "content-type": "application/json"
    },
    data: {
        "twitterUrl": "https://twitter.com/narendramodi/status/1571162212190007298",
        "imageType": "square",
        "templates": [
            "crisp"
        ]
    }
});

See below (Examples) for more detailed examples

API

call(projectHandle, method, path, config)

Use the call function to call any exponential API as mentioned above. exponential.call(projectHandle, method, path, config). config is an object containing optionally additional HTTP headers (headers), request body (data), URL params (params), and other optional axios configurations (https://github.com/axios/axios#request-config).

Response is an axios promise (https://github.com/axios/axios#response-schema).

credits()

Get your remaining credits

const exponential = require('@exponential/consumer-utils')(process.env.EXPONENTIAL_API_KEY);

console.log(exponential.credits); // Response: {credits_available: { freeCredits: <integer>, purchasedCredits: <integer> }, balanceCredits: <integer>, cumulativeTotalCredits: <integer>}

Examples

Example 1: Call the website screenshot API

const exponential = require("@exponential/consumer-utils")(process.env.EXPONENTIAL_API_KEY);

const fs = require('fs');

async function callWebsiteScreenshotAPI() {
    const response = await exponential.call('website-screenshot-api', 'GET', '/', {
        params: {
            url: 'blog.exponentialhost.com'
        },
        responseType: 'stream'
    }).catch((e) => { 
        console.error(e);
    });
    response.data.pipe(fs.createWriteStream('/tmp/screenshot.png'));
    response.data.on('end', () => {
        console.log('screenshot written to /tmp/screenshot.png');
    });
}

callWebsiteScreenshotAPI();

Example 2 : tweet image API

const exponential = require("@exponential/consumer-utils")(process.env.EXPONENTIAL_API_KEY);

exponential.call('tweet-image', 'POST', '/image', {
    headers: {
        "content-type": "application/json"
    },
    data: {
        "twitterUrl": "https://twitter.com/narendramodi/status/1571162212190007298",
        "imageType": "square",
        "templates": [
            "crisp"
        ]
    }
}).then((response) => { 
    console.log(response.data); // response { 'crisp': 'https://i.exponentialhost.com/tweetImages/crisp_1571162212190007298_square.png' }
}).catch((e) => { 
    console.error(e);
});

Package Sidebar

Install

npm i @exponential/consumer-utils

Weekly Downloads

2

Version

1.1.0

License

MIT

Unpacked Size

13.2 kB

Total Files

7

Last publish

Collaborators

  • fahisayub
  • kbsbng