Giter Site home page Giter Site logo

frane_cagalj-sdk's Introduction

The One (The Lord of the Rings) API SDK for TypeScript

Introduction

A TypeScript SDK for The One (The Lord of the Rings) API. This library is built with TypeScript developers in mind, but it also works with JavaScript.

Features

  • Full type information for requests and responses
  • OAuth2 support
  • Supports Node.js 18+. Doesn't work in browser environments due to the The One (The Lord of the Rings) API not supporting CORS

Installing

npm install the-lord-of-the-rings-api-ts-sdk

Client

To set up the client you need to authenticate with authentication token

import { Client } from "the-lord-of-the-rings-api-ts-sdk";

const client = new Client({ auth: 'MY-BEARER-TOKEN' });

Examples

Listing movies

import { Client } from "the-lord-of-the-rings-api-ts-sdk";

const client = new Client({ auth: ACCESS_TOKEN });

const moviesRes = await client.listMovies();

if (!('docs' in moviesRes)) {
    throw new Error(moviesRes.body.message);
}

const movies = moviesRes.docs;

Getting a movie

import { Client } from "the-lord-of-the-rings-api-ts-sdk";

const client = new Client({ auth: ACCESS_TOKEN });

const movieRes = await client.getMovie({ movieId: movies[0]._id });

if (!('_id' in movieRes)) {
    throw new Error(movieRes.body.message);
}

console.log(`Movie: ${movieRes.name} (${movieRes.budgetInMillions} M$)`);

Getting a movie quotes

import { Client } from "the-lord-of-the-rings-api-ts-sdk";

const client = new Client({ auth: ACCESS_TOKEN });

const quotesRes = await client.getMovieQuotes({ movieId: movieRes._id });

if (!('docs' in quotesRes)) {
    throw new Error('No movies to list');
}

const quotes = quotesRes.docs;

Sorting

Pass the sort parameter to the queryParameters method to sort the results.

import { Client } from "the-lord-of-the-rings-api-ts-sdk";
    
const client = new Client({ auth: ACCESS_TOKEN });

    
const moviesRes = await client.listMovies({ sort: 'name:desc' });

Filtering

Filter results by passing the value to any available key parameter to the queryParameters.

import { Client } from "the-lord-of-the-rings-api-ts-sdk";
    
const client = new Client({ auth: ACCESS_TOKEN });

    
const moviesRes = await client.listMovies({ name: 'hobbit' });

Pagination

You can paginate results by passing the limit, page and offset parameter to the queryParameters method.

import { Client } from "the-lord-of-the-rings-api-ts-sdk";
    
const client = new Client({ auth: ACCESS_TOKEN });

const moviesRes = await client.listMovies({
    queryParameters: { page: '2', offset: '3' },
});

Contributing

Live development

npm run build:watch

Building

npm run build

Testing

npm run test

frane_cagalj-sdk's People

Contributors

fcagalj avatar

Stargazers

Roman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.