-
Notifications
You must be signed in to change notification settings - Fork 7
Add Webhooks API + slim README to docs.mifiel.com #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,69 @@ | ||||||||||||||||
| from mifiel import Base | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| class Webhook(Base): | ||||||||||||||||
| """Account-level webhook subscriptions. | ||||||||||||||||
|
|
||||||||||||||||
| See https://docs.mifiel.com/en/#tag/Webhooks | ||||||||||||||||
| """ | ||||||||||||||||
|
|
||||||||||||||||
| def __init__(self, client): | ||||||||||||||||
| Base.__init__(self, client, 'webhooks') | ||||||||||||||||
|
|
||||||||||||||||
| @staticmethod | ||||||||||||||||
| def find(client, webhook_id): | ||||||||||||||||
| webhook = Webhook(client) | ||||||||||||||||
| webhook.process_request('get', url=webhook.url(webhook_id)) | ||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||||||||||
| return webhook | ||||||||||||||||
|
|
||||||||||||||||
| @staticmethod | ||||||||||||||||
| def all(client): | ||||||||||||||||
| base = Webhook(client) | ||||||||||||||||
| response = base.execute_request('get', url=base.url()) | ||||||||||||||||
| result = [] | ||||||||||||||||
| for single in response.json(): | ||||||||||||||||
|
Comment on lines
+22
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- mifiel/webhook.py ---'
cat -n mifiel/webhook.py
printf '%s\n' '--- request helpers and response handling ---'
rg -n -C 5 "def execute_request|execute_request\\(|class Webhook|def all|def find|raise_for_status|response\\.json" mifiel tests 2>/dev/null || true
printf '%s\n' '--- repository files near webhook tests ---'
git ls-files | rg '(^|/)(test|tests|webhook|README|docs)' | head -80Repository: Mifiel/python-api-client Length of output: 13029 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- targeted source files ---'
for f in $(git ls-files | rg '(^|/)(webhook|base|client|request|test)' | head -80); do
case "$f" in
*.py)
printf '\n--- %s ---\n' "$f"
sed -n '1,260p' "$f"
;;
esac
doneRepository: Mifiel/python-api-client Length of output: 21004 Check the HTTP status before iterating the response body.
Proposed fix base = Webhook(client)
response = base.execute_request('get', url=base.url())
+ response.raise_for_status()
result = []
for single in response.json():📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| obj = Webhook(client) | ||||||||||||||||
| obj.set_data(single) | ||||||||||||||||
| result.append(obj) | ||||||||||||||||
| return result | ||||||||||||||||
|
|
||||||||||||||||
| @staticmethod | ||||||||||||||||
| def create(client, url, callback_type): | ||||||||||||||||
| webhook = Webhook(client) | ||||||||||||||||
| webhook.process_request( | ||||||||||||||||
| 'post', | ||||||||||||||||
| json={ | ||||||||||||||||
| 'url': url, | ||||||||||||||||
| 'callback_type': callback_type, | ||||||||||||||||
| }, | ||||||||||||||||
| ) | ||||||||||||||||
| return webhook | ||||||||||||||||
|
|
||||||||||||||||
| @staticmethod | ||||||||||||||||
| def delete(client, webhook_id): | ||||||||||||||||
| base = Webhook(client) | ||||||||||||||||
| response = base.execute_request('delete', url=base.url(webhook_id)) | ||||||||||||||||
| if response.content: | ||||||||||||||||
| return response.json() | ||||||||||||||||
| return None | ||||||||||||||||
|
|
||||||||||||||||
| def trigger(self, resource, instant=False): | ||||||||||||||||
| """Trigger delivery for this webhook. | ||||||||||||||||
|
|
||||||||||||||||
| Args: | ||||||||||||||||
| resource: UUID of the related resource included in the callback payload. | ||||||||||||||||
| instant: When True, deliver immediately once instead of enqueueing retries. | ||||||||||||||||
| """ | ||||||||||||||||
| if not self.id: | ||||||||||||||||
| raise ValueError('Webhook id is required to trigger') | ||||||||||||||||
| response = self.execute_request( | ||||||||||||||||
| 'post', | ||||||||||||||||
| url=self.url('{}/trigger'.format(self.id)), | ||||||||||||||||
| json={ | ||||||||||||||||
| 'resource': resource, | ||||||||||||||||
| 'instant': instant, | ||||||||||||||||
| }, | ||||||||||||||||
| ) | ||||||||||||||||
| if response.content: | ||||||||||||||||
| return response.json() | ||||||||||||||||
| return None | ||||||||||||||||
|
Comment on lines
+63
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win Raise on non-success responses from 🤖 Prompt for AI Agents |
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Use environment-specific access-token instructions.
Step 1 permits production or sandbox setup, but Step 2 links only to sandbox tokens. Sandbox credentials are not valid for the production-default client endpoint, so production users can fail authentication. Provide separate production and sandbox links, or link to an environment-neutral account page.
🤖 Prompt for AI Agents