1.0.0 • Published 7 years ago

knowledge-node v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

knowledge-node

Simple Node.js module for Google Graph Knowledge API.

Module Usage

Types

Returns all possible types to build search parameters.

Example

const Knowledge = require('knowledge-node')({ serverKey: '<Your Google Server Key>' });

const allTypes = Knowledge.types;

console.log(allTypes);

//"types": {
//    "book": "Book",
//    "bookSeries": "BookSeries",
//    "educationalOrganization": "EducationalOrganization",
//    ...
//}

Build Parameters

Builds parameter object to be used on search request.

ParameterTypeRequiredInformation
queryStringYes
limitNumberNoDefault: 20
indentBooleanNoDefaut: true
typesArrayTypesYes

Example

const Knowledge = require('knowledge-node')({ serverKey: '<Your Google Server Key>' });

const query = 'Harry Potter';
const types = [
    Knowledge.types.book,
    Knowledge.types.bookSeries
];
const limit = 5;
const indent = true;

const parameters = Knowledge.buildParams(query, types, limit, indent);

//{
//    "query": "Harry Potter",
//    "limit": 5,
//    "indent": true, 
//    "key": "<Google API Key>",
//    "types": [
//        "Book",
//        "BookSeries"
//    ]
//}

Search

Makes search request to Google Knowledge API. You must define correctly the search parameters: please read Build Parameters section.

For more extensive information about errors and successful body response, please read Google Knowledge Graph API Documentation.

Example

const Knowledge = require('knowledge-node')({ serverKey: '<Your Google Server Key>' });

const query = 'Harry Potter';
const types = [
    Knowledge.types.book,
    Knowledge.types.bookSeries
];

const params = Knowledge.buildParams(query, types);
return Knowledge.search(params)
                .then(body => {
                    //do something with success response
                })
                .catch(error => {
                    //handle error
                });

Test

First you should follow the Google Knowledge Graph Search API Prerequisites, so you have your Google Account setup.

Edit ./test/fixtures/auth.json file and add your Google Server Key. Install the dev dependencies and run the tests:

$ npm install
$ npm test

License

Licensed under the MIT License.