Skip to content

Commit

Permalink
v0.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
mastashake08 committed Jan 20, 2023
1 parent 9048527 commit a3b68fb
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 86 deletions.
82 changes: 0 additions & 82 deletions classes/Gutendex.js

This file was deleted.

85 changes: 82 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -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 }
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit a3b68fb

Please sign in to comment.