From 78f4939a8ebde4e18caef4d7f99001b49b6c5c57 Mon Sep 17 00:00:00 2001 From: Robert Habermann <mail@rhab.de> Date: Mon, 31 Oct 2016 21:44:20 +0100 Subject: [PATCH] merge type map into operation map --- pyotrs/lib.py | 76 ++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/pyotrs/lib.py b/pyotrs/lib.py index e862d44..fd1262e 100644 --- a/pyotrs/lib.py +++ b/pyotrs/lib.py @@ -19,47 +19,44 @@ import requests OPERATION_MAPPING_DEFAULT = { 'SessionCreate': {'RequestMethod': 'POST', - 'Route': '/Session'}, + 'Route': '/Session', + 'Result': 'SessionID'}, 'TicketCreate': {'RequestMethod': 'POST', - 'Route': '/Ticket'}, + 'Route': '/Ticket', + 'Result': 'TicketID'}, 'TicketGet': {'RequestMethod': 'GET', - 'Route': '/Ticket/:TicketID'}, + 'Route': '/Ticket/:TicketID', + 'Result': 'Ticket'}, 'TicketGetList': {'RequestMethod': 'GET', - 'Route': '/TicketList'}, + 'Route': '/TicketList', + 'Result': 'Ticket'}, 'TicketSearch': {'RequestMethod': 'GET', - 'Route': '/Ticket'}, + 'Route': '/Ticket', + 'Result': 'TicketID'}, 'TicketUpdate': {'RequestMethod': 'PATCH', - 'Route': '/Ticket/:TicketID'}, + 'Route': '/Ticket/:TicketID', + 'Result': 'TicketID'}, 'LinkAdd': {'RequestMethod': 'POST', - 'Route': '/LinkAdd'}, + 'Route': '/LinkAdd', + 'Result': 'LinkAdd'}, 'LinkDelete': {'RequestMethod': 'DELETE', - 'Route': '/LinkDelete'}, + 'Route': '/LinkDelete', + 'Result': 'LinkDelete'}, 'LinkDeleteAll': {'RequestMethod': 'DELETE', - 'Route': '/LinkDeleteAll'}, + 'Route': '/LinkDeleteAll', + 'Result': 'LinkDeleteAll'}, 'LinkList': {'RequestMethod': 'GET', - 'Route': '/LinkList'}, + 'Route': '/LinkList', + 'Result': 'LinkList'}, 'PossibleLinkList': {'RequestMethod': 'GET', - 'Route': '/PossibleLinkList'}, + 'Route': '/PossibleLinkList', + 'Result': 'PossibleLinkList'}, 'PossibleObjectsList': {'RequestMethod': 'GET', - 'Route': '/PossibleObjectsList'}, + 'Route': '/PossibleObjectsList', + 'Result': 'PossibleObject'}, 'PossibleTypesList': {'RequestMethod': 'GET', - 'Route': '/PossibleTypesList'} -} - -TYPE_MAPPING_DEFAULT = { - 'SessionCreate': 'SessionID', - 'TicketCreate': 'TicketID', - 'TicketGet': 'Ticket', - 'TicketGetList': 'Ticket', - 'TicketSearch': 'TicketID', - 'TicketUpdate': 'TicketID', - 'LinkAdd': 'LinkAdd', - 'LinkDelete': 'LinkDelete', - 'LinkDeleteAll': 'LinkDeleteAll', - 'LinkList': 'LinkList', - 'PossibleLinkList': 'PossibleLinkList', - 'PossibleObjectsList': 'PossibleObjectsList', - 'PossibleTypesList': 'PossibleTypesList' + 'Route': '/PossibleTypesList', + 'Result': 'PossibleType'} } @@ -672,28 +669,32 @@ class Client(object): password (str): Password session_id_file (str): Session ID path on disc, used to persistently store Session ID session_timeout (int): Session Timeout configured in OTRS (usually 28800 seconds = 8h) + session_validation_ticket_id (int): Ticket ID of an existing ticket - used to perform + several check - e.g. validate log in (defaults to 1) + webservicename_link (str): OTRSGenericInterfaceLinkMechanism REST Web Service Name proxies (dict): Proxy settings - refer to requests docs for more information - default to no proxies https_verify (bool): Should HTTPS certificates be verified (defaults to True) ca_cert_bundle (str): file path - if specified overrides python/system default for Root CA bundle that will be used. - operation_map (dict): A dictionary for mapping OTRS operations to HTTP Method and Route. - type_map (dict): A dictionary for mapping OTRS result type to operations. + operation_map (dict): A dictionary for mapping OTRS operations to HTTP Method, Route and + Result string. """ + def __init__(self, baseurl=None, webservicename=None, username=None, password=None, - session_timeout=None, session_id_file=None, + session_timeout=None, session_validation_ticket_id=1, + webservicename_link=None, proxies=None, https_verify=True, ca_cert_bundle=None, - operation_map=None, - type_map=None): + operation_map=None): if not baseurl: raise ArgumentMissingError("baseurl") @@ -741,11 +742,6 @@ class Client(object): else: self.operation_map = OPERATION_MAPPING_DEFAULT - if type_map: - self.type_map = type_map - else: - self.type_map = TYPE_MAPPING_DEFAULT - # credentials self.username = username self.password = password @@ -1254,7 +1250,7 @@ class Client(object): if not payload: raise ArgumentMissingError("payload") - self._result_type = self.type_map[self.operation] + self._result_type = self.operation_map[self.operation]["Result"] url = self._build_url(ticket_id) -- GitLab