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

tba-api-client

v1.1.1

Published

Promise Based TBA V3 API Client with Types

Downloads

12

Readme

TBA API V3 Client

An auto generated client for the The Blue Alliance V3 API from the TBA V3 Swagger Document

The generated file is a Typescript file with Type Definitions for all of the types provided in the TBA V3 API Spec

Therefore if this is used in any Typescript enabled editor then types will be provided whether it is for type checking in TS files or just ensuring correct spelling in JS files

This client supports cashing and can be used using either Promises or Callbacks

Installation

npm install tba-api-client

Usage Examples

Using Promise

const TBA = require("tba-api-client")
const client = TBA.API("{TBA API KEY}")

client.Teams(2017, 0).then( teams =>{ // Gets the first page of the teams that were active in 2017
    console.log(teams)
}).catch(console.error)

Using Async functions

const TBA = require("tba-api-client")
const client = TBA.API("{TBA API KEY}")

async function main(){
    let teams = await client.Teams(2017, 0) // Gets the first page of the teams that were active in 2017
}

main().catch(console.error)

Using Callbacks

const TBA = require("tba-api-client")
const client = TBA.API("{TBA API KEY}")

client.Teams(2017, 0, (err, teams) => { // Gets the first page of the teams that were active in 2017
    if(err != null) console.error(err)
    else console.log(teams)
})

Using Listeners

const TBA = require("tba-api-client")
const client = TBA.API("{TBA API KEY}")

client.Teams(2017, 0, (err, teams) => { // Gets the first page of the teams that were active in 2017
    if(err != null) console.error(err)
    else console.log(teams)
}, true) // The last argument Sets this callback to be called every time the server responds with a 202 instead of a 303

Using the onCashExpire callbacks

const TBA = require("tba-api-client")
const client = TBA.API("{TBA API KEY}")

getMatchesInfo(client.TeamMatches('frc3571', 2018, getPromise => getMatchesInfo(getPromise())))

function getMatchesInfo(matchPromise){
    matchPromise.then(matches=>{

    }).catch(console.error)
}

Definition

After being built, the type definitions will be located in types/genAPI.d.ts

All function calls are located in in the class API and with names that ware taken from their paths with a minor exception

The parameters for these function are in the same order as as in their path with optional additional Parameters

For Example:

  • TeamRobots(team_key) points to /team/{team_key}/robots
  • EventTeamsStatuses(event_key) points to /event/{event_key}/teams/statuses
  • TeamMedia(team_key, year) points to /team/{team_key}/media/{year}
  • TeamMedia(team_key, year) points to /team/{team_key}/media/{year}

The exceptions comes to:

  • Those that would have the same name
  • And TeamMedia

For the use of the API check out The API Docs

Same Name

Those with the same name have been combined and will give a different result depending on the parameters

  • Teams(page_num) points to /teams/{page_num}
  • Teams(year, page_num) points to /teams/{year}/{page_num}

TeamMedia

This is a combination of three paths:

  • /team/{team_key}/media/{year}
  • /team/{team_key}/media/tag/{media_tag}
  • /team/{team_key}/media/tag/{media_tag}/{year}

These should have had the names TeamMedia and TeamMediaTag but since combining them would not cause an error and them being similar, it was decided to just combine them and let the parameters decide which path would be used

Promise

This is a standard Promise containing the value of the request

Example:

client.Teams(0).then(teams => {
    // Gets the First page of all Teams using a promise
}).catch(console.error)

OnCashExpire

This callback contains a function for a new Promise for the same path

This cashExpire callback is identified by having only a single argument

Example:

client.Teams(0, onExpire =>{
    // This will run when the cache will expire
    onExpire().then(teamLater => { // By calling onExpire a new GET request was made to the same path which will renew the cache
        // This will have the result of the new request
    }).catch(console.error)
}).then(teamNow => {
    // This will run once with teamNow having either the value from the cache if it is still fresh or the result of a new request if not
}).catch(console.error)

Callback

This is a standard error first callback that can be used instead Promises

This callback is identified by having two arguments

Example:

client.Teams(2018, 0, (err, teams) => { // Gets the first page of Teams active in 2018
    // Returns with a value from cache if it is fresh or the value from a request if not 
}, true)

Listener

By setting the parameter after the callback to true, the callback becomes a listener for changes to the values from the path

To Remove the listener call removeListener(id) where id is what is returned by the function that set the listener

Example:

let teamsID = client.TeamMatches('frc3571', 2018, (err, matches) => { // Sets a listener for team 3571's 2018 matches
    // Runs after the first request is made and when the value changes
}, true)

client.removeListener(teamsID) // Removes the listener

Build Instructions

  1. Clone The Repository
    • The npm package does not contain the generator
  2. Run npm i
  3. Run npm run build