knowledge-node

    1.0.0 • Public • Published

    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.

    Parameter Type Required Information
    query String Yes
    limit Number No Default: 20
    indent Boolean No Defaut: true
    types Array[Types] Yes

    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.

    Install

    npm i knowledge-node

    DownloadsWeekly Downloads

    2

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • avatar