1.0.3 • Published 1 year ago

@samdiano/lotr-sdk v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

The Lord of the Rings SDK

Overview

This SDK is designed to provide easy access to information about The Lord of the Rings trilogy through an existing API . The SDK covers only the movie endpoints.

Installation

The SDK can be installed using your preferred package manager. For example, if you're using npm:

npm install @samdiano/lotr-sdk

Usage

To use the SDK, first import it into your code:

const LordOfTheRingsSDK = require('@samdiano/lotr-sdk');

Then create a new instance of the SDK with your API key. Sign up here to obtain your API key:

const apiKey = 'YOUR_API_KEY';
const lotr = new LordOfTheRingsSDK({
  apiKey,
});

You can then use the methods provided by the SDK to access information about the movies. For example:

lotr.getMovies().then((movies) => {
  console.log(movies);
});

This will return an object containing the list of movies each containing information about a movie in The Lord of the Rings trilogy, and pagination metadata.

Methods

The following methods are available in the SDK:

getMovies(options?)

Returns an object containing an array of objects, each containing information about a movie in The Lord of the Rings trilogy, as well as metadata about the API response. You can optionally pass in an object to specify query parameters for the API request.

Example:

const sdk = new LordOfTheRingsSDK();
const movies = await sdk.getAllMovies();
console.log(movies); // { movies: [{...}, {...}, {...}], total: 8, limit: 10, page: 1, pages: 1 }

getMovieById(id)

Returns an object containing information about the movie with the specified ID. The object contains a single movie property, which is an object containing movie information.

Example:

const sdk = new LordOfTheRingsSDK();
const movie = await sdk.getMovieById('tt0120737');
console.log(movie); // { movie: {...} }

getMovieQuotes(id, options?)

Returns an object containing an array of objects, each containing a quote from the movie with the specified ID, as well as metadata about the API response. You can optionally pass in an object to specify query parameters for the API request.

Example:

const quotes = await sdk.getMovieQuotes('tt0120737');
console.log(quotes); // { quotes: [{...}, {...}, {...}], total: 8, limit: 10, page: 1, pages: 1 }

Here are some examples of how to use the optional query parameters:

  • To limit the number of results returned:
const options = { limit: 10 };
const movies = await sdk.getAllMovies(options);
  • To paginate through results:
const options = { limit: 10, page: 2 };
const movies = await sdk.getAllMovies(options);
  • To specify an offset:
const options = { limit: 10, offset: 20 };
const movies = await sdk.getAllMovies(options);
  • To sort the results:
const options = { sort: 'name:asc' };
const movies = await sdk.getAllMovies(options);
  • To apply filters:
const options: GetOptions = {
  filters: { director: 'Peter Jackson', year: 2001 },
};
const movies = await sdk.getAllMovies(options);

You can get more info on how to add the query parameters from the API documentation here.

Testing

The SDK includes a suite of tests to ensure that it is working as expected. To run the tests, run npm test from the root of the project.

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago