Skip to content

Commit 8eabe7f

Browse files
authored
Merge pull request #71 from veryfi/cursor/add-any-document-tags-2f79
2 parents e6779b8 + f9d596d commit 8eabe7f

5 files changed

Lines changed: 65 additions & 0 deletions

File tree

lib/anydocs/getAnyDocumentTags.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const Client = require('../client/constructor');
2+
/**
3+
* Return all tags assigned to a specific any document. https://docs.veryfi.com/api/anydocs/get-A-doc-tags/
4+
*
5+
* @memberof Client
6+
* @param {number} document_id The unique identifier of the document.
7+
* @param {Object} kwargs Additional request parameters
8+
* @returns {JSON} List of tags assigned to a specific any document.
9+
*/
10+
Client.prototype.get_any_document_tags = async function (document_id, {...kwargs} = {}) {
11+
let endpoint_name = `/any-documents/${document_id}/tags/`;
12+
let request_arguments = {};
13+
let response = await this._request("GET", endpoint_name, request_arguments, kwargs, false);
14+
return response['data'];
15+
}

lib/client/client.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const Client = require('../client/function');
22
require('../anydocs/deleteAnyDocument');
33
require('../anydocs/getAnyDocument');
4+
require('../anydocs/getAnyDocumentTags');
45
require('../anydocs/getAnyDocuments');
56
require('../anydocs/processAnyDocument');
67
require('../anydocs/processAnyDocumentBase64');

lib/types/Client.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,16 @@ export declare class Client {
317317
confidence_details?: boolean,
318318
{...kwargs}?: VeryfiExtraArgs): Promise<JsonObject>;
319319

320+
/**
321+
* Return all tags assigned to a specific any document. https://docs.veryfi.com/api/anydocs/get-A-doc-tags/
322+
* @memberof Client
323+
* @param {number} document_id The unique identifier of the document.
324+
* @param {Object} kwargs Additional request parameters
325+
* @returns {Promise<{tags: Tag[]}>} List of tags assigned to a specific any document.
326+
*/
327+
public get_any_document_tags(document_id: number,
328+
{...kwargs}?: VeryfiExtraArgs): Promise<{tags: Tag[]}>;
329+
320330
/**
321331
* Process any document and extract all the fields from it. https://docs.veryfi.com/api/anydocs/process-%E2%88%80-doc/
322332
* @example

test/main.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,31 @@ describe('Processing any documents', () => {
377377
}
378378
});
379379

380+
test('Get any document tags', async () => {
381+
try {
382+
if (mock_responses) {
383+
const mockResponse = require('../mocks/getTags.json');
384+
veryfi_client._request = jest.fn().mockResolvedValue(mockResponse);
385+
}
386+
const doc_id = 4559535;
387+
let response = await veryfi_client.get_any_document_tags(doc_id);
388+
expect(response.tags).toBeDefined();
389+
expect(response.tags.length).toBeGreaterThan(0);
390+
expect(response.tags[0].name).toBeDefined();
391+
if (mock_responses) {
392+
expect(veryfi_client._request).toHaveBeenCalledWith(
393+
"GET",
394+
`/any-documents/${doc_id}/tags/`,
395+
{},
396+
{},
397+
false
398+
);
399+
}
400+
} catch (error) {
401+
throw new Error(error);
402+
}
403+
});
404+
380405
test('Process any document from file_path', async () => {
381406
try {
382407
if (mock_responses) {

tests/main.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,20 @@ describe('Processing any documents', () => {
511511
}
512512
});
513513

514+
test('Get any document tags', async () => {
515+
try {
516+
if (mock_responses) {
517+
return assert(true)
518+
}
519+
let docs = await veryfi_client.get_any_documents();
520+
const doc_id = docs.results[0].id;
521+
let response = await veryfi_client.get_any_document_tags(doc_id);
522+
expect(response.tags).toBeDefined();
523+
} catch (error) {
524+
throw new Error(error);
525+
}
526+
});
527+
514528
test(`Get any doc with id `, async () => {
515529
try {
516530
if (mock_responses) {

0 commit comments

Comments
 (0)