UNPKG

torrent-api-ts

Version:

[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) [![Build Status](https://travis-ci.org/Belphemur/torrent-api-ts.svg?branch=master)](https

65 lines (64 loc) 2.18 kB
import { SearchCategory, SearchParams } from './Request/SearchParams'; import { TorrentCollection } from './Torrent/Torrent'; export default class TorrentSearch { private _appName; private _userAgent; private _token; private _queue; private _endpoint; /** * The search object * @param {string} appName needed TorrentApi to identify the client * @param {string} userAgent in case the one we set stop workin (chrome vers. 60) * @param {string} endpoint if the end point change and we didn't update fast enough, you can change it here */ constructor(appName: string, userAgent?: string, endpoint?: string); /** * Change delay between each request * * Only change this if you know what you're doing * @param {number} value */ delayBetweenRequests: number; /** * Advanced search with possibility to set all the different parameters * @param {SearchParams} search * @returns {Promise<TorrentCollection>} */ searchAdvanced(search: SearchParams): Promise<TorrentCollection>; /** * Search and in which category * @param {string} search * @param {SearchCategory} category * @returns {Promise<TorrentCollection>} */ search(search: string, category: SearchCategory): Promise<TorrentCollection>; /** * Ensure we have a valid token to do requests on their API * @returns {Promise<Token>} */ private ensureToken(); /** * Do request on the api * @param {RequestParams} params * @returns {Promise<T>} * @private */ private _request<T>(params); /** * The API is rate limited, be sure to only do the request in the right time to avoid hitting the rate limiting * @param {RequestParams} params * @returns {Promise<T>} * @private */ private _delayedRequest<T>(params); /** * Set all the query parameters for the request * * Check also for token expired * @param {RequestParams} params * @returns {Promise<T>} * @private */ private _processRequest<T>(params); }