README
bunny-wrapper
A promise based wrapper for the Inkbunny API
Installation
npm i bunny-wrapper
or
yarn add bunny-wrapper
Prerequisites
Enable “Enable API Access” in the in your Inkbunny Account Settings https://inkbunny.net/account.php
Authentication
Login
In order to make requests to the API, you need to get an SID by logging in.
Use the method bunny.auth.login
to get a SID.
The function takes 3 parameters:
- username: string
- password: string
- writeFile: boolean (default = false)
Setting writeFile to true
will save the SID to a file called sid.txt which is loaded into the environment varable INKBUNNY_SID
apon the first request to the API.
The function returns a promise which resolves to return the SID. It also automatically assigns it to a runtime varable, so that you don't have to pass the sid with every request.
Here is an example of getting a SID
const bunny = require('bunny-wrapper');
(async ()=>{
try {
const sid = await bunny.auth.login('username', 'password', true);
} catch (error) {
console.error(error)
}
})();
Alternatively you can pass the SID directly in a environment variable
export INKBUNNY_SID=xxxxxxxxxxxxxxxx
Logout
Logging out is easy: use the method bunny.auth.logout
It only takes 1 argument, the SID, which you can get via bunny.SID.get()
. This function also returns a promise which resolves with the SID.
Thus logout as follows:
const bunny = require('bunny-wrapper');
(async ()=>{
try {
await bunny.auth.logout(await bunny.SID.get());
} catch (error) {
console.error(error)
}
})();
Searching
Searches are done using a bunny.Search
object.
The constructor takes the search parameters as a argument. See https://wiki.inkbunny.net/wiki/API#Parameters_4 Search Condition Parameters for the full list of parameters.
Use the fetch method to get the API results. The method automatically pages through all the results and assembles it into an object. It returns a promise which resolves with an object.
interface SearchResults {
raw: any[],
submissions: bunny.Submissions
}
The raw property contains the raw submission data as an array of submissions.
The submission property returns a bunny.Submissions
object, which you can use to get the details of the submissions in the search. Do this with ```bunny.Submissions.fetch()`` which returns a promise which resolves an array of the submission data returned by the API.
Example of getting all file names under a certain pool_id
const bunny = require('bunny-wrapper');
new bunny.Search({ pool_id: 'xxxx' }).fetch()
.then(dat=>{
dat.submissions.fetch()
.then(data => {
data.forEach(sub=>{
sub.files.forEach(file=>console.log(file.file_url_full));
})
})
.catch(console.error);
})
.catch(console.error);