The Lord of the Rings SDK is a software development kit that enables developers to consume information about the trilogy through an existing Lord of the Rings API. The SDK is designed to provide a simple and intuitive interface for developers to access movie endpoints using Javascript or Typescript.
- [x] Get all movies
- [x] Get movie
- [x] Get movie quote
Using npm:
$ npm i welington-sdk
Using yarn:
$ yarn add welington-sdk
Using pnpm:
$ pnpm add welington-sdk
Once the package is installed, you can import the library using import
or require
approach:
import { getAllMovies, getMovie, getMovieQuote } from "welington-sdk";
If you use require
for importing:
const { getAllMovies, getMovie, getMovieQuote } = require("welington-sdk");
An .env should be set in root with the following variables:
API_URL=https://the-one-api.dev/v2
API_KEY=your-api-key
To get an API key, you need to register at https://the-one-api.dev/sign-up
. After that, you can get your API key.
import { getAllMovie, getMovie, getMovieQuote } from "welington-sdk";
getAllMovie().then((movies) => {/* handle paginated result containing movies */})
getMovie('movie-id').then((movie) => {/* handle result containing the requested movie */})
getMovieQuote('movie-id').then((quotes) => {/* handle result containing movie quotes */})
All requests and responses are typed. The following types are used:
Represents a Movie
.
{
"id": "movie-id",
"name": "The Lord of the Rings Series",
"runtimeInMinutes": 558,
"budgetInMillions": 281,
"boxOfficeRevenueInMillions": 2917,
"academyAwardNominations": 30,
"academyAwardWins": 17,
"rottenTomatoesScore": 94
}
Represents a Quote
.
{
"id": "quote-id",
"dialog": "Deagol",
"movieId": "movie-id",
"characterId": "character-id"
}
Useful for paginated requests. The page
and pageSize
properties are optional. If not provided, the default values are page = 1
and pageSize = 10
.
{
"page": 1,
"pageSize": 10
}
Response from paginated requests. All list requests will return a PageResult
object containing the requested items
.
{
"items": [/*{...}, {...}*/],
"total": 8,
"page": 2,
"pages": 5,
"offset": 0
}
The unit tests execute core logic of the SDK, like the getAllMovies
function. As its proposal, there is no communication with external dependencies, like the API.
To run the unit tests, execute the following command:
$ npm run test:unit
The integration tests verify if external dependencies are working as expected. To run it, configure an .env.test file with the following variables:
Note that the .env.test file should be created in the root folder and if possible with pre-prod environment values. Currently, the API does not have a pre-prod environment, so the .env.test file should be configured with the same values as the .env file. But be caution to execute these tests, because they will consume your API requests.
API_URL='https://the-one-api.dev/v2'
API_KEY='your-api-key'
$ npm run test:int