Rules
opengate_data.rules.rules
RulesBuilder
RulesBuilder Objects
Rules builder
with_organization_name
Specify the organization name.
Arguments:
organization_namestr - The name of the organization.
Returns:
RulesBuilder- Returns self for chaining.
Example:
with_identifier
Specify the identifier for the rule.
Arguments:
identifierstr - The identifier for the rules.
Returns:
RulesBuilder- Returns self for chaining.
Example:
with_actions
Specify the actions in rules.
Arguments:
actionsdict - Actions
Returns:
RulesBuilder- Returns self for chaining.
Example:
with_actions_delay
Waiting threshold before actions are executed. Allows cancellation of the execution of actions if another rule exists with a subsequent delay cancellation action.
Arguments:
actions_delayint - Delay option in milliseconds
Returns:
RulesBuilder- Returns self for chaining.
Example:
with_active
Specify the active in rules.
Arguments:
activebool - Activate or deactivate action
Returns:
RulesBuilder- Returns self for chaining.
Example:
with_channel
Specify the channel in rules.
Arguments:
channelstr - Channel
Returns:
RulesBuilder- Returns self for chaining.
Example:
with_condition
Specify the condition for the rule. Mandatory for EASY mode and not applicable for ADVANCED mode. JSON filter which follows the same filter structure of the Opengate platform. It can contain rule parameters.
Arguments:
conditiondict - Specify the identifier for the rule.
Returns:
RulesBuilder- Returns self for chaining.
Example:
with_mode
Specify rule type mode
Arguments:
modestr - Advanced or basic.
Returns:
RulesBuilder- Returns self for chaining.
Example:
with_name
Specify the name for the rule.
Arguments:
namestr - The identifier for the rules.
Returns:
RulesBuilder- Returns self for chaining.
Example:
with_description
Specify the description.
Arguments:
descriptionstr - The description for the rules.
Returns:
RulesBuilder- Returns self for chaining.
Example:
with_type
Specify the description.
Arguments:
rule_typedict - The description for the rules.
Returns:
RulesBuilder- Returns self for chaining.
Example:
with_parameters
Specify the parameters for rules.
Arguments:
parametersdict - The parameters for the rules.
Returns:
RulesBuilder- Returns self for chaining.
Example:
with_code
Specify the JavaScript code for advanced rules.
Arguments:
codestr - The JavaScript code to be used in the rule.
Returns:
RulesBuilder- Returns self for chaining.
Raises:
Exception- If the mode is not set to ‘ADVANCED’.
Example:
with_code_file
Specify the JavaScript code for advanced rules from a file.
This method reads the JavaScript code from a specified file and converts it into a single line to be used in the rule.
Arguments:
code_filestr - The path to the file containing the JavaScript code.
Returns:
RulesBuilder- Returns self for chaining.
Raises:
ValueError- If the file does not exist or is not a valid file.ValueError- If the mode is not set to ‘ADVANCED’.
Example:
with_env
Specify the environment variable.
Arguments:
data_envstr - The environment variable.
Returns:
RulesBuilder- Returns self for chaining.
Example:
with_config_file
Sets up the configuration file (.ini).
This method allows specifying a configuration file, a section within that file, and a key to retrieve a specific value from the section.
Arguments:
config_filestr - The path to the.ini configuration file.sectionstr - The section name within the.ini file where the desired configuration is located.config_keystr - The key within the specified section whose value will be retrieved.
Returns:
RulesBuilder- Returns itself to allow for method chaining.
Example:
with_find_by_name
Specify the name to find.
Arguments:
find_namestr - The name of the pipeline.
Returns:
RulesBuilder- Returns self for chaining.
Example:
find_all
Retrieve all models.
This method sets up the RulesBuilder instance to retrieve all rules associated with the specified organization.
Returns:
RulesBuilder- The instance of the RulesBuilder class itself, allowing for method chaining.
Example:
find_one
Retrieve all models.
This method sets up the RulesBuilder instance to retrieve all rules associated with the specified organization.
Returns:
RulesBuilder- The instance of the RulesBuilder class itself, allowing for method chaining.
Example:
create
Initiates the creation process of a new model.
This method prepares the RulesBuilder instance to create a new model by setting up the necessary parameters such as the organization name and the file to be associated with the model. It also specifies the URL endpoint for creating the model and sets the operation type to ‘create’.
Returns:
RulesBuilder- The instance of the RulesBuilder class itself, allowing for method chaining.
Example:
update
Update an existing rule.
This method sets up the RulesBuilder instance to update a specific rule associated with the specified organization and identifier.
Returns:
RulesBuilder- The instance of the RulesBuilder class itself, allowing for method chaining.
Example:
delete
Delete an existing model within the organization.
This method sets up the RulesBuilder instance to delete a specific model associated with the specified organization and identifier. It configures the URL endpoint for the delete operation and sets the operation type to ‘delete’.
Returns:
RulesBuilder- The instance of the RulesBuilder class itself, allowing for method chaining.
Example:
update_parameters
Updates the parameters of an existing rule.
This function prepares the RulesBuilder instance to update the parameters of a specific rule associated with the specified organization and channel.
Returns:
RulesBuilder- The RulesBuilder instance itself, allowing method chaining.
Example:
catalog
Retrieves the rules catalog.
This function prepares the RulesBuilder instance to retrieve the catalog of rules
Returns:
RulesBuilder- The RulesBuilder instance itself, allowing method chaining.
Example:
save
Selects the create-or-update operation.
It reads the rule identifier from the .env variable set with
with_env(), or from the file set with with_config_file(), and then
decides on its own: if a rule with that identifier already exists it is
updated, and if it does not, it is created and the resulting identifier
written back to the same place. Use it when a script has to be safe to
run more than once.
Returns:
RulesBuilder- Returns itself to allow for method chaining.
Example:
set_config_file_identifier
Selects the operation that writes the rule identifier into a configuration file.
It stores the identifier given to with_identifier() under the section
and key named with with_config_file(), so a later run can pick the rule
up from the file instead of carrying its identifier in the code. The key
must already exist in the file.
Returns:
RulesBuilder- Returns itself to allow for method chaining.
Example:
set_env_identifier
Selects the operation that writes the rule identifier into the .env
file.
It stores the identifier given to with_identifier() under the variable
named with with_env(), so a later run can pick the rule up from the
environment. The variable must already exist in the .env file.
Returns:
RulesBuilder- Returns itself to allow for method chaining.
Raises:
ValueError- If there is no identifier to write, or if the variable is not in the.envfile.
Example:
build
Finalizes the construction of the IoT collection configuration.
This method prepares the builder to execute the collection by ensuring all necessary configurations are set and validates the overall integrity of the build. It should be called before executing the collection to ensure that the configuration is complete and valid.
The build process involves checking that mandatory fields such as the device identifier are set. It also ensures that method calls that are incompatible with each other (like build and build_execute) are not both used.
Returns:
RulesBuilder- Returns itself to allow for method chaining, enabling further actions likeexecute.
Raises:
ValueError- If required configurations are missing or if incompatible methods are used together.
Example:
build_execute
Executes the data sets search immediately after building the configuration.
This method is a shortcut that combines building and executing in a single step.
Returns:
dict- A dictionary containing the execution response which includes the status code and potentially other metadata about the execution.
Raises:
ValueError- Ifbuildhas already been called on this builder instance.
Example:
execute
Execute the configured operation and return the response.
This method executes the operation that has been configured using the builder pattern. It ensures that the build method has been called and that it is the last method invoked before execute. Depending on the configured method (e.g., create, find, update, delete), it calls the appropriate internal execution method.
Returns:
requests.Response- The response object from the executed request.
Raises:
Exception- If thebuildmethod has not been called or if it is not the last method invoked beforeexecute.ValueError- If the configured method is unsupported.
Example: