diff --git a/classes/Gutendex.js b/classes/Gutendex.js deleted file mode 100644 index c6816c5..0000000 --- a/classes/Gutendex.js +++ /dev/null @@ -1,82 +0,0 @@ -import SpeechKit from '@mastashake08/speech-kit' -class Gutendex { - /* - * Returns a new instance of Gutendex. - * @params {string} baseUrl - the base URL for gutendex API. Defaults to cloud instance - * @returns {Gutendex} - a new instance of Gutendex - */ - - constructor ({ - baseUrl = 'https://gutendex.com/books' - }) { - this.baseUrl = baseUrl - } - - /* - * Returns a new book by ID from Gutenberg database. - * @params {string} baseUrl - the base URL for gutendex API. Defaults to cloud instance - * @returns {object} - ebook metadata JSON object - */ - - async getBook (id) { - try { - const res = await fetch(this.baseUrl + `/${id}`) - return res - } catch (e) { - alert(`${e.name} - ${e.message}`) - } - } - - /* - * Returns a collection of books by ID from Gutenberg database. - * @params {string} baseUrl - the base URL for gutendex API. Defaults to cloud instance - * @returns {array | null} - ebook metadata JSON collection - */ - - async getBooksByIds (ids) { - try { - const res = await fetch(this.baseUrl + `?ids=${ids}`) - return res - } catch (e) { - alert(`${e.name} - ${e.message}`) - } - } - - async getBooksByTopic (topic) { - try { - const res = await fetch(this.baseUrl + `?topic=${topic}`) - return res - } catch (e) { - alert(`${e.name} - ${e.message}`) - } - } - - async getBooksByTerm (term) { - try { - const res = await fetch(this.baseUrl + `?search=${topic}`) - return res - } catch (e) { - alert(`${e.name} - ${e.message}`) - } - } - - async getBooksByMimeType (type) { - try { - const res = await fetch(this.baseUrl + `?mime_type=${type}`) - return res - } catch (e) { - alert(`${e.name} - ${e.message}`) - } - } - - async readBook (id) { - try { - const res = await fetch(this.baseUrl + `/${id}?mime_type=text%2F`) - return res - } catch (e) { - alert(`${e.name} - ${e.message}`) - } - } -} - -export { Gutendex } diff --git a/index.js b/index.js index d707aeb..02a33b3 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,82 @@ -export { - default as Gutendex -} from './classes/Gutendex.js'; +import SpeechKit from '@mastashake08/speech-kit' +export default class Gutendex { + /* + * Returns a new instance of Gutendex. + * @params {string} baseUrl - the base URL for gutendex API. Defaults to cloud instance + * @returns {Gutendex} - a new instance of Gutendex + */ + + constructor ({ + baseUrl = 'https://gutendex.com/books' + }) { + this.baseUrl = baseUrl + } + + /* + * Returns a new book by ID from Gutenberg database. + * @params {string} baseUrl - the base URL for gutendex API. Defaults to cloud instance + * @returns {object} - ebook metadata JSON object + */ + + async getBook (id) { + try { + const res = await fetch(this.baseUrl + `/${id}`) + return res + } catch (e) { + alert(`${e.name} - ${e.message}`) + } + } + + /* + * Returns a collection of books by ID from Gutenberg database. + * @params {string} baseUrl - the base URL for gutendex API. Defaults to cloud instance + * @returns {array | null} - ebook metadata JSON collection + */ + + async getBooksByIds (ids) { + try { + const res = await fetch(this.baseUrl + `?ids=${ids}`) + return res + } catch (e) { + alert(`${e.name} - ${e.message}`) + } + } + + async getBooksByTopic (topic) { + try { + const res = await fetch(this.baseUrl + `?topic=${topic}`) + return res + } catch (e) { + alert(`${e.name} - ${e.message}`) + } + } + + async getBooksByTerm (term) { + try { + const res = await fetch(this.baseUrl + `?search=${topic}`) + return res + } catch (e) { + alert(`${e.name} - ${e.message}`) + } + } + + async getBooksByMimeType (type) { + try { + const res = await fetch(this.baseUrl + `?mime_type=${type}`) + return res + } catch (e) { + alert(`${e.name} - ${e.message}`) + } + } + + async readBook (id) { + try { + const res = await fetch(this.baseUrl + `/${id}?mime_type=text%2F`) + return res + } catch (e) { + alert(`${e.name} - ${e.message}`) + } + } +} + +export { Gutendex } diff --git a/package.json b/package.json index f321141..5ecc850 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gutendex", - "version": "0.0.4", + "version": "0.0.5", "description": "npm package for interacting with the Project Gutenberg ebook metadata catalog using the Gutendex API. Can be sel-hosted or cloud.", "main": "index.js", "scripts": {