Allow the function to be called directly with arguments
(self, *args)
| 118 | } |
| 119 | |
| 120 | def __call__(self, *args): |
| 121 | """Allow the function to be called directly with arguments""" |
| 122 | # Validate and convert args to dictionary |
| 123 | arg_dict = self._validate_args(*args) |
| 124 | |
| 125 | # Prepare request |
| 126 | request_config = self._prepare_request(arg_dict) |
| 127 | |
| 128 | # Make the request |
| 129 | response = requests.request(**request_config) |
| 130 | |
| 131 | # Handle response |
| 132 | if response.ok: |
| 133 | try: |
| 134 | result = response.json() |
| 135 | except requests.exceptions.JSONDecodeError: |
| 136 | result = response.text or None |
| 137 | # Interpolate success feedback if provided |
| 138 | if hasattr(self.config, 'success_feedback'): |
| 139 | print(self._interpolate_template(self.config.success_feedback, |
| 140 | {"response": result, **arg_dict})) |
| 141 | return result |
| 142 | else: |
| 143 | # Handle error |
| 144 | try: |
| 145 | error_msg = response.json() |
| 146 | except requests.exceptions.JSONDecodeError: |
| 147 | error_msg = {"description": response.text or response.reason} |
| 148 | if hasattr(self.config, "error_feedback"): |
| 149 | print( |
| 150 | self._interpolate_template( |
| 151 | self.config.error_feedback, {"response": error_msg, **arg_dict} |
| 152 | ) |
| 153 | ) |
| 154 | raise requests.exceptions.HTTPError(f"Request failed: {error_msg}") |
| 155 | |
| 156 | |
| 157 | class Agent: |
nothing calls this directly
no test coverage detected