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

rotowire-api-client

v1.0.5

Published

Node and NestJS wrappers for Rotowire feeds

Downloads

330

Readme

npm version install size npm downloads Known Vulnerabilities GitHub top language GitHub Sponsors

Welcome to the comprehensive interface for the Rotowire API Client!

This package provides a seamless integration with the Rotowire API, allowing developers to fetch sports data with ease. It's been refactored and optimized to provide a straightforward experience. This, in part, uses the Open API v3 Open API Generator.

🚨 Disclaimer

This package initially provides access to a select set of Rotowire APIsthat have been acquired for my project from Rotowire. Additionally, not all use cases have been exhaustively tested or verified. Users are encouraged to test the package in their specific contexts and report any issues they encounter. Contributions and feedback are always welcome!

🌟 Why Use This?

  • Partial Coverage: This package offers complete access to the a select set of Rotowire Endpoints.
  • Optimized for Use: The refactoring ensures that accessing and using the API is as intuitive and straightforward as possible.
  • Full documentation: See full documentation of the API Specification.

✅ Feeds Included (at this point)

  • ⚾️ MLB
    • dailyProjections(format, date?)
    • expectedLineups(format, date?)
    • injuries(format)
    • newsInjuries(format, date?)
    • projectedStarters(format, date?, spring_training?)
  • 🏀 NBA
    • dailyProjections(format, date?)
    • expectedLineups(format, date?)
    • injuries(format)
    • newsInjuries(format, date?, hours?)
  • 🏈 NFL
    • dailyProjections(format, date?)
    • injuries(format)
    • newsInjuries(format, date?, hours?)
    • weeklyProjections(format, position?, season?, team?, week?)

🛠 Installation

npm install rotowire-api-client --save

🚀 Getting Started

NestJS Implementation

To begin, you'll need your API keys for MLB, NBA, and NFL.

Synchronous Configuration - Using forRoot

You can configure the RotowireApiClientModule synchronously using the forRoot method:

import { RotowireApiClientModule } from 'rotowire-api-client';

@Module({
  imports: [
    RotowireApiClientModule.forRoot({
      mlb: {
        apiKey: 'YOUR_MLB_API_KEY',
        basePath: 'YOUR_MLB_BASE_PATH',
      },
      nba: {
        apiKey: 'YOUR_NBA_API_KEY',
        basePath: 'YOUR_NBA_BASE_PATH',
      },
      nfl: {
        apiKey: 'YOUR_NFL_API_KEY',
        basePath: 'YOUR_NFL_BASE_PATH',
      },
    }),
  ],
})
export class AppModule {}

Asynchronous Configuration with ConfigService - Using forRootAsync

If you're using NestJS's ConfigModule and ConfigService to manage your application's configuration, you can configure the RotowireApiClientModule asynchronously:

import { RotowireApiClientModule } from 'rotowire-api-client';
import { ConfigModule, ConfigService } from '@nestjs/config';

@Module({
  imports: [
    ConfigModule.forRoot(),
    RotowireApiClientModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        mlb: {
          apiKey: configService.get<string>('MLB_API_KEY'),
          basePath: configService.get<string>('MLB_BASE_PATH'),
        },
        nba: {
          apiKey: configService.get<string>('NBA_API_KEY'),
          basePath: configService.get<string>('NBA_BASE_PATH'),
        },
        nfl: {
          apiKey: configService.get<string>('NFL_API_KEY'),
          basePath: configService.get<string>('NFL_BASE_PATH'),
        },
      }),
      inject: [ConfigService],
    }),
  ],
  exports: [RotowireApiClientModule], 
})
export class AppModule {}

In the asynchronous configuration example, the ConfigService is used to retrieve the API keys and base paths from your environment or configuration files.

Using the Client in Your Service or Controller

After configuration, you can import RotowireApiClientModule into your module, then import the appropriate API (e.g. RotowireMlbApi) and inject the service RotowireMlbApi.DefaultRotowireMlbApiService (or the respective service for other sports) into your services or controllers. Here is an example accessing a few of the MLB API endpoints in a controller:

import { Controller, Get, HttpException, HttpStatus } from '@nestjs/common';
import { Observable } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { RotowireMlbApi } from 'rotowire-api-client';

@Controller('mlb')
export class MlbController {
    constructor(private readonly rwMlbService: RotowireMlbApi.DefaultRotowireMlbApiService) {}

    @Get('injuries')
    getInjuries(): Observable<any> {
        return this.rwMlbService.injuries("en", "json").pipe(
            map(apiResponse => {
                if (apiResponse.status !== 200) {
                    throw new HttpException(apiResponse.data, apiResponse.status);
                }
                return apiResponse.data;
            }),
            catchError(err => {
                throw new HttpException(err.message, HttpStatus.INTERNAL_SERVER_ERROR);
            })
        );
    }
}

Regular Node.js Implementation

For a non-NestJS implementation, you can directly use the services provided by the package.

const { DefaultRotowireMlbApiService } = require('rotowire-api-client');

const mlbConfig = {
    apiKey: 'YOUR_MLB_API_KEY',
    basePath: 'https://api.rotowire.us/mlb/production/v7'
};

const mlbService = new DefaultRotowireMlbApiService(mlbConfig);

// Use mlbService to access all the MLB endpoint APIs

With these setups, you have the entire Rotowire API at your fingertips! Currently, the package supports MLB, NBA, and NFL. However, other sports can be added in the future.

📌 Features

  • Easy Initialization: Set up and start using the client in no time.
  • Multiple Sports: Includes endpoints from MLB, NBA and NFL.
  • Expandable: While the package currently supports MLB, NBA, and NFL, it's designed to be easily expandable to other sports in the future.

🤝 Contribute

Your insights and contributions can make this package even better! Check out our CONTRIBUTING.md guide and be a part of this exciting project.

📖 Documentation

Our library's documentation is generated using TypeDoc, ensuring that you get the most accurate and up-to-date information directly from the source code.

Happy coding! 🎉

⚖️ License

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