Skip to content

Latest commit

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

knowledge-node

Simple Node.js module for Google Graph Knowledge API.

Module Usage

Types

Returns all possible types to build search parameters.

Example

constKnowledge=require('knowledge-node')({serverKey: '<Your Google Server Key>'});constallTypes=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
typesArray[Types]Yes

Example

constKnowledge=require('knowledge-node')({serverKey: '<Your Google Server Key>'});constquery='Harry Potter';consttypes=[Knowledge.types.book,Knowledge.types.bookSeries];constlimit=5;constindent=true;constparameters=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

constKnowledge=require('knowledge-node')({serverKey: '<Your Google Server Key>'});constquery='Harry Potter';consttypes=[Knowledge.types.book,Knowledge.types.bookSeries];constparams=Knowledge.buildParams(query,types);returnKnowledge.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.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages