1.2.1 • Published 1 year ago

@loama18/eduardolopez-sdk v1.2.1

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

Lord Of The Rings JS Library

The Lord Of The Rings (LOTR) JS Library provides convenient access to the LOTR API from applications written in Javascript (or typescript), both server and client side.

Installation

Install the package with

npm i @loama18/eduardolopez-sdk

Usage

The package needs to be configured with your account's secret key, which is available in the LOTR API Account Page, sign up for free if you haven't already, to get an API Key. Otherwise you will only be able to access the book endpoints.  


 

Require it with the key's value:

const LOTR = require("@loama18/eduardolopez-sdk");

LOTR.setup("<your-key>"); // replace <your-key> for the key you got

// do the actual call to get info, in this case for books
LOTR.get("book")
  .then((res: any) => {
    console.log(res);
  })
  .catch((e: any) => {
    console.log(e.response.data);
  });

 

Or using ES modules and async/await::

import LOTR from "@loama18/eduardolopez-sdk";

LOTR.setup("<your-key>"); // replace <your-key> for the key you got

(async () => {
  const book = await LOTR.get("book");

  console.log(book);
})();

depending on your environment, you might need to replace LOTR.setup with LOTR.default.setup

 

 

Which routes are available?

All routes that you can find in LOTR API docs are also available here, with the LOTR.get(<endpoint>) method.

Complete List

EndpointResponseToken required
bookList of all "The Lord of the Rings" booksno
/book/{id}Request one specific bookno
book/{id}/chapterRequest all chapters of one specific bookno
movieList of all movies, including the "The Lord of the Rings" and the "The Hobbit" trilogiesyes
movie/{id}Request one specific movieyes
movie/{id}/quoteRequest all movie quotes for one specific movie (only working for the LotR trilogy)yes
characterList of characters including metadata like name, gender, realm, race and moreyes
character/{id}Request one specific characteryes
character/{id}/quoteRequest all movie quotes of one specific characteryes
quoteList of all movie quotesyes
quote/{id}Request one specific movie quoteyes
chapterList of all book chaptersyes
chapter/{id}Request one specific book chapteryes

 

GraphQL

You can also use graphQL to query the API, doing something like this

LOTR.graphQL(<query>)

In there, you have access to every single point of data in the API at the same time.

To get all the data in the API at once you would do something like this:

LOTR.graphQL(
  `{
  book {
    _id,
    name,
    chapter {
      _id,
      chapterName
    }
  },
  chapter {
    _id,
    chapterName,
    book
  },
  character {
    _id,
    height,
    race,
    gender,
    birth,
    spouse,
    death,
    realm,
    hair,
    name,
    wikiUrl
  },
  movie {
    _id,
    name,
    runtimeInMinutes,
    budgetInMillions,
    boxOfficeRevenueInMillions,
    academyAwardNominations,
    academyAwardWins,
    rottenTomatoesScore,
    quote {
      _id,
      dialog,
      movie,
      character,
      id
    }
  }
  quote {
    _id,
    dialog,
    movie,
    character,
    id
  }
}`
)
  .then((res) => {
    console.log(res);
  })
  .catch((e) => {
    console.log(e);
  });

This is an extreme case, feel free to remove whatever fields that you don't require, to make the request faster and smaller.

Note that from within movie you are able to request the quotes that belong to that movie, same thing for books, you are able to request their belonging chapters.

LOTR.graphQL(`{
  book {
    _id,
    name,
    chapter {
      _id,
      chapterName
    }
  }
}`);

 

Caching

By default, the SDK will cache the responses of each call made, it is setup to last 1 hour, so you might notice considerably faster responses after the first call within the same hour.

If you are running it from Node, it will use cachios.

If you are running it from the Browser (most likely with something like Vue or React), it will use axios-cache-adapter

 

Test

Run

npm run test

 

Pending To Do for next release:

  • Make character/quotes available directly in GraphQL
  • Add ability to paginate, slice and filter with GraphQL like:

      movies(first:2) {
        _id,
        name
      }
    
      // or
    
      movies(id: "5cd95395de30eff6ebccde57") {
        _id,
        name
      }
1.2.1

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago