@exponential/apps

1.1.3 • Public • Published

apps


Quick Start:

Get the API key

Login at https://app.datacloud.sh/ and get your API key at https://app.datacloud.sh/my-apps. Put your API key in DATACLOUD_API_KEY environment variable.

export DATACLOUD_API_KEY=<your-datacloud-api-key>

Installation:

npm install --save @exponential/apps

Start calling the datacloud APIs

const datacloud = require('@exponential/apps')(process.env.DATACLOUD_API_KEY);

datacloud.api.tweetImage.postImage({
    data: {
        "twitterUrl": "https://twitter.com/narendramodi/status/1571162212190007298",
        "imageType": "square",
        "templates": [
            "crisp"
        ]
    }
}).then((response) => { 
    console.log(response.data);
}).catch((e) => { 
    console.error(e);
});

See below (Examples) for more detailed examples

API

api.<project_name>.<function>

Use the datacloud.api.<project_name>.<function_name> methods to make the API calls. See below (Examples) for detailed examples for how to use it.

call(projectHandle, method, path, config)

Use the call function to call any datacloud API as mentioned above. datacloud.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 datacloud = require('@exponential/apps')(process.env.DATACLOUD_API_KEY);

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

Examples

Example 1: Call the website screenshot API

Using the API interface

const datacloud = require("@exponential/apps")(process.env.DATACLOUD_API_KEY);
const fs = require('fs');

async function callWebsiteScreenshotAPI() {
    const response = await datacloud.api.websiteScreenshotApi.get({
        params: {
            url: 'blog.datacloud.sh'
        },
        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();

Using call method

const datacloud = require("@exponential/apps")(process.env.DATACLOUD_API_KEY);
const fs = require('fs');

async function callWebsiteScreenshotAPI() {
    const response = await datacloud.call('website-screenshot-api', 'GET', '/', {
        params: {
            url: 'blog.datacloud.sh'
        },
        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

Using the API interface

const datacloud = require("@exponential/apps")(process.env.DATACLOUD_API_KEY);
datacloud.api.tweetImage.postImage({
    data: {
        "twitterUrl": "https://twitter.com/narendramodi/status/1571162212190007298",
        "imageType": "square",
        "templates": [
            "crisp"
        ]
    }
}).then((response) => { 
    console.log(response.data);
}).catch((e) => { 
    console.error(e);
});

Using call method

const datacloud = require("@exponential/apps")(process.env.DATACLOUD_API_KEY);

datacloud.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.datacloud.sh/tweetImages/crisp_1571162212190007298_square.png' }
}).catch((e) => { 
    console.error(e);
});

Package Sidebar

Install

npm i @exponential/apps

Weekly Downloads

1

Version

1.1.3

License

MIT

Unpacked Size

12.1 kB

Total Files

6

Last publish

Collaborators

  • fahisayub
  • kbsbng