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

dales_fragoso-sdk-lotr

v1.1.0

Published

This is an SDK for the LOTR API, providing convenient methods to interact with the API and retrieve data related to movies and quotes from The Lord of the Rings.

Downloads

1

Readme

Dales Fragoso Lord of the Rings SDK

This is an SDK for the LOTR API, providing convenient methods to interact with the API and retrieve data related to movies and quotes from The Lord of the Rings.

Getting an API Key

To use the SDK, you need an API key from the LOTR API. Here's how you can obtain one:

  1. Visit https://the-one-api.dev/ in your web browser.
  2. Click on the "Sign Up" button on the top right menu.
  3. Sign up for an account if you don't have one. If you already have an account, log in.
  4. Once you're logged in, you'll see your API key displayed on their homepage.
  5. Copy the API key and use it when initializing the LotrClient in your code.

Note: The API key is a secret credential that grants access to the Lotr API on your behalf. Keep your API key secure and do not share it publicly.

For more information on the Lotr API and API key usage, refer to the Lotr API Documentation.

Installation

Using npm:

npm install dales_fragoso-sdk-lotr

Using yarn:

yarn add dales_fragoso-sdk-lotr

Using pnpm:

pnpm add dales_fragoso-sdk-lotr

Testing

To run the tests for this package, follow these steps:

Make sure you have all the dependencies installed by running the following command:

pnpm install

Execute the test command:

pnpm test

This will run the test suite using Jest and provide you with the test results.

(Optional) If you want to run the tests in watch mode, use the following command:

pnpm run test:watch

This will run the tests in watch mode, where the test runner will re-run the tests whenever there are changes to the source code or test files. You can use this to apply TDD during the development process.

Basic Usage

import { LotrClient, Pagination } from 'dales_fragoso-sdk-lotr';

async function main() {
  const apiKey: string = 'your-api-key';
  const enableLogging: boolean = true;

  const client: LotrClient = new LotrClient(apiKey, enableLogging);

  try {
    // Example: Get all movies with pagination
    const pagination: Pagination = {
      limit: 10,
      page: 1
    };
    const moviesResponse = await client.getMovies(pagination);
    console.log(moviesResponse.data); // List of movies for the specified page

    // Example: Get a movie by ID
    const movieId: string = 'your-movie-id';
    const movieResponse = await client.getMovieById(movieId);
    console.log(movieResponse.data); // Movie with the given ID

    // Example: Get quotes from a movie with pagination
    const movieQuotesPagination: Pagination = {
      limit: 5,
      page: 1
    };
    const movieQuotesResponse = await client.getMovieQuotes(movieId, movieQuotesPagination);
    console.log(movieQuotesResponse.data); // List of quotes from the movie for the specified page

    // Example: Get all quotes with pagination
    const quotesPagination: Pagination = {
      limit: 20,
      page: 3
    };
    const quotesResponse = await client.getQuotes(quotesPagination);
    console.log(quotesResponse.data); // List of all quotes for the specified page

    // Example: Get a quote by ID
    const quoteId: string = 'your-quote-id';
    const quoteResponse = await client.getQuoteById(quoteId);
    console.log(quoteResponse.data); // Quote with the given ID
  } catch (error) {
    console.error('Error:', error);
  }
}

main();

Replace 'your-api-key', 'your-movie-id', and 'your-quote-id' with the actual values you need for your requests.

Advanced Usage

You can use the Pagination, Filter, and Sort objects to filter, paginate, and sort data in your API requests. Here's an example of using the revised LotrClient with the separate parameters for pagination, filters, and sorting:

import { LotrClient, Pagination, Filter, Sort } from 'dales_fragoso-sdk-lotr';

const client: LotrClient = new LotrClient(apiKey, enableLogging);

async function main() {
  try {
    // Example: Get all movies with pagination, filters, and sorting
    const pagination: Pagination = {
      limit: 10,
      page: 1
    };
    const filters: Filter[] = [
      {
        match: {
          attribute: 'name',
          operation: '=',
          value: 'The Two Towers'
        }
      },
      {
        comparator: {
          attribute: 'rottenTomatoesScore',
          value: 90,
          operation: '>'
        }
      }
    ];
    const sort: Sort = {
      attribute: 'name',
      order: 'asc'
    };

    const response = await client.getMovies(pagination, filters, sort);
    console.log(response.data); // List of movies matching the filters, sorted, and paginated
  } catch (error) {
    console.error('Error:', error);
  }
}

main();

Check the type documentation in the package to learn how to properly use each one of the available features.

Keep in mind that the filters will be aplied by the API using MongoDB aggregations, and therefore you should be carefull to not override your previous filters

License

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