@zivkaziv/the-one-sdk
v1.0.3
Published
Load Of The Rings sdk base on the-one-api api
Downloads
3
Readme
The-One-SDK
The SDK, implemented in TypeScript, is built upon the One API project, providing seamless access to its functionalities.
Table of Contents
Installation
npm i @zivkaziv/the-one-sdkAuthentication
To utilize the SDK, you must initialize it with your own token, which is obtainable for free from One API.
Initialization
In order to initialize the SDK we require the following data
token- Mandatory - The token of the one apibaseUrl- Optional - Also supportsTHE_ONE_BASE_URLenv param. Default valuehttps://the-one-api.dev/v2logger.logLevel- Optional - log level. Default valueinfologger.prefix- Optional - prefix for each loglevel. Default valuethe-one-sdk
Quick Start
import {Sdk} from '@zivkaziv/the-one-sdk';
const client = new Sdk({
token: '<YOUR_TOKEN_TO_THE_ONE_API>',
});
try {
const movie = await client.movie.getById('5cd95395de30eff6ebccde5c');
const quote = await client.quote.getById('5cd96e05de30eff6ebcce7e9')
}catch (e){
console.error(e);
}
That's it!
Usage
Quote
client.quote.getById(quoteId: string): Promise<Quote>
Retrieves a specific quote based on the provided quoteId.
client.quote.list(params?: RequestParams<Quote>): Promise<Quote[]>
Retrieves a list of quotes based on the optional parameters specified in the params object.
Available params options:
limit: Limits the number of quotes to be retrieved (type: number).offset: Specifies the starting index for pagination (type: number).page: Specifies the page number for pagination (type: number).sort: Sorts the quotes based on a property and direction (type: { [modelProperty: string]: 'asc' | 'desc' }).filters: Filters the quotes based on specific criteria (type: { [modelProperty: string]: { [filterOption: string]: string | number }.filterOptionsuch as "match", "negateMatch", "include", "exclude", "exists", "notExists", "regex", "lessThan", "lessEqualThan", "greaterThan", "greaterEqualThan", and "equal" }).
model
| Field Name | Type |
|------------|--------|
| _id | string |
| dialog | string |
| movie | string |
| character | string |
| id | string |
Movie
client.movie.getById(movieId: string): Promise<Movie>
Retrieves a specific movie based on the provided movieId.
client.movie.list(params?: RequestParams<Movie>): Promise<Movie[]>
Retrieves a list of movies based on the optional parameters specified in the params object.
Available params options:
limit: Limits the number of movies to be retrieved (type: number).offset: Specifies the starting index for pagination (type: number).page: Specifies the page number for pagination (type: number).sort: Sorts the movies based on a property and direction (type: { [property: string]: 'asc' | 'desc' }).filters: Filters the quotes based on specific criteria (type: { [modelProperty: string]: { [filterOption: string]: string | number }.filterOptionsuch as "match", "negateMatch", "include", "exclude", "exists", "notExists", "regex", "lessThan", "lessEqualThan", "greaterThan", "greaterEqualThan", and "equal" }).
client.movie.getQuotesById(movieId: string, params?: RequestParams<Quote>): Promise<Quote[]>
Retrieves quotes associated with a specific movie based on the provided movieId.
Available params options:
limit: Limits the number of quotes to be retrieved (type: number).offset: Specifies the starting index for pagination (type: number).page: Specifies the page number for pagination (type: number).sort: Sorts the quotes based on a property and direction (type: { [property: string]: 'asc' | 'desc' }).filters: Filters the quotes based on specific criteria (type: { [property: string]: { [filterOption: string]: string | number } }).
Model
| Field Name | Type |
|-----------------------------|--------|
| _id | string |
| name | string |
| runtimeInMinutes | number |
| budgetInMillions | number |
| boxOfficeRevenueInMillions | number |
| academyAwardNominations | number |
| academyAwardWins | number |
| rottenTomatoesScore | number |
For additional details you can always read the One API documentations
Tests
In order to run the unit tests
npm installnpm run testYou can see the coverage report that will be created this link
Some Examples
To list all movies:
import {Sdk} from '@zivkaziv/the-one-sdk';
const client = new Sdk({
token: '<YOUR_TOKEN_TO_THE_ONE_API>'
});
const movies = await client.movie.list();limit to 10 results of quotes:
import {Sdk} from '@zivkaziv/the-one-sdk';
const client = new Sdk({
token: '<YOUR_TOKEN_TO_THE_ONE_API>'
});
const quotes = await client.quote.list({
limit: 10
});filter the movies:
import {Sdk} from '@zivkaziv/the-one-sdk';
const client = new Sdk({
token: '<YOUR_TOKEN_TO_THE_ONE_API>'
});
const movies = await client.movie.list({
filters:{
name: {
regex: "the"
},
budgetInMillions: {
greaterThan: 5
}
}
});