-
Notifications
You must be signed in to change notification settings - Fork 65
ON-2 Python sdk: CRUD Voice API resource - Webhooks #47
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
639b8a6
Read voice webhook by id
781bc79
Add class CreateWebhookRequest
0f66565
Add class VoiceUpdateWebhookRequest
6a32787
Made _format_query static method
3e3f875
Add [editor config](https://editorconfig.org)
ca3b777
Returned 4 indent spaces to editorconfig from PEP8
0471316
Client methods for voice webhooks for [docs](https://developers.messa…
cdde607
Increase coverage for voice webhooks
91f9399
Fixes for create/update voice webhook requests
bc8fe32
Example for voice webhook creation
67917ba
Add examples for crud operations on voice webhooks
967be48
Added example of how to run examples with args to README.
02eede0
Put requests inside method swither into lambda, to make request lazy
b26dc2f
Exit in voice webhook deletion example, if result is empty
bbe7179
Code style changes
1c048b7
Fix error in documentation. URL is the only required parameter
b7222f0
Fix test for VoiceCreateWebhook validation
4aacc14
Deleted editorconfig
484456b
Style fixes
06e38d4
Style fixes for tests
beb9130
Changed webhookId to a valid uuid in tests
d3fd626
New string formatting for example code
19b02dd
Fixes in tests and voice webhook class for consistency
352fc05
Changed allowed methods check
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #!/usr/bin/env python | ||
| import argparse | ||
| import messagebird | ||
| from messagebird.voice_webhook import VoiceCreateWebhookRequest | ||
|
|
||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument('--accessKey', help='access key for MessageBird API', type=str, required=True) | ||
| parser.add_argument('--url', help='url for the webhook', type=str, required=True) | ||
| parser.add_argument('--title', help='title for the webhook', type=str) | ||
| parser.add_argument('--token', help='token for the webhook', type=str) | ||
| args = vars(parser.parse_args()) | ||
|
|
||
| try: | ||
| client = messagebird.Client(args['accessKey']) | ||
|
|
||
| create_webhook_request = VoiceCreateWebhookRequest(url=args['url'], title=args['title'], token=args['token']) | ||
| webhook = client.voice_create_webhook(create_webhook_request) | ||
|
|
||
| # Print the object information. | ||
| print('\nThe following information was returned as a Voice Webhook object:\n') | ||
| print(' id : {}'.format(webhook.id)) | ||
| print(' token : {}'.format(webhook.token)) | ||
| print(' url : {}'.format(webhook.url)) | ||
| print(' createdAt : {}'.format(webhook.createdAt)) | ||
| print(' updatedAt : {}'.format(webhook.updatedAt)) | ||
|
|
||
| except messagebird.client.ErrorException as e: | ||
| print('An error occured while creating a Voice Webhook object:') | ||
|
|
||
| for error in e.errors: | ||
| print(' code : {}'.format(error.code)) | ||
| print(' description : {}'.format(error.description)) | ||
| print(' parameter : {}\n'.format(error.parameter)) | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #!/usr/bin/env python | ||
| import argparse | ||
| import messagebird | ||
|
|
||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument('--accessKey', help='access key for MessageBird API', type=str, required=True) | ||
| parser.add_argument('--webhookId', help='webhook that you want to update', type=str, required=True) | ||
|
|
||
| args = vars(parser.parse_args()) | ||
|
|
||
| try: | ||
| client = messagebird.Client(args['accessKey']) | ||
| webhook = client.voice_delete_webhook(args['webhookId']) | ||
|
|
||
| # Print the object information. | ||
| print('Webhook has been deleted') | ||
|
|
||
| except messagebird.client.ErrorException as e: | ||
| print('An error occured while deleting a Voice Webhook object:') | ||
|
|
||
| for error in e.errors: | ||
| print(' code : {}'.format(error.code)) | ||
| print(' description : {}'.format(error.description)) | ||
| print(' parameter : {}\n'.format(error.parameter)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/usr/bin/env python | ||
| import argparse | ||
| import messagebird | ||
| from messagebird.voice_webhook import VoiceCreateWebhookRequest | ||
|
|
||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument('--accessKey', help='access key for MessageBird API', type=str, required=True) | ||
|
|
||
| args = vars(parser.parse_args()) | ||
|
|
||
| try: | ||
| client = messagebird.Client(args['accessKey']) | ||
|
|
||
| webhooks_list = client.voice_list_webhooks(limit=5, offset=0) | ||
|
|
||
| if webhooks_list is None or webhooks_list.data is None: | ||
| print("\nNo webhooks\n") | ||
| exit(0) | ||
|
|
||
| # Print the object information. | ||
| print('\nThe following information was returned as a Voice Webhook objects:\n') | ||
| for webhook in webhooks_list.data: | ||
| print('{') | ||
| print(' id : {}'.format(webhook.id)) | ||
| print(' token : {}'.format(webhook.token)) | ||
| print(' url : {}'.format(webhook.url)) | ||
| print(' createdAt : {}'.format(webhook.createdAt)) | ||
| print(' updatedAt : {}'.format(webhook.updatedAt)) | ||
| print('}\n') | ||
|
|
||
| except messagebird.client.ErrorException as e: | ||
| print('An error occured while reading a Voice Webhook object:') | ||
|
|
||
| for error in e.errors: | ||
| print(' code : {}'.format(error.code)) | ||
| print(' description : {}'.format(error.description)) | ||
| print(' parameter : {}\n'.format(error.parameter)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/usr/bin/env python | ||
| import argparse | ||
| import messagebird | ||
| from messagebird.voice_webhook import VoiceCreateWebhookRequest | ||
|
|
||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument('--accessKey', help='access key for MessageBird API', type=str, required=True) | ||
| parser.add_argument('--webhookId', help='webhook that you want to update', type=str, required=True) | ||
|
|
||
| args = vars(parser.parse_args()) | ||
|
|
||
| try: | ||
| client = messagebird.Client(args['accessKey']) | ||
|
|
||
| webhook = client.voice_read_webhook(args['webhookId']) | ||
|
|
||
| # Print the object information. | ||
| print('\nThe following information was returned as a Voice Webhook object:\n') | ||
|
|
||
| print(' id : {}'.format(webhook.id)) | ||
| print(' token : {}'.format(webhook.token)) | ||
| print(' url : {}'.format(webhook.url)) | ||
| print(' createdAt : {}'.format(webhook.createdAt)) | ||
| print(' updatedAt : {}'.format(webhook.updatedAt)) | ||
|
|
||
|
|
||
| except messagebird.client.ErrorException as e: | ||
| print('An error occured while reading a Voice Webhook object:') | ||
|
|
||
| for error in e.errors: | ||
| print(' code : {}'.format(error.code)) | ||
| print(' description : {}'.format(error.description)) | ||
| print(' parameter : {}\n'.format(error.parameter)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/usr/bin/env python | ||
| import argparse | ||
| import messagebird | ||
| from messagebird.voice_webhook import VoiceUpdateWebhookRequest | ||
|
|
||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument('--accessKey', help='access key for MessageBird API', type=str, required=True) | ||
| parser.add_argument('--webhookId', help='webhook that you want to update', type=str, required=True) | ||
| parser.add_argument('--title', help='title for the webhook', type=str) | ||
| parser.add_argument('--token', help='token for the webhook', type=str) | ||
|
|
||
| args = vars(parser.parse_args()) | ||
|
|
||
| try: | ||
| client = messagebird.Client(args['accessKey']) | ||
|
|
||
| update_webhook_request = VoiceUpdateWebhookRequest(title=args['title'], token=args['token']) | ||
| webhook = client.voice_update_webhook(args['webhookId'], update_webhook_request) | ||
|
|
||
| # Print the object information. | ||
| print('\nThe following information was returned as a Voice Webhook object:\n') | ||
| print(' id : {}'.format(webhook.id)) | ||
| print(' token : {}'.format(webhook.token)) | ||
| print(' url : {}'.format(webhook.url)) | ||
| print(' createdAt : {}'.format(webhook.createdAt)) | ||
| print(' updatedAt : {}'.format(webhook.updatedAt)) | ||
|
|
||
| except messagebird.client.ErrorException as e: | ||
| print('An error occured while updating a Voice Webhook object:') | ||
|
|
||
| for error in e.errors: | ||
| print(' code : {}'.format(error.code)) | ||
| print(' description : {}'.format(error.description)) | ||
| print(' parameter : {}\n'.format(error.parameter)) | ||
|
|
||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| from messagebird.base import Base | ||
|
|
||
|
|
||
| class Balance(Base): | ||
| def __init__(self): | ||
| self.amount = None | ||
| self.type = None | ||
| self.payment = None | ||
| def __init__(self): | ||
rafavaliev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.amount = None | ||
| self.type = None | ||
| self.payment = None | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,18 @@ | ||
| from datetime import datetime | ||
|
|
||
| import dateutil.parser | ||
| import json | ||
|
|
||
|
|
||
| class Base(object): | ||
| def load(self, data): | ||
| for name, value in list(data.items()): | ||
| if hasattr(self, name) and not callable(getattr(self,name)): | ||
| setattr(self, name, value) | ||
| def load(self, data): | ||
| for name, value in list(data.items()): | ||
| if hasattr(self, name) and not callable(getattr(self, name)): | ||
| setattr(self, name, value) | ||
|
|
||
| return self | ||
| return self | ||
|
|
||
| @staticmethod | ||
| def value_to_time(value, format='%Y-%m-%dT%H:%M:%S+00:00'): | ||
| if value is not None: | ||
| return dateutil.parser.parse(value).replace(microsecond=0) | ||
| @staticmethod | ||
| def value_to_time(value, format='%Y-%m-%dT%H:%M:%S+00:00'): | ||
| if value is not None: | ||
| return dateutil.parser.parse(value).replace(microsecond=0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,4 +39,3 @@ def data(self, value): | |
| if isinstance(value, list): | ||
| self.count = len(value) | ||
| self.items = value | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.