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

@ewmiller/lotr-sdk

v1.0.5

Published

An SDK for the One API to Rule Them All

Downloads

11

Readme

LOTR SDK

One SDK to bring them all, and in the ~darkness~ network, bind them.

Introduction

This Javascript/Typescript SDK is used to access the entities within the /movie endpoint of The One API. You can get a list of all Lord of the Rings Movies, request one specific movie via its ID, or request quotes from any individual movie (also by its ID).

Installation

Using npm:

npm i @ewmiller/lotr-sdk

Usage

API Key

First you'll need to sign up for an account at The One API to receive an API key.

Next, import the SDK and instantiate it with your API key. In this example, we're using dotenv to set the API key as an environment variable called LOTR_API_TOKEN, but you can use any method you prefer.

Create the Client

Javascript:

const LOTR = require('@ewmiller/lotr-sdk').LOTR;
require('dotenv').config();
const client = new LOTR({
  apiToken: process.env.LOTR_API_TOKEN
});

Typescript:

import { LOTR } from '@ewmiller/lotr-sdk';
import * as dotenv from 'dotenv';
dotenv.config();

const client = new LOTR({
  apiToken: process.env.LOTR_API_TOKEN
});

Using the Client

Now you're ready to call the SDK methods! The following methods are supported: movies.getAll(), movies.getOne(id: string), and quotes.getQuotesFromMovie(id: string). Here are usage examples of each:

const allMovies = await lotr.movies.getAll();

const oneMovie = await lotr.movies.getOne("5cd95395de30eff6ebccde56");

const movieQuotes = await lotr.quotes.getQuotesFromMovie("5cd95395de30eff6ebccde5d");

Response Output

Data will be returned in the following format:

{
  docs: [
    {
      ... // movie or quote details here
    },
    {
      ... // movie or quote details here 
    }
  ]
}

Where docs will be an array of either movie or quote entities. The data types for these are described on the One API's documentation, but are also copied here as typescript interfaces for reference:

export interface Movie {
  _id: string;
  name: string;
  runtimeInMinutes: number;
  budgetInMillions: number;
  boxOfficeRevenueInMillions: number;
  academyAwardNominations: number;
  academyAwardWins: number;
  rottenTomatoesScore: number;
}

export interface Quote {
  _id: string;
  dialog: string;
  movie: string;
  character: string;
  id: string;
}

Config Options

Each SDK method takes an optional configuration object as its second parameter. The config options are used for pagination of the API:

export interface ConfigOptions {
  limit?: number;
  page?: number;
  offset?: number;
}

To use these options, simply pass them in to any SDK method when you call it:

const result = await lotr.quotes.getQuotesFromMovie("5cd95395de30eff6ebccde5d", {
  limit: 100,
  page: 2,
  offset: 3
});

Future Work

This SDK only implements the /movie endpoint of The One API, but could easily be extended to include more API functionality. Check out design.md for more thoughts on the SDK design and potential for expansion. Thanks for reading!