Writing Custom Operations
In case the existing operations are not enough, the user can write their own to add the new functionality. Those new operations should be written in the project’s configuration directory in a “.hy” file. To do this, a new class has to be defined, which will inherit from Raider’s Operation class:
- class Operation(function, flags=0, action=None, otherwise=None)[source]
Parent class for all operations.
Each Operation class inherits from here.
- function
A callable function to be executed when the operation is run.
- flags
An integer with the flags which define the behaviour of the Operation. For now only two flags are allowed: NEEDS_RESPONSE and IS_CONDITIONAL. If NEEDS_RESPONSE is set, the HTTP response will be sent to the “function” for further processing. If IS_CONDITIONAL is set, the function should return a boolean, and if the return value is True the Operation inside “action” will be run next, if it’s False, the one from the “otherwise” will be run.
- action
An Operation object that will be run if the function returns True. Will only be used if the flag IS_CONDITIONAL is set.
- otherwise
An Operation object that will be run if the function returns False. Will only be used if the flag IS_CONDITIONAL is set.
- __init__(function, flags=0, action=None, otherwise=None)[source]
Initializes the Operation object.
- Parameters
function (
Callable
[...
,Any
]) – A callable function to be executed when the operation is run.flags (
int
) – An integer with the flags that define the behaviour of this Operation.action (
Union
[Operation
,List
[Operation
],None
]) – An Operation object that will be run when the function returns True.otherwise (
Union
[Operation
,List
[Operation
],None
]) – An Operation object that will be run when the function returns False.
- run(pconfig, response)[source]
Runs the Operation.
Runs the defined Operation, considering the “flags” set.
- Parameters
response (
Response
) – A requests.models.Response object with the HTTP response to be passed to the operation’s “function”.- Return type
Optional
[str
]- Returns
An optional string with the name of the next flow.
- run_conditional(response)[source]
Runs a conditional operation.
If the IS_CONDITIONAL flag is set, run the Operation’s “function” and if True runs the “action” next, if it’s False runs the “otherwise” Operation instead.
- Parameters
response (
Response
) – A requests.models.Response object with the HTTP response to be passed to the operation’s “function”.- Return type
Optional
[str
]- Returns
An optional string with the name of the next flow.
- property needs_response: bool
Returns True if the NEEDS_RESPONSE flag is set.
- Return type
bool
- property needs_userdata: bool
Returns True if the NEEDS_USERDATA flag is set.
- Return type
bool
- property is_conditional: bool
Returns True if the IS_CONDITIONAL flag is set.
- Return type
bool
- property will_append: bool
Returns True if the WILL_APPEND flag is set.
- Return type
bool