-
Notifications
You must be signed in to change notification settings - Fork 9
V2 Changes to handle errors #7
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
Open
anudeepkalitkar
wants to merge
4
commits into
Zenduty:master
Choose a base branch
from
anudeepkalitkar:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 was deleted.
Oops, something went wrong.
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,67 @@ | ||
| from zenduty import ZendutyClient | ||
|
|
||
| zenduty_client = ZendutyClient( | ||
| api_key="f3ab5c762c914dacca2c0c530b260fdf9fff0cc7", use_https=True | ||
| ) # Default credentials to ZENDUTY_API_KEY env variable if not provided. (use export ZENDUTY_API_KEY="<YOUR KEY>") | ||
|
|
||
|
|
||
| from zenduty import AccountMemberClient | ||
| members = AccountMemberClient(zenduty_client).get_all_members() | ||
| test_member = members[0] | ||
| from zenduty import AccountNotificationClient | ||
| member_contact_methods = AccountNotificationClient(zenduty_client,test_member).list_member_contact_methods() | ||
| member_notification_rules = AccountNotificationClient(zenduty_client, test_member).list_member_notification_rules() | ||
|
|
||
| from zenduty import AccountRoleClient | ||
| account_roles = AccountRoleClient(zenduty_client).list_account_roles() | ||
|
|
||
| from zenduty import EventClient | ||
|
|
||
| from zenduty import RouterClient | ||
| all_routers = RouterClient(zenduty_client).get_all_routers() | ||
|
|
||
| from zenduty import IncidentClient | ||
| all_incidents = IncidentClient(zenduty_client).get_all_incidents(status=3) | ||
|
|
||
| from zenduty import IncidentNoteClient | ||
| all_incident_notes = IncidentNoteClient(zenduty_client, all_incidents[0]).get_all_incident_notes() | ||
|
|
||
| from zenduty import IncidentTagClient | ||
| all_tags = IncidentTagClient(zenduty_client, all_incidents[0]).get_all_tags() | ||
|
|
||
| from zenduty import TeamsClient | ||
| teams = TeamsClient(zenduty_client).list_teams() | ||
| team_members = TeamsClient(zenduty_client).list_team_members(teams[0]) | ||
| team_permissions = TeamsClient(zenduty_client).fetch_team_permissions(teams[0]) | ||
| oncall = TeamsClient(zenduty_client).get_all_oncall(teams[0]) | ||
|
|
||
| from zenduty import EscalationPolicyClient | ||
| eps = EscalationPolicyClient(zenduty_client, teams[0]).get_all_policies() | ||
|
|
||
| from zenduty import TeamMaintenanceClient | ||
| team_maintenace = TeamMaintenanceClient(zenduty_client, teams[0]).get_all_maintenance() | ||
|
|
||
| from zenduty import OncallClient | ||
| oncall_v2 = OncallClient(zenduty_client, teams[0]).list_team_oncall_v2() | ||
| oncall = OncallClient(zenduty_client, teams[0]).get_all_oncall() | ||
|
|
||
| from zenduty import PostmortemClient | ||
| pm = PostmortemClient(zenduty_client, teams[0]).get_all_postmortem() | ||
|
|
||
| from zenduty import PriorityClient | ||
| p = PriorityClient(zenduty_client, teams[0]).get_all_priorities() | ||
|
|
||
| from zenduty import IncidentRoleClient | ||
| ir = IncidentRoleClient(zenduty_client, teams[0]).get_all_roles() | ||
|
|
||
| from zenduty import ScheduleClient | ||
| schedules = ScheduleClient(zenduty_client, teams[0]).get_all_schedules() | ||
|
|
||
| from zenduty import ServiceClient | ||
| sercives = ServiceClient(zenduty_client, teams[0]).get_all_services() | ||
|
|
||
| from zenduty import IntegrationClient | ||
| intergrations = IntegrationClient(zenduty_client, teams[0], sercives[0]).get_all_integrations() | ||
|
|
||
| from zenduty import SLAClient | ||
| sla = SLAClient(zenduty_client, teams[0]).get_all_slas() |
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,55 @@ | ||
| from __future__ import absolute_import | ||
|
|
||
| __version__ = "1.2.0" | ||
|
|
||
| # All Model Imports | ||
| from .accounts.members.models import AccountMember, User | ||
| from .accounts.notifications.models import NotificationRule, ContactMethod | ||
| from .accounts.roles.models import AccountRole | ||
| from .events.models import Event | ||
| from .events.router.models import Router | ||
| from .incidents.models import Incident, IncidentAlert, IntegrationObject | ||
| from .incidents.notes.models import IncidentNote | ||
| from .incidents.tags.models import Tag as IncidentTag | ||
| from .teams.models import Team | ||
| from .teams.models import Member as TeamMember | ||
| from .teams.escalation_policies.models import EscalationPolicy | ||
| from .teams.maintenance.models import TeamMaintenance | ||
| from .teams.oncall.models import OnCall, OnCallV2 | ||
| from .teams.postmortem.models import Postmortem | ||
| from .teams.priorities.models import Priority | ||
| from .teams.roles.models import IncidentRole | ||
| from .teams.schedules.models import Schedule | ||
| from .teams.services.models import Service | ||
| from .teams.services.integrations.models import Integration, IntegrationAlert, IntegrationObject | ||
| from .teams.sla.models import SLA | ||
| from .teams.tags.models import Tag | ||
| from .teams.task_templates.models import TaskTemplate | ||
|
|
||
|
|
||
| # All Clients imports | ||
| from .client import ZendutyClient, ZendutyClientRequestMethod | ||
| from .accounts.members import AccountMemberClient | ||
| from .accounts.notifications import AccountNotificationClient | ||
| from .accounts.roles import AccountRoleClient | ||
| from .events import EventClient | ||
| from .events.router import RouterClient | ||
| from .incidents import IncidentClient | ||
| from .incidents.notes import IncidentNoteClient | ||
| from .incidents.tags import IncidentTagClient | ||
| from .teams import TeamsClient | ||
| from .teams.escalation_policies import EscalationPolicyClient | ||
| from .teams.maintenance import TeamMaintenanceClient | ||
| from .teams.oncall import OncallClient | ||
| from .teams.postmortem import PostmortemClient | ||
| from .teams.priorities import PriorityClient | ||
| from .teams.roles import IncidentRoleClient | ||
| from .teams.schedules import ScheduleClient | ||
| from .teams.services import ServiceClient | ||
| from .teams.services.integrations import IntegrationClient | ||
| from .teams.sla import SLAClient | ||
| from .teams.tags import TagClient | ||
| from .teams.task_templates import TaskTemplateClient | ||
|
|
||
| #all exception imports | ||
| from .exceptions import APIException |
This file was deleted.
Oops, something went wrong.
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,147 @@ | ||
| from zenduty.apiV2.accounts.members import AccountMember | ||
| from .models import ContactMethod, NotificationRule | ||
| from zenduty.apiV2.client import ZendutyClient, ZendutyClientRequestMethod | ||
|
|
||
|
|
||
| class AccountNotificationClient: | ||
| def __init__(self, client: ZendutyClient, member: AccountMember): | ||
| self._client = client | ||
| self._member = member | ||
|
|
||
| def list_member_contact_methods(self) -> list[ContactMethod] : | ||
| """list members contact methods | ||
| Returns: | ||
| list [ContactMethodObject]: list of Contact Method objects | ||
| """ | ||
| response = self._client.execute( | ||
| method=ZendutyClientRequestMethod.GET, | ||
| endpoint=f"/api/account/users/{self._member.user.username}/contacts/" | ||
| ) | ||
|
|
||
| return [ContactMethod(**contact) for contact in response] | ||
|
|
||
| def get_member_contact_method(self, contact_method_id: str) -> ContactMethod: | ||
| """Get member contact method object by contact_method_id | ||
|
|
||
| Args: | ||
| contact_method_id (str): the unique id of contact method | ||
|
|
||
| Returns: | ||
| ContactMethod: Contact Method object | ||
| """ | ||
| response = self._client.execute( | ||
| method=ZendutyClientRequestMethod.GET, | ||
| endpoint=f"/api/account/users/{self._member.user.username}/contacts/{contact_method_id}/" | ||
| ) | ||
| return ContactMethod(**response) | ||
|
|
||
| def create_member_contact_method(self, name: str, value: str, contact_type: int) -> ContactMethod: | ||
| """Create member contact method | ||
|
|
||
| Args: | ||
| contact_method_id (str): the unique id of contact method | ||
| name (str): name of the contact method | ||
| value (str): value for the contact method | ||
| contact_type (int): contact type | ||
|
|
||
| Returns: | ||
| ContactMethod: Contact Method object | ||
| """ | ||
|
|
||
| response = self._client.execute( | ||
| method=ZendutyClientRequestMethod.POST, | ||
| endpoint=f"/api/account/users/{self._member.user.username}/contacts/", | ||
| request_payload={ | ||
| "name":name, | ||
| "value": value, | ||
| "contact_type": contact_type | ||
| }, | ||
| success_code=201 | ||
| ) | ||
| return ContactMethod(**response) | ||
|
|
||
| def delete_member_contact_method(self, contact_method_id: str) -> None: | ||
| """Delete member contact method | ||
|
|
||
| Args: | ||
| contact_method_id (str): the unique id of contact method | ||
|
|
||
| Returns: | ||
| None | ||
| """ | ||
|
|
||
| response = self._client.execute( | ||
| method=ZendutyClientRequestMethod.DELETE, | ||
| endpoint=f"/api/account/users/{self._member.user.username}/contacts/{contact_method_id}", | ||
| ) | ||
| return None | ||
|
|
||
| def list_member_notification_rules(self) -> list[NotificationRule]: | ||
|
|
||
| """list members notification rules | ||
| Returns: | ||
| list [NotificationRules]: list of Notification Rule objects | ||
| """ | ||
| response = self._client.execute( | ||
| method=ZendutyClientRequestMethod.GET, | ||
| endpoint=f"/api/account/users/{self._member.user.username}/notification_rules/" | ||
| ) | ||
| return [NotificationRule(**contact) for contact in response] | ||
|
|
||
| def get_member_notification_rules(self, notification_rule_id: str) -> NotificationRule: | ||
| """Get member nottification rule object by notification_rule_id | ||
|
|
||
| Args: | ||
| notification_rule_id (str): the unique id of notification rule | ||
|
|
||
| Returns: | ||
| ContactMethod: Contact Method object | ||
| """ | ||
| response = self._client.execute( | ||
| method=ZendutyClientRequestMethod.GET, | ||
| endpoint=f"/api/account/users/{self._member.user.username}/notification_rules/{notification_rule_id}/" | ||
| ) | ||
|
|
||
| return NotificationRule(**response) | ||
|
|
||
| def create_member_notification_rules(self, start_delay: int, contact_method: str, urgency: int) -> NotificationRule: | ||
| """create member nottification rule object by notification_rule_id | ||
|
|
||
| Args: | ||
| start_delay (int): the unique id of notification rule | ||
| contact_method (ContactMethod): | ||
| urgency (int): urgency | ||
|
|
||
| Returns: | ||
| ContactMethod: Contact Method object | ||
| """ | ||
| response = self._client.execute( | ||
| method=ZendutyClientRequestMethod.POST, | ||
| endpoint=f"/api/account/users/{self._member.user.username}/notification_rules/", | ||
| request_payload = { | ||
| "contact" : contact_method, | ||
| "start_delay": start_delay, | ||
| "urgency": urgency | ||
| }, | ||
| success_code=201 | ||
| ) | ||
|
|
||
| return NotificationRule(**response) | ||
|
|
||
|
|
||
| def delete_member_notification_rule(self, notification_rule_id: str) -> None: | ||
| """Delete member notification rule | ||
|
|
||
| Args: | ||
| notification_rule_id (str): the unique id of notification rule | ||
|
|
||
| Returns: | ||
| None | ||
| """ | ||
|
|
||
| response = self._client.execute( | ||
| method=ZendutyClientRequestMethod.DELETE, | ||
| endpoint=f"/api/account/users/{self._member.user.username}/notification_rules/{notification_rule_id}", | ||
| success_code=204 | ||
| ) | ||
| return None |
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.
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.
There are customers who are still using the v1 configuration. So, we would need it ideally.