1.0.0 • Published 11 months ago

haryells-lotr-sdk v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

Lord of the Rings SDK

Overview

Lord of the Rings SDK is a easy way to conume the resources from the The One API from wherever Node application you are working on.


Instalation

To install this SDK on your project just run the following command:

npm i @haryells/lotr-sdk

Example usage

// Import the lib
const TOAClient = required('@haryells/lotr-sdk');

// Initialize the client passing your customer token from The One API. Follow this documentation to get one token: (https://the-one-api.dev/documentation#3)
const client = new TOAClient("YOUR_THE_ONE_API_TOKEN");

// Call the listMovies method to get all movies from the API.
const response = await client.listMovies();

// Extract the movies from the response
const movies = response.docs;

Getting Started

Before you start to use the SDK, please make sure you have a Access token from The One API. Please follow the documentation to get one.

Methods

.listMovies()

Return all the movies from the API. It can be paginated and filtered though params.

INPUT PARAMETERS | param | required | type | description | |---|---|---|---| | options | false | Object | Options to be used when get the list of the movies. | | options.limit | false | Integer | Number of results to be returned. The default value will only be used if the param page is informed. Default value: 0. | | options.page | false | Integer | Number of the page to be returned. The default value will only be used if the param limit is informed. Default value: 1 | | options.search | false | Array | List of search objects, used to filter the movies to be returned. More information about search options see this documentation | | options.search.field | false | String | Field to be filtered. | | options.search.operation | false | String | The filter operation. Possible values: =, !=, >, <, >=, <=, exists and !exists. | | options.serach.value | false | String | The filtered value. |

.getMovieById()

Return the movie data by it's Id.

INPUT PARAMETERS | param | required | type | description | |---|---|---|---| | id | true | String | The Id of the movie. |

.listQuotesByMovieId()

List all quotes from a movie. You can paginate the result using the params.

INPUT PARAMETERS | param | required | type | description | |---|---|---|---| | movieId | true | String | The ID of the movie. | options | false | Object | Options to be used when get the list of the quotes. | | options.limit | false | Integer | Number of results to be returned. The default value will only be used if the param page is informed. Default value: 0. | | options.page | false | Integer | Number of the page to be returned. The default value will only be used if the param limit is informed. Default value: 1 |

.listQuotes()

List all quotes from all movies. You can paginate and filter the result using the params.

INPUT PARAMETERS | param | required | type | description | |---|---|---|---| | options | false | Object | Options to be used when get the list of the quotes. | | options.limit | false | Integer | Number of results to be returned. The default value will only be used if the param page is informed. Default value: 0. | | options.page | false | Integer | Number of the page to be returned. The default value will only be used if the param limit is informed. Default value: 1 | | options.search | false | Array | List of search object, used to filter the quotes to be returned. More information about search options see this documentation | | options.search.field | false | String | Field to be filtered. | | options.search.operation | false | String | The filter operation. Possible values: =, !=, >, <, >=, <=, exists and !exists. | | options.serach.value | false | String | The filtered value. |

.getQuoteById()

Return de details of a Quote by it's ID.

INPUT PARAMETERS | param | required | type | description | |---|---|---|---| | id | true | String | The Id of the Quote. |


Responses

The response object are the default response from the API tha follows the uppcomming pattern:

{
    "docs": [
        ...
    ], // Object(s) returned for the request, it is alwas an Array of Objects, even when calling to get an registry by it ID.
    "total": 1, // Total of registers founds
    "limit": 1000, // Max of registers returneds
    "offset": 0, // Registers skippeds, for pagination purpose.
    "page": 1, // Current page returned.
    "pages": 1 // Total of pages.
}

Error

The SDK throw exception errors with if there is missing params or if there is API problems. If you wan't you can treat this errors with try {} catch() {};:

// Import the lib
const TOAClient = required('@haryells/lotr-sdk');
try {
    // Initialize the client without a token.
    const client = new TOAClient();
} catch (error) {
    // It will throw a error with the message "Token is required.".
}

Test

To run the unit test first go to the file ./test/TOAClient.test.js and place your Access Token from the The One API in the line 2:

const token = null; // Place your The One API Token here

Then run the command to start the test:

npm run test

License

ISC

1.0.0

11 months ago