@klangoo/magnetapiclient

Magnet API client driver for NodeJS

Stats

StarsIssuesVersionUpdatedCreatedSize
@klangoo/magnetapiclient
021.0.43 years ago4 years agoMinified + gzip package size for @klangoo/magnetapiclient in KB

Readme

This library allows you to easily use the Magnet API via NodeJS.

Table of Contents

About

Magnet offers online publishers and digital content providers with the following features to help them better engage their users on their website and mobile App.

  • Topically Related Articles
  • Personalized Recommendations
  • Automatically Generated Summary
  • Follow a Specific Topic
  • Follow a Developing Story
  • Meta Tags/Description
  • Highlight Named-Entities
  • Entity Listing
  • Entity Pages

Read More.

Book a demo with our sales team now!

Installation

Prerequisites

Install

To use MagnetApiClient in your NodeJS project, you can either download the Magnet API Library directly from our Github repository and reference it in your project or, if you have the Node package manager installed, you can download it automatically by running

$ npm install @klangoo/magnetapiclient

Once you have the Magnet API Client properly referenced in your project, you can start sending calls to the API in your code. For sample implementations, check the news agency sample.

Dependencies

Magnet API Client uses the following Node built in Libraries:

Usage

Get Article

The following is an example for reading an article from the API:

function getArticle(articleUID) {
    let request = {}; //request json object (key / value) will handle all the request parameters.
    request.articleUID = articleUID;
    request.format = "json";
  
    //instance of the magnetapiclient 
    var MagnetAPIClient = require("@klangoo/magnetapiclient");
    var _magnetAPIClient = new MagnetAPIClient(ENDPOINT_URI, CALK, SECRET_KEY);

    try {
        _magnetAPIClient.CallWebMethod("GetArticle", request, "GET", function (data) {

            let parsedResult = JSON.parse(data);

            console.log("GetArticle: ");

            if (parsedResult.status == "OK") {
                console.log("Success", parsedResult);
            }
            else {
                HandleApiError(parsedResult);
            }
        });
    }
    catch (error) {
        console.log("Exception occured: ", error);
    }
}

Add Article

The same applies for posting or updating an article. following is an example for adding an article:

function getArticle(articleUID) {
    let request = {}; //request json object (key / value) will handle all the request parameters.
    request.text = "SAMPLE ARTICLE TEXT";
    request.title = "SAMPLE ARTICLE TITLE";
    request.insertDate = "23 JAN 2017 10:12:00 +01:00"; //article date
    request.url = "http://demo.klangoo.com/article-demo/api-example";
    request.articleUID = articleUID;
    request.source = "klangoo.com";
    request.language = "en";
    request.format = "json";
  
    //instance of the magnetapiclient 
    var MagnetAPIClient =  require("@klangoo/magnetapiclient");
    var _magnetAPIClient = new MagnetAPIClient(ENDPOINT_URI, CALK, SECRET_KEY);

    try {
        _magnetAPIClient.CallWebMethod("addArticle", request, "POST", function (data) {

            let parsedResult = JSON.parse(data);

            console.log("GetArticle: ");

            if (parsedResult.status == "OK") {
                console.log("Success", parsedResult);
            }
            else {
                HandleApiError(parsedResult);
            }
        });
    }
    catch (error) {
        console.log("Exception occured: ", error);
    }
}

You can find an example implementation for all of the API calls here here.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.