1.1.4 • Published 9 years ago
forismatic-node v1.1.4
An asynchronous client library for Forismatic API.
Installation
npm install forismatic-node
Quick Start
The quickest way to get started is by executing following code:
var forismatic = require('forismatic-node')();
forismatic.getQuote(function (error, quote) {
if (!error) {
console.log(quote);
} else {
console.error(error);
}
});
If everything went well, you'll see something like this in your console:
{
quoteText: 'Ignorance never settle a question.',
quoteAuthor: 'Benjamin Disraeli',
senderName: '',
senderLink: '',
quoteLink: 'http://forismatic.com/en/33ae3b318c/'
}
Documentation
getQuote
Requests random quote.
Options
lang
(default:en
) - Response language (en
orru
).key
(default:undefined
) - Numeric key, which influences the choice of quotation, the maximum length is 6 characters.generateKey
(defaultfalse
) - Determines whether numeric key is auto-generated.
Examples
Requests quote in Russian with manually set key.
forismatic.getQuote({
lang: 'ru',
key: 123456
}, function (error, quote) {
if (!error) {
console.log(quote);
} else {
console.error(error);
}
});
Requests quote in English with auto-generated key.
forismatic.getQuote({
lang: 'en',
generateKey: true
}, function (error, quote) {
if (!error) {
console.log(quote);
} else {
console.error(error);
}
});
Errors
When errors occur, you receive an error object with default properties as a first argument of the callback.
Tests
To run the test suite, first install the dependencies, then run npm test
:
$ npm install
$ npm test
License
Distributed under the MIT License.