-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9048527
commit a3b68fb
Showing
3 changed files
with
83 additions
and
86 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters