Парсер курсов
Here's the revised documentation with brief explanations of the properties, without the comments:
Parser Integration Documentation
This document outlines the structure and key components required to integrate a parser into the system.
File Structure
Your parser should be organized in the following directory structure:
configure.js
: Configuration file to set up the parser.icon.png
: An icon representing the parser.index.js
: The main implementation of the parser.
Configuration (configure.js
)
configure.js
)The configure.js
file is used to define the parser's setup. It should export an object with the following structure:
Properties:
title
: The display name of the parser.name
: A unique identifier for the parser, typically in lowercase and snake_case.defaultInterval
: The default time interval (in milliseconds) at which the parser fetches data.isActiveDefault
: A boolean indicating whether the parser is active by default when initialized.extra
: An object for any additional settings such as API keys, currencies, or other specific parameters required by the parser.
Icon (icon.png
)
icon.png
)The icon.png
file should be a PNG image with a minimum size of 150x150 pixels. This icon will represent your parser in the user interface.
Implementation (index.js
)
index.js
)The index.js
file contains the core logic of your parser. Below are the key methods that should be implemented:
Constructor
The constructor is responsible for initializing the parser with the necessary configurations and options.
Parameters:
config
: An object containing configuration details like the parser's name, title, default interval, and extra settings such as API keys.options
: An object that may include anemitter
for event-based data processing or acallback
for direct function-based processing.
updateRate
Method
updateRate
MethodThe updateRate
method fetches the latest data from an external API, processes it, and then either emits the data through an event emitter or returns it via a callback function.
Key Responsibilities:
Fetch data from the API using the
apiRequest
method.Process the data, including calculations like exchange rates.
Format the data into a consistent structure
({ from, to, buy })
and create data objectsrate1
Emit or return the processed data
rate1
using theemitter
orcallback
provided in the options.Optional: Reverse the exchange rate if the API provides only one-way rates.
Return an array of processed data objects.
apiRequest
Method
apiRequest
MethodThe apiRequest
method handles communication with the external API to retrieve the necessary data.
Key Responsibilities:
Send an HTTP request to the API endpoint.
Handle the response and format the data.
Manage errors, ensuring that descriptive messages are provided if the request fails.
Example Implementation
Testing
To test the parser, you can instantiate it and call the updateRate
method:
Notes
Unique Directory Name: Ensure that each parser has a unique directory name.
Default States: Always define a default interval and active state (
isActiveDefault
) in the configuration.Title and Name: Both
title
andname
fields in the configuration are mandatory and must be unique.Icon: Use a distinct icon for each parser to avoid confusion in the UI.
Last updated