Rett Behrens LOTR SDK
This SDK makes it easy for developers to consume information about the LOTR series via the LOTR API.
Table of Contents
SDK Installation
To install this SDK in your project:
npm install rett-behrens-lotr-sdk
Getting Started
The LOTR API rquires a valid access token in order to make API requests to the server. To obtain an access token sign up for a LOTR API user account. Upon sign up you will be presented with an access token. You can also revisit your account page to retrieve your access token at any time. Add the access token to your project evironment variables file so you can reference this key securely in your project code.
LOTR_TOKEN = "xxxxxxxuxxxxxxxxxx-x"
Available Methods
method | description |
---|
getMovies() | Returns a list of all movies, including the "The Lord of the Rings" and the "The Hobbit" trilogies |
getMovieById(id) | Returns the specified movie |
getQuotes() | Returns a list of all movie quotes |
getQuoteById(id) | Returns the specified quote |
getQuotesByMovieId(id) | Returns all movie quotes for one specific movie (only working for the LotR trilogy) |
Usage
require('dotenv').config()
const lotr = require('rett_behrens_lotr_sdk');
(async () => {
const moviesAPI = new lotr.MoviesApi()
const quotesAPI = new lotr.QuotesApi();
moviesAPI.accessToken = process.env.LOTR_TOKEN;
quotesAPI.accessToken = process.env.LOTR_TOKEN;
const movies = await moviesAPI.getMovies();
console.log(movies.body);
const movieId = movies.body.docs.filter(movie => movie.name == 'The Fellowship of the Ring')[0].id;
console.log(movieId);
const movie = await moviesAPI.getMovieById(movieId);
console.log(movie.body);
const quotes = await quotesAPI.getQuotes();
console.log(quotes.body);
const quote = await quotesAPI.getQuoteById(quotes.body.docs[397].id);
console.log(quote.body);
const quotesFromTFOTR = await quotesAPI.getQuotesByMovieId(movieId);
console.log(quotesFromTFOTR.body);
})();