Core API

Document Manager

Document manager is responsible for creating, receiving, and deleting documents in the application.

All file manipulation is provided by these methods:

  1. createDocument

  2. getDocument

  3. getDocuments

  4. deleteDocument

createDocument

This method is called for creating a new document in the certain application. It takes object of general document data.

import GudHub from '@gudhub/core';
const authkey = 'kLKKSlfjMmslk;eks;ldfspfk,v';
const gudhub = new GudHub(authkey);

let documentObject = {
    app_id: "24343",
    element_id: "324534",
    item_id: "2324234",
    data: {
        name: "John",
        last_name: "Dow"
    },
}

let createdDocument = gudhub.createDocument(documentObject);
console.log(createdDocument)
Argument Name Type Description
documentObject object contains app_id, field_id, item_id, and data

In response we get the object of the created document:

{
    "_id": "62b9a14990084b1d7bea8dc3",
    "app_id": 24343,
    "element_id": 324534,
    "item_id": 2324234,
    "last_update": 1656332617160,
    "data": "{\"text\":\"John\",\"level\":\"Dow\"}"
}

getDocument

The method for getting needed document from the applications documents list. It takes a desired document location object as an argument.

import GudHub from '@gudhub/core';
const authkey = 'kLKKSlfjMmslk;eks;ldfspfk,v';
const gudhub = new GudHub(authkey);

let documentAddress = {
    app_id: "24343",
    element_id: "324534",
    item_id: "2324234",
};

let gottenDoc = gudhub.getDocument(documentAddress);
console.log(gottenDoc)
Argument Name Type Description
documentAddress object contains app_id, field_id, and item_id

This method returns such object as response:

{
    "_id": "62b9a14990084b1d7bea8dc3",
    "app_id": 24343,
    "element_id": 324534,
    "item_id": 2324234,
    "last_update": 1656332617160,
    "data": "{\"text\":\"John\",\"level\":\"Dow\"}"
}

getDocuments

This method is called to get array of documents from the application. As an argument it takes a array of document locations objects.

import GudHub from '@gudhub/core';
const authkey = 'kLKKSlfjMmslk;eks;ldfspfk,v';
const gudhub = new GudHub(authkey);

let documentsAddresses = [{
    app_id: "24343",
    element_id: "324534",
    item_id: "2324234",
}]

let gottenDocs = gudhub.getDocuments(documentsAddresses);
console.log(gottenDocs)
Argument Name Type Description
documentsAddresses object contains app_id, field_id, and item_id

This method returns an array of document objects:

[{
    "_id": "62b9a14990084b1d7bea8dc3",
    "app_id": 24343,
    "element_id": 324534,
    "item_id": 2324234,
    "last_update": 1656332617160,
    "data": "{\"text\":\"John\",\"level\":\"Dow\"}"
}]

deleteDocument

Due to this method you can delete document from the application.

import GudHub from '@gudhub/core';
const authkey = 'kLKKSlfjMmslk;eks;ldfspfk,v';
const gudhub = new GudHub(authkey);

let deletedDoc = gudhub.deleteDocument(documentAddress);
console.log(deletedDoc)
Argument Name Type Description
documentAddress object contains app_id, field_id, and item_id

Despite the method deletes document, it returns an object of the deleted document:

{
    "_id": "62b9a14990084b1d7bea8dc3",
    "app_id": 24343,
    "element_id": 324534,
    "item_id": 2324234,
    "last_update": 1656332617160,
    "data": "{\"text\":\"John\",\"level\":\"Dow\"}"
}