isbndb-client
Version:
A TypeScript client library for the ISBNdb API
102 lines (101 loc) • 3.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IsbndbService = void 0;
/**
* A typed wrapper for the ISBNdb v2 API.
*
* Instantiate using:
* ```ts
* const client = createIsbndbClient('API_KEY', 'PRO');
* const isbndb = new IsbndbService(client);
* ```
*/
class IsbndbService {
constructor(client) {
this.client = client;
}
/**
* Fetch book details by ISBN-10 or ISBN-13.
*/
getBook(isbn, withPrices) {
return this.client.get(`/book/${isbn}`, {
params: withPrices ? { with_prices: "1" } : undefined,
});
}
/**
* Search for books by keyword and optional filters.
*/
searchBooks(query, options) {
const hasParams = options && Object.keys(options).length > 0;
return this.client.get(`/books/${encodeURIComponent(query)}`, {
...(hasParams ? { params: options } : {}),
});
}
/**
* Fetch author details and book list by author name.
*/
getAuthor(name, options) {
const hasParams = options && Object.keys(options).length > 0;
return this.client.get(`/author/${encodeURIComponent(name)}`, {
...(hasParams ? { params: options } : {}),
});
}
/**
* Search authors by name.
*/
searchAuthors(query, options) {
const hasParams = options && Object.keys(options).length > 0;
return this.client.get(`/authors/${encodeURIComponent(query)}`, {
...(hasParams ? { params: options } : {}),
});
}
/**
* Fetch publisher details and book list by publisher name.
*/
getPublisher(name, options) {
const hasParams = options && Object.keys(options).length > 0;
return this.client.get(`/publisher/${encodeURIComponent(name)}`, {
...(hasParams ? { params: options } : {}),
});
}
/**
* Search publishers by query.
*/
searchPublishers(query, options) {
const hasParams = options && Object.keys(options).length > 0;
return this.client.get(`/publishers/${encodeURIComponent(query)}`, {
...(hasParams ? { params: options } : {}),
});
}
/**
* Fetch a subject and its parent.
*/
getSubject(name) {
return this.client.get(`/subject/${encodeURIComponent(name)}`);
}
/**
* Search subjects by query.
*/
searchSubjects(query, options) {
const hasParams = options && Object.keys(options).length > 0;
return this.client.get(`/subjects/${encodeURIComponent(query)}`, {
...(hasParams ? { params: options } : {}),
});
}
/**
* Perform a general search across one of the supported indexes.
*/
searchIndex(index, options) {
const hasParams = options && Object.keys(options).length > 0;
return this.client.get(`/search/${index}`, {
...(hasParams ? { params: options } : {}),
});
}
/**
* Retrieve general stats about the ISBNdb database.
*/
getStats() {
return this.client.get(`/stats`);
}
}
exports.IsbndbService = IsbndbService;