Skip to content
Snippets Groups Projects
Commit 940a810e authored by Robert Habermann's avatar Robert Habermann
Browse files

extend docs

parent e1cb4a5a
No related branches found
No related tags found
No related merge requests found
...@@ -34,6 +34,7 @@ extensions = [ ...@@ -34,6 +34,7 @@ extensions = [
'sphinx.ext.autodoc', 'sphinx.ext.autodoc',
'sphinx.ext.intersphinx', 'sphinx.ext.intersphinx',
'sphinx.ext.ifconfig', 'sphinx.ext.ifconfig',
'sphinx.ext.autosummary',
'sphinxcontrib.napoleon', 'sphinxcontrib.napoleon',
] ]
......
pyotrs pyotrs
====== ======
:mod:`pyotrs`
-------------
.. automodule:: pyotrs
:members:
:undoc-members:
:show-inheritance:
:mod:`pyotrs.client` Module :mod:`pyotrs.client` Module
--------------------------- ---------------------------
.. automodule:: pyotrs.client .. automodule:: pyotrs.client
:members: :members:
:private-members:
:undoc-members: :undoc-members:
:show-inheritance: :show-inheritance:
:noindex:
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Python wrapper for OTRS (using REST API) """
Name: pyotrs.py
Description: PyOTRS .. module:: pyotrs.client
:platform: Unix
:synopsis: Python wrapper for OTRS (using REST API)
.. moduleauthor:: Robert Habermann <robert.habermann@dlh.de>
.. autosummary::
.. note::
Roughly implements: https://otrs.github.io/doc/api/otrs/5.0/Perl/index.html
Author: robert.habermann@dlh.de This should work too::
Date: 2015-07-20
from pyotrs import Client
client = Client("https://otrs.example.com", "GenericTicketConnectorREST", "root@localhost", "x")
client.session_restore_or_set_up_new()
client.ticket_get_by_id(1)
https://otrs.github.io/doc/api/otrs/5.0/Perl/index.html
``` .. note::
Kernel::GenericInterface::Operation GenericInterface Operation interface
Kernel::GenericInterface::Operation foo bar
::Common Base class for all Operations
::Session::Common Base class for Session Operations Kernel::GenericInterface::Operation GenericInterface Operation interface
::Session::SessionCreate GenericInterface Session Create Operation backend Kernel::GenericInterface::Operation
::Test::Test GenericInterface Operation Test backend ::Common Base class for all Operations
::Ticket::Common Base class for all Ticket Operations ::Session::Common Base class for Session Operations
::Ticket::TicketCreate GenericInterface Ticket TicketCreate Operation backend ::Session::SessionCreate GenericInterface Session Create Operation backend
::Ticket::TicketGet GenericInterface Ticket Get Operation backend ::Test::Test GenericInterface Operation Test backend
::Ticket::TicketSearch GenericInterface Ticket Search Operation backend ::Ticket::Common Base class for all Ticket Operations
::Ticket::TicketUpdate GenericInterface Ticket TicketUpdate Operation backend ::Ticket::TicketCreate GenericInterface Ticket TicketCreate Operation backend
``` ::Ticket::TicketGet GenericInterface Ticket Get Operation backend
::Ticket::TicketSearch GenericInterface Ticket Search Operation backend
::Ticket::TicketUpdate GenericInterface Ticket TicketUpdate Operation backend
""" """
...@@ -110,7 +123,19 @@ class OTRSHTTPError(PyOTRSError): ...@@ -110,7 +123,19 @@ class OTRSHTTPError(PyOTRSError):
class Client(object): class Client(object):
"""PyOTRS Client class - includes Session handling""" """PyOTRS Client class - includes Session handling
Args:
baseurl (str): Base URL for OTRS System, no trailing slash e.g. http://otrs.example.com
webservicename (str): OTRS REST Web Service Name
username (str): Username
password (str): Password
session_id (str): Session ID
session_id_file (str): Session ID full path on disk, used to persistently store Session ID
session_timeout (int): Session Timeout configured in OTRS (usually 28800 seconds = 8h)
https_verify (bool): Should HTTPS certificates be verified (defaults to True)
"""
def __init__(self, def __init__(self,
baseurl, baseurl,
...@@ -168,12 +193,12 @@ class Client(object): ...@@ -168,12 +193,12 @@ class Client(object):
def session_valid(self): def session_valid(self):
""" check whether Session ID (self.session_id) is currently valid """ check whether Session ID (self.session_id) is currently valid
Returns:
bool: True if valid, False otherwise.
Raises: Raises:
SessionError is self.session_id is not set SessionError is self.session_id is not set
Returns:
bool: True if valid, False otherwise.
""" """
if not self.session_id: if not self.session_id:
...@@ -191,6 +216,9 @@ class Client(object): ...@@ -191,6 +216,9 @@ class Client(object):
def session_create(self): def session_create(self):
""" create new OTRS Session and store Session ID """ create new OTRS Session and store Session ID
Returns:
bool: True if successful, False otherwise.
""" """
url = "{0.baseurl}/otrs/nph-genericinterface.pl/Webservice/" \ url = "{0.baseurl}/otrs/nph-genericinterface.pl/Webservice/" \
...@@ -225,6 +253,10 @@ class Client(object): ...@@ -225,6 +253,10 @@ class Client(object):
Raises: Raises:
SessionCreateError SessionCreateError
SessionIDFileError SessionIDFileError
Returns:
bool: True if successful, False otherwise.
""" """
# try to read session_id from file # try to read session_id from file
...@@ -253,6 +285,9 @@ class Client(object): ...@@ -253,6 +285,9 @@ class Client(object):
def _read_session_id_from_file(self): def _read_session_id_from_file(self):
""" Retrieve a stored Session ID from file """ Retrieve a stored Session ID from file
Returns:
bool: True if successful, False otherwise.
""" """
if os.path.isfile(self.session_id_file): if os.path.isfile(self.session_id_file):
with open(self.session_id_file, "r") as f: with open(self.session_id_file, "r") as f:
...@@ -277,8 +312,11 @@ class Client(object): ...@@ -277,8 +312,11 @@ class Client(object):
def _write_session_id_to_file(self): def _write_session_id_to_file(self):
""" Write and store a Session ID to file (rw for user only) """ Write and store a Session ID to file (rw for user only)
Todo: Notes:
Error Handling and return True/False Todo: Error Handling and return True/False
Returns:
bool: True if successful, False otherwise.
""" """
with os.fdopen(os.open(self.session_id_file, os.O_WRONLY | os.O_CREAT, 0o600), 'w') as f: with os.fdopen(os.open(self.session_id_file, os.O_WRONLY | os.O_CREAT, 0o600), 'w') as f:
...@@ -289,7 +327,14 @@ class Client(object): ...@@ -289,7 +327,14 @@ class Client(object):
def _remove_session_id_file(self): def _remove_session_id_file(self):
""" remove session id file (e.g. when it only contains an invalid session id """ remove session id file (e.g. when it only contains an invalid session id
Todo: Notes:
Todo: Implement this?!
Raises:
NotImplementedError
Returns:
bool: True if successful, False otherwise.
""" """
raise NotImplementedError("Not yet done") raise NotImplementedError("Not yet done")
...@@ -415,13 +460,14 @@ class Client(object): ...@@ -415,13 +460,14 @@ class Client(object):
def _parse_response_dynamic_fields(self): def _parse_response_dynamic_fields(self):
""" Parses dynamic field from response and stores dict in self.ticket_dynamic_fields """ Parses dynamic field from response and stores dict in self.ticket_dynamic_fields
Returns:
True
Raises: Raises:
TicketDynamicFieldsNoRequestedError TicketDynamicFieldsNoRequestedError
TicketDynamicFieldsParseError TicketDynamicFieldsParseError
Returns:
bool: True if valid, False otherwise.
""" """
if not self.ticket_dynamic_fields_requested: if not self.ticket_dynamic_fields_requested:
...@@ -450,15 +496,15 @@ class Client(object): ...@@ -450,15 +496,15 @@ class Client(object):
"""Wrapper for search ticket """Wrapper for search ticket
Args: Args:
**kwargs **kwargs: Key, Value pairs for Dynamic Field search
Returns:
list: tickets that were found
Notes: Notes:
If value of kwargs is a datetime object then this object will be If value of kwargs is a datetime object then this object will be
converted to the appropriate string format for REST API. converted to the appropriate string format for REST API.
Returns:
list: tickets that were found
""" """
url = "{0.baseurl}/otrs/nph-genericinterface.pl/Webservice/" \ url = "{0.baseurl}/otrs/nph-genericinterface.pl/Webservice/" \
...@@ -487,7 +533,7 @@ class Client(object): ...@@ -487,7 +533,7 @@ class Client(object):
"""Wrapper for search ticket for full text search """Wrapper for search ticket for full text search
Args: Args:
pattern (str) pattern (str): Search pattern (a % will be added to from and end automatically)
Returns: Returns:
list: tickets that were found list: tickets that were found
...@@ -699,10 +745,10 @@ class Client(object): ...@@ -699,10 +745,10 @@ class Client(object):
""" datetime_to_pending_time_str """ datetime_to_pending_time_str
Args: Args:
datetime_obj: datetime_obj (datetime):
Returns: Returns:
str: representing the pending time string format for OTRS REST interface str: The pending time in the format required for OTRS REST interface
""" """
pending_time_str = { pending_time_str = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment