biocv-api-js
v1.2.3
Published
A programming Interface to integrate the services of the BioCV System.
Downloads
7
Readme
LiSA NodeJS API
LiSA NodeJS API
Overview
LiSA Access Module provides a streamlined way to interact with the BioCV System for specific data retrieval and management tasks. It's designed for ease of use and quick integration with existing projects. The complete API is built on a single animal approach.
Features
- Initialization: Set up LiSA access with custom tokens.
- Data Retrieval: Fetch eartags associated with a given user.
- Real-time Updates: Subscribe to real-time updates of eartags.
Installation
To install the LiSA Firestore Access Module, follow these steps:
- Ensure you have Node.js installed on your system.
- Clone the repository or download the module.
- Navigate to the module directory and run
npm installto install dependencies.
Usage of the main API
Import the module and use the provided functions to interact with Firestore:
const lisa = require("biocv-api-js");
// Initialize with a custom token
await lisa.init("your_custom_token");
// Retrieve all eartags for the logged-in user
const eartags: Eartag[] = await lisa.getEartags();
console.log("Retrieved eartags:", eartags);
// Get details of a specific eartag by ID
const eartagDetails: Eartag | null = await lisa.getEartag("eartag_id");
console.log("Eartag details:", eartagDetails);
// Subscribe to real-time updates of eartags
lisa.subEartags((updatedEartags: Eartag[]) => {
console.log("Real-time update received. Updated eartags:", updatedEartags);
});API Reference
Classes
This section prvides you with a structered overview of all used classes, used in the API.
Eartag
The Eartag class represents an eartag with various properties related to its status and metrics.
| Variable | Type | Description |
| --------------------- | ------- | -------------------------------------------------- |
| ID | string | The unique identifier for the eartag. |
| MAC | string | The MAC address of the eartag. |
| Active | boolean | Indicates whether the eartag is active. |
| CurrentActivity | string | The current activity status. |
| CurrentTemperature | number | The current temperature reading from the eartag. |
| DailyActivity | string | The daily activity level. |
| Group | string | The group or category to which the eartag belongs. |
| HeatProbability | number | Probability or likelihood of heat. |
| BirthProbability | number | Probability or likelihood of birth. |
| LamenessProbability | number | Probability or likelihood of lameness. |
| HealthScore | number | A numeric value representing the health status. |
| Battery | number | The battery level of the eartag. |
Functions
Import the module and use the provided functions to interact with Firestore:
init(token: string): Promise<void>
Initialize LiSA access. This function needs to be called before any calls to the database.
- Parameters:
token(string): The custom token for authentication.
- Returns:
Promise<void>- A promise that resolves when the initialization is successful.
getEartags(): Promise<Eartag[]>
Get all eartags of a given user.
- Returns:
Promise<Eartag[]>- A promise that resolves to an array of Eartag objects.
getEartag(id: string): Promise<Eartag | null>
Get one specific eartag by ID.
- Parameters:
id(string): The ID of the eartag.
- Returns:
Promise<Eartag | null>- A promise that resolves to the Eartag object or null if not found.
subEartags(callback: (eartags: Eartag[]) => void): void
Subscribe to real-time updates of eartags collection for the current user.
- Parameters:
callback(function): Function to call with the updated eartags array.
Dev Notes
The following section is only for contributng developers.
Test
To test the library, please follow these steps:
Build the Library: Ensure that the library is built and ready for use.
npm run build npm link cd test npm link biocv-api-js npm run test-script
