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

ensembledata

v0.1.4

Published

Node.js bindings for the EnsembleData API

Downloads

212

Readme

EnsembleData Node.js API

Version

Documentation

Check out the API docs to see which endpoints are available for each social media and for detailed descriptions of their parameters and functionality.

Installation

Install the package with npm, pnpm or yarn.

npm install ensembledata
yarn add ensembledata
pnpm add ensembledata

Requirements

  • The package requires Node 18 or higher.

Usage

Register to get your free API token.

import { EDClient } from "ensembledata";

const client = EDClient({ token: "API-TOKEN" });
const result = await client.tiktok.userInfoFromUsername({
    username: "daviddobrik",
});

console.log("Data: ", result.data);
console.log("Units charged:", result.unitsCharged);

// Other Examples:
// const result = await client.instagram.userInfo({ username: "daviddobrik" })
// const result = await client.youtube.channel_subscribers({ channelId: "UCnQghMm3Z164JFhScQYFTBw" })

Missing Endpoints / Parameters

If you find that one of the endpoints from our API docs is not yet available in this package, you can use the EDClient.request method to specify the endpoint manually in the meantime.

import { EDClient } from "ensembledata";

const client = EDClient({ token: "API-TOKEN" });
const result = await client.request("/instagram/example", {
    foo: "...",
    bar: "...",
});

If you find that one the parameters to an existing endpoint is missing, you can still send this parameter via the extraParams which is available on all endpoint methods as shown below:

import { EDClient } from "ensembledata";

const client = EDClient({ token: "API-TOKEN" });
const result = await client.instagram.userInfo(
    { username: "..." },
    {
        extraParams: {
            baz: "...",
        },
    },
);

Handling Errors

In the API docs, each endpoint lists a handful of possible errors the API may respond with. You can handle these errors by catching the EDError exception.

import { EDClient, errors } from "ensembledata";

const client = EDClient({ token: "API-TOKEN" });
try {
    const result = await client.tiktok.userInfoFromUsername({
        username: "daviddobrik",
    });
} catch (error) {
    switch (error.statusCode) {
        // Rate limit exceeded...
        case errors.STATUS_429_RATE_LIMIT_EXCEEDED:
            console.log(error.detail);
            break;

        // Subscription expired...
        case errors.STATUS_493_SUBSCRIPTION_EXPIRED:
            console.log(error.detail);
            break;

        // Some other error occurred, unrelated to the EnsembleData API
        default:
            break;
    }
}

Using Promises

Every endpoint method returns a promise. You can use the .then() and .catch() methods to handle the result and errors respectively.

import { EDClient } from "ensembledata";

const client = EDClient({ token: "API-TOKEN" });
client.tiktok
    .userInfoFromUsername({ username: "daviddobrik" })
    .then((result) => {
        console.log("Data: ", result.data);
        console.log("Units charged:", result.unitsCharged);
    })
    .catch((error) => {
        console.log("Error: ", error);
    });

Network Retries

By default the EDClient will perform 3 retries when it encounters network issues. If you would like to customise this behaviour, you can pass in the maxNetworkRetries param as show below:

Note: if the request times out, it will not be retried.

import { EDClient } from "ensembledata";

const client = EDClient({ token: "API-TOKEN", maxNetworkRetries: 5 });

Configure Timeout

If you would like control over the timeout, you can configure this either for all request by setting timeout (in seconds) when creating the EDClient, or you can specify the timeout per request, on any of the individual methods as shown below:

import { EDClient } from "ensembledata";

const client = EDClient({ token: "API-TOKEN", timeout: 120 });
const result = await client.instagram.userInfo(
    { username: "..." },
    { timeout: 10 },
);

Types

This package provides TypeScript types for all the endpoints and their parameters. You can use these types to get autocompletion and type checking in your IDE. Internally the package uses JSDoc comments to provide these types. If you experience any typing problems, please let us know by creating an issue.