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

tribe-api-wrapper

v1.3.2

Published

Custom wrapper for tribe tracking

Downloads

65

Readme

tribe-api-wrapper

npm npm NPM GitHub issues

This package is designed to offer an accessible and efficient interface for the Tribe Leaderboard API. It encompasses a React component for visualizing leaderboards and a set of functions that were intended to facilitate various interactions with the API endpoints.

Project To-Do List

Test live now in storybook

  • [ ] Update storybook build out
  • [ ] Fix small errors/consistency in props/options
  • [ ] Fix docs to be super efficient and explanatory
  • [ ] Build more components

Table of Contents

Installation

Install the library using npm:

npm install tribe-api-wrapper

Usage

The library provides a set of functions that can be used directly to interact with the Tribe API. It also includes pre-made React components for common tasks. You can choose to use the functions directly or utilize the components based on your needs.

Importing Functions and Components

import {
  getLeaderboard,
  getClientList,
  getPublicClientUserList,
  Leaderboard,
  ClientList,
  UserList,
  ClientCardLG,
  ClientCardSM
} from 'tribe-api-wrapper';

Examples

Using Functions Directly

Fetching List of Clients

const clients = await getClientList();

Fetching Leaderboard Data

const data = await getLeaderboard('example-client-id', { timePeriod: 'week', trial: true, badgeFilter: false });

Fetching Public Client User List

const users = await getPublicClientUserList('example-client-id', { timePeriod: 'all', badgeFilter: false });

Examples

Using the getLeaderboard Function

Note:

The client parameter is required and can be a specific client ID or the special value "all" to get data for all clients.

TypeScript

import { LeaderboardResponse, getLeaderboard } from 'tribe-api-wrapper';
import { useState, useEffect } from 'react';

export default function Home() {
  const [leaderboardData, setLeaderboardData] = useState<LeaderboardResponse | null>(null);
  const [error, setError] = useState<string | null>(null);

  useEffect(() => {
    async function fetchData() {
      // To fetch leaderboard data for all clients, you can use 'all' as the client parameter:
      const data = await getLeaderboard('all', { timePeriod: 'week', trial: true, badgeFilter: false });
      if (data instanceof Error) {
        setError(data.message);
      } else {
        setLeaderboardData(data as LeaderboardResponse);
      }
    }
    fetchData();
  }, []);

  return (
    <div>
      <h1>Leaderboard</h1>
      {error ? (
        <div>Error: {error}</div>
      ) : leaderboardData ? (
        leaderboardData.data.map((user) => (
          <div key={user.username}>
            Username: {user.username} <br />
            Twitter Points: {user.twitter_points} <br />
            Content Points: {user.content_points} <br />
            Total Points: {user.total_points} <br />
            {user.has_badge && `Badge: ${user.badge_icon}`} <br />
            <hr />
          </div>
        ))
      ) : (
        <div>Loading...</div>
      )}
    </div>
  );
}

JavaScript

import { getLeaderboard } from 'tribe-api-wrapper';
import { useState, useEffect } from 'react';

export default function Home() {
  const [leaderboardData, setLeaderboardData] = useState(null);
  const [error, setError] = useState(null);

  useEffect(() => {
    async function fetchData() {
      const data = await getLeaderboard('example-client-id', { timePeriod: 'week', trial: true, badgeFilter: false });
      if (data instanceof Error) {
        setError(data.message);
      } else {
        setLeaderboardData(data);
      }
    }
    fetchData();
  }, []);

  return (
    <div>
      <h1>Leaderboard</h1>
      {error ? (
        <div>Error: {error}</div>
      ) : leaderboardData ? (
      leaderboardData.data.map((user) => (
        <div key={user.username}>
          Username: {user.username} <br />
          Twitter Points: {user.twitter_points} <br />
          Content Points: {user.content_points} <br />
          Total Points: {user.total_points} <br />
          {user.has_badge && `Badge: ${user.badge_icon}`} <br />
          <hr />
        </div>
      ))
      ) : (
        <div>Loading...</div>
      )}
    </div>
  );
}

Using the Leaderboard Component

TypeScript

import { Leaderboard } from 'tribe-api-wrapper';

export default function Home() {
  return (
    <div>
      <h1>Leaderboard</h1>
        <Leaderboard
          client="example-client-id"
          timePeriod="week"
          trial={true}
          badgeFilter={false}
          limit={10}
          className="custom-leaderboard"
          errorClassName="custom-error"
          loadingClassName="custom-loading"
          tableClassName="custom-table"
          headerClassName="custom-header"
          rowClassName="custom-row"
          badgeClassName="custom-badge"
          titleClassName="custom-title"
          textClassName="custom-text"
          badge_icon="path/to/badge/icon.png"
          style={{ border: '1px solid #ccc' }}
        />
    </div>
  );
}

JavaScript

import { Leaderboard } from 'tribe-api-wrapper';

export default function Home() {
  return (
    <div>
      <h1>Leaderboard</h1>
        <Leaderboard
          client="example-client-id"
          timePeriod="week"
          trial={true}
          badgeFilter={false}
          limit={10}
          className="custom-leaderboard"
          errorClassName="custom-error"
          loadingClassName="custom-loading"
          tableClassName="custom-table"
          headerClassName="custom-header"
          rowClassName="custom-row"
          badgeClassName="custom-badge"
          titleClassName="custom-title"
          textClassName="custom-text"
          badge_icon="path/to/badge/icon.png"
          style={{ border: '1px solid #ccc' }}
        />
    </div>
  );
}

Using the UserList Component

TypeScript

import { UserList } from 'tribe-api-wrapper';

export default function Home() {
  return (
    <UserList
      client="example-client-id"
      containerClassName="custom-container"
      userClassName="custom-user"
      textClassName="custom-text"
      style={{ padding: '10px' }}
    />
  );
}

JavaScript

import { UserList } from 'tribe-api-wrapper';

export default function Home() {
  return (
    <UserList
      client="example-client-id"
      containerClassName="custom-container"
      userClassName="custom-user"
      textClassName="custom-text"
      style={{ padding: '10px' }}
    />
  );
}

Using the ClientList Component

TypeScript

import { ClientList } from 'tribe-api-wrapper';

export default function Home() {
  return (
    <ClientList
      className="custom-list"
      clientClassName="custom-client"
      avatarClassName="custom-avatar"
      backgroundClassName="custom-background"
      textClassName="custom-text"
      style={{ margin: '20px' }}
    />
  );
}

JavaScript

import { ClientList } from 'tribe-api-wrapper';

export default function Home() {
  return (
    <ClientList
      className="custom-list"
      clientClassName="custom-client"
      avatarClassName="custom-avatar"
      backgroundClassName="custom-background"
      textClassName="custom-text"
      style={{ margin: '20px' }}
    />
  );
}

Using the ClientCardLG Component

TypeScript

import { ClientCardLG } from 'tribe-api-wrapper';

export default function Home() {
  return (
    <ClientCardLG
      client="example-client-id"
      cardClassName="custom-card-lg"
      bannerClassName="custom-banner"
      avatarClassName="custom-avatar"
      nameClassName="custom-name"
      style={{ boxShadow: '0 0 10px rgba(0,0,0,0.1)' }}
    />
  );
}

JavaScript

import { ClientCardLG } from 'tribe-api-wrapper';

export default function Home() {
  return (
    <ClientCardLG
      client="example-client-id"
      cardClassName="custom-card-lg"
      bannerClassName="custom-banner"
      avatarClassName="custom-avatar"
      nameClassName="custom-name"
      style={{ boxShadow: '0 0 10px rgba(0,0,0,0.1)' }}
    />
  );
}

Using the ClientCardSM Component

TypeScript

import { ClientCardSM } from 'tribe-api-wrapper';

export default function Home() {
  return (
    <ClientCardSM
      client="example-client-id"
      cardClassName="custom-card-sm"
      bannerClassName="custom-banner"
      avatarClassName="custom-avatar"
      nameClassName="custom-name"
      style={{ boxShadow: '0 0 5px rgba(0,0,0,0.1)' }}
    />
  );
}

JavaScript

import { ClientCardSM } from 'tribe-api-wrapper';

export default function Home() {
  return (
    <ClientCardSM
      client="example-client-id"
      cardClassName="custom-card-sm"
      bannerClassName="custom-banner"
      avatarClassName="custom-avatar"
      nameClassName="custom-name"
      style={{ boxShadow: '0 0 5px rgba(0,0,0,0.1)' }}
    />
  );
}

Using the ClientProfile Component

TypeScript

import { ClientProfile } from 'tribe-api-wrapper';

export default function Home() {
  return (
    <ClientProfile
      client="example-client-id"
      containerClassName="custom-container"
      bannerClassName="custom-banner"
      avatarClassName="custom-avatar"
      leaderboardClassName="custom-leaderboard"
      style={{ boxShadow: '0 0 5px rgba(0,0,0,0.1)' }}
    />
  );
}

JavaScript

import { ClientProfile } from 'tribe-api-wrapper';

export default function Home() {
  return (
    <ClientProfile
      client="example-client-id"
      containerClassName="custom-container"
      bannerClassName="custom-banner"
      avatarClassName="custom-avatar"
      leaderboardClassName="custom-leaderboard"
      style={{ boxShadow: '0 0 5px rgba(0,0,0,0.1)' }}
    />
  );
}

API Docs

Functions API Docs

Component API Docs

Types

Refer to types.ts for the detailed type definitions.

Contributing

Contributions are welcome! Please follow the contributing guidelines for more information.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Links

Disclaimer

Please note that this library was developed independently and is not associated with or endorsed by Tribe. It is intended for responsible and ethical use and is not designed to violate or circumvent Tribe's terms of service.

The library is provided "as-is," and users are encouraged to review Tribe's terms of service and ensure compliance with all applicable regulations. Use of this library is at your own risk, and the authors make no warranties or representations regarding its legality, reliability, or fitness for a particular purpose.