forked from messagebird/python-rest-api
-
Notifications
You must be signed in to change notification settings - Fork 0
DEVP-12 :: list & delete voice calls #1
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
stefan-messagebird
merged 15 commits into
DEVP-12_add_create_voice_call
from
DEVP-12_list_voice_calls
Sep 10, 2019
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
64a8811
ignore venv folder
stefan-messagebird ec77dee
add listing for calls
stefan-messagebird dc9b554
fix list command comments
stefan-messagebird bb6c239
add delete call functionality
stefan-messagebird 2c8ba9d
simplify string test
stefan-messagebird 60793ed
ignore venv folder
stefan-messagebird 3dad329
add listing for calls
stefan-messagebird 194fe18
fix list command comments
stefan-messagebird 7801032
add delete call functionality
stefan-messagebird 1ea8566
Merge branch 'DEVP-12_list_voice_calls' of github.com:stefan-messageb…
stefan-messagebird ee91e65
ignore venv folder
stefan-messagebird ae049df
add listing for calls
stefan-messagebird 415423c
fix list command comments
stefan-messagebird ceb7fcd
add delete call functionality
stefan-messagebird 16fa504
merge with base
stefan-messagebird 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,3 +59,6 @@ target/ | |
|
|
||
| # PyCharm | ||
| .idea/ | ||
|
|
||
| # pyvenv | ||
| venv/ | ||
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,48 @@ | ||
| #!/usr/bin/env python | ||
| import os | ||
| import sys | ||
| import json | ||
| import argparse | ||
| import requests | ||
|
|
||
| sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | ||
| import messagebird | ||
|
|
||
| parser = argparse.ArgumentParser(usage='call_create.py\ | ||
| --accessKey="*******" \ | ||
| --callId=dda20377-72da-4846-9b2c-0fea3ad4bcb6 \ | ||
| ') | ||
| parser.add_argument('--accessKey', help='Access key for MessageBird API.', type=str, required=True) | ||
| parser.add_argument('--callId', help='The ID of the MessageBird call to delete.', type=str, required=True) | ||
| args = vars(parser.parse_args()) | ||
|
|
||
| try: | ||
| # Create a MessageBird client with the specified accessKey. | ||
| client = messagebird.Client(args['accessKey']) | ||
|
|
||
| # Create a call for the specified callID. | ||
| call = client.call_delete(args['callId']) | ||
|
|
||
| # If no error is thrown, means delete was successful. | ||
| print('\nDeleted call with id `%s` successfully!' % args['callId']) | ||
|
|
||
| except messagebird.client.ErrorException as e: | ||
| print('\nAn error occurred while creating a call:\n') | ||
|
|
||
| for error in e.errors: | ||
| print(' code : %d' % error.code) | ||
| print(' description : %s' % error.description) | ||
| print(' parameter : %s' % error.parameter) | ||
| print(' type : %s' % error.__class__) | ||
|
|
||
| except requests.exceptions.HTTPError as e: | ||
| print('\nAn http exception occurred while deleting a call:') | ||
| print(' ', e) | ||
| print(' Http request body: ', e.request.body) | ||
| print(' Http response status: ', e.response.status_code) | ||
| print(' Http response body: ', e.response.content.decode()) | ||
|
|
||
| except Exception as e: | ||
| print('\nAn ', e.__class__, ' exception occurred while deleting a call:') | ||
| print(e) | ||
|
|
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,64 @@ | ||
| #!/usr/bin/env python | ||
| import os | ||
| import sys | ||
| import argparse | ||
| import requests | ||
|
|
||
| sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | ||
| import messagebird | ||
|
|
||
|
|
||
| parser = argparse.ArgumentParser(usage='call_create.py\ | ||
| --accessKey="*******" \ | ||
| --page=1 \ | ||
| ') | ||
| parser.add_argument('--accessKey', help='Access key for MessageBird API.', type=str, required=True) | ||
| parser.add_argument('--page', help='The page you wish to view.', type=str, required=False, default=1) | ||
| args = vars(parser.parse_args()) | ||
|
|
||
| try: | ||
| # Create a MessageBird client with the specified accessKey. | ||
| client = messagebird.Client(args['accessKey']) | ||
| del(args['accessKey']) | ||
|
|
||
| # Create a call for the specified callID. | ||
| callList = client.call_list(**args) | ||
|
|
||
| # Print the object information. | ||
| print('\nThe following information was returned as a %s object:\n' % callList.__class__) | ||
| if callList.items is not None: | ||
| print(' Containing the the following items:') | ||
| for item in callList.items: | ||
| print(' {') | ||
| print(' id : %s' % item.id) | ||
| print(' status : %s' % item.status) | ||
| print(' source : %s' % item.source) | ||
| print(' destination : %s' % item.destination) | ||
| print(' createdAt : %s' % item.createdAt) | ||
| print(' updatedAt : %s' % item.updatedAt) | ||
| print(' endedAt : %s' % item.endedAt) | ||
| print(' },') | ||
| else: | ||
| print(' With an empty response.') | ||
|
|
||
| except messagebird.client.ErrorException as e: | ||
| print('\nAn error occurred while listing calls:\n') | ||
|
|
||
| for error in e.errors: | ||
| print(' code : %d' % error.code) | ||
| print(' description : %s' % error.description) | ||
| print(' parameter : %s' % error.parameter) | ||
| print(' type : %s' % error.__class__) | ||
|
|
||
| except requests.exceptions.HTTPError as e: | ||
| print('\nAn HTTP exception occurred while listing calls:') | ||
| print(' ', e) | ||
| print(' Http request body: ', e.request.body) | ||
| print(' Http response status: ', e.response.status_code) | ||
| print(' Http response body: ', e.response.content.decode()) | ||
|
|
||
| except Exception as e: | ||
| print('\nAn ', e.__class__, ' exception occurred while creating a call:') | ||
| print(e) | ||
|
|
||
|
|
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,42 @@ | ||
| from messagebird.base_list import BaseList | ||
| from messagebird.call_data import CallData | ||
|
|
||
|
|
||
| class CallList(BaseList): | ||
| def __init__(self): | ||
| # We're expecting items of type CallData | ||
| super(CallList, self).__init__(CallData) | ||
| self.perPage = None | ||
| self.currentPage = None | ||
| self.pageCount = None | ||
| self._pagination = None | ||
|
|
||
| @property | ||
| def data(self): | ||
| return self.items | ||
|
|
||
| @property | ||
| def pagination(self): | ||
| return { | ||
| "totalCount": self.totalCount, | ||
| "pageCount": self.pageCount, | ||
| "currentPage": self.currentPage, | ||
| "perPage": self.perPage | ||
| } | ||
|
|
||
| @pagination.setter | ||
| def pagination(self, value): | ||
| if isinstance(value, dict): | ||
| self.totalCount = value['totalCount'] | ||
| self.pageCount = value['pageCount'] | ||
| self.currentPage = value['currentPage'] | ||
| self.perPage = value['perPage'] | ||
| self.limit = self.perPage * self.currentPage | ||
| self.offset = self.perPage * (self.currentPage - 1) | ||
|
|
||
| @data.setter | ||
| def data(self, value): | ||
| if isinstance(value, list): | ||
| self.count = len(value) | ||
| self.items = value | ||
|
|
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
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.
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.
Maybe
return "%s with %d items.\n" % (str(self.__class__), items_count)would be a bit nicer