berea
v1.0.1
Published
A promise-wrapped library and ORM for using https://scripture.api.bible
Downloads
25
Maintainers
Readme
Berea
A Promised-wrapped Node library and ORM for https://scripture.api.bible/.
This includes a bibleService
which is a promised-wrapped library for the API with some convenience methods.
But it also includes an ORM that turns data into Bible
, Book
, Chapter
, Verse
, and Passage
objects that have their own convenience methods and relations for easier navigation of scripture.
Pre-requisites
- Node 12+
- NPM 6.14.12
API Token from Scripture.API.Bible
- go to https://scripture.api.bible
- Sign up
- Go to Applications
- Create a new application
- After it's created you will need the credentials
Usage
This is thoroughly documented via JSDoc and a Github Wiki
Using the API and this library amounts to three steps:
- Create the Bible Service
- Use the Bible service to get the id for a Bible
- Do stuff with a Bible id
The Bible Id that you get is needed to get any data from the API. For this reason, there exists a whole ORM that you can use which turns books, chapters, verses, and passages into objects that let you request data when you want it.
But you can't get there until you have at least a service.
Creating a new Bible Service
You may want multiple services if you plan on using different versions of the api, or fetching text and audio.
Basic Example
const {BibleService} = require('berea');
const service = new BibleService('someLongToken');
Setting a Version
As the API itself is version controlled, the library is too. This is an optional second parameter:
const {BibleService} = require('berea');
const service = new BibleService('someLongToken', 1);
Setting the medium
The Bible API itself offers text and audio. As you may want one over the other, this is an optional third parameter. The options are text
or audio
.
const {BibleService} = require('berea');
const service = new BibleService('someLongToken', 1, 'audio');
Setting options in requests
All of the request options are documented. One notable difference between how this library works is that options can be camelCased.
While the API will require content-type
if you want to set options, you can send contentType
.
Look in src/constants/requestParameters.js
for all of the aliases. RequestParameters
is also set as a static property on the BibleService
class.
Getting Bibles
Before getting verses, chapters, or passages, you need a bibleId
. The only way to know that is to look at all of the Bibles, first.
Get all Bibles
- Request Options ( an array)
async function doThings() {
const bibles = await service.getBibles();
}
Get Bibles with options
- Response (an array)
async function doThings() {
const bibles = await service.getBibles({
language: 'eng'
});
}
Get One Bible
- Response
- Request: only a string
Once you've found a bibleId
, you can get some information on it.
async function doThings() {
const bible = await service.getBible('06125adad2d5898a-01');
}
Getting Books
About bookId
:
A bookId
is typically the first 3-letters of the name of a book.
e.g.
- Exodus => EXO
- Mark => MAR
Get all books from a Bible (no options)
- Request Options
- Response (an array)
- A Single parameter can be passed, an object, containing
id
forbibleId
with additional options. Here, all that's passed is thebibleId
as a string.
async function doThings() {
const books = await service.getBooks('06125adad2d5898a-01');
}
Get all books from a Bible (with options)
- Request Options
- Response (an array)
- A Single parameter can be passed, an object, containing
id
forbibleId
with additional options.includeChapters
is an option that's passed in.
async function doThings() {
const books = await service.getBooks({
id: '06125adad2d5898a-01'
includeChapters: true,
});
}
Getting Chapters
About chapterId
:
- Take the three-letter abbrevation ( EXO)
- Add a
.
- Then add the number
e.g.
- Exodus 1 => EXO.1
- Mark 8 => MAR.8
Get all chapters from a book
- Request Options
- Response (an array)
- A Single parameter can be passed, an object, containing
id
forbibleId
andbookId
with additional options.
async function doThings() {
const exodusChapters = await service.getChaptersFromBook('c315fa9f71d4af3a-01', 'EXO');
}
Get one chapter
- Request Options
- Response
- A Single parameter can be passed, an object, containing
id
forbibleId
andchapterId
with additional options.
async function doThings(){
const chapter = service.getChapter('c315fa9f71d4af3a-01', 'EXO.1');
}
Getting Verses
About verseId
:
- Take the
chapterId
( EXO.1) - Add a
.
- Then add the number
e.g.
- Exodus 1:1 => EXO.1.1
- Mark 8:8 => MAR.8.8
Get all verses from a chapter
- Response (as array)
Note that this will not give you the content of the verses. It may be useful, however, in getting verseId
s
async function doThings(){
const chapter = service.getVersesFromChapter('c315fa9f71d4af3a-01', 'EXO.1');
}
Get one verse
- Request Options
- Response
- A Single parameter can be passed, an object, containing
id
forbibleId
andverseId
with additional options.
Note that This only returns one verse, for multiples you want a passage.
async function doThings(){
const chapter = service.getVerse('c315fa9f71d4af3a-01', 'EXO.1.1');
}
Get Range of verses
Note: This is an alias for getPassage()
async function doThings(){
const chapter = service.getPassage('c315fa9f71d4af3a-01', 'EXO.1.1-EXO.1.20');
}
Getting Passages
About verseId
:
- Take the
verseId
( EXO.1.1) - Add a
-
- Then add the
verseId
for the last verse
e.g.
- Exodus 1:1-20 => EXO.1.1-EXO.1.20
- Mark 8:8-14 => MAR.8.8-MAR.8.14
Get one passage
- Request Options
- Response
- A Single parameter can be passed, an object, containing
id
forbibleId
andpassageId
with additional options.
async function doThings(){
const chapter = service.getPassage('c315fa9f71d4af3a-01', 'EXO.1.1-EXO.1.20');
}