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

Merge branch 'get-with-params' into 'master'

Sent GET with params

Closes #27

See merge request rhab/PyOTRS!20
parents ca9db794 3a2c1191
No related branches found
No related tags found
No related merge requests found
......@@ -13,9 +13,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1.0.0 - planned first release
-----------------------------
0.7.x - 2020-xx-yy (unreleased)
0.8.x - 2020-xx-yy (unreleased)
-------------------------------
0.7.0 - 2020-04-06
------------------
- fix #27: GET must not contain a body (OTRS: #14203)
0.6.0 - 2020-03-13
------------------
- add: auth to Client (e.g. for HTTP BasicAuth)
......
The MIT License (MIT)
Copyright (c) 2016-2018 Robert Habermann
Copyright (c) 2016-2020 Robert Habermann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......
......@@ -8,7 +8,7 @@ Overview
:target: https://badge.fury.io/py/PyOTRS
:alt: |version|
.. |BuildStatus| image:: https://gitlab.com/rhab/PyOTRS/badges/master/build.svg
.. |BuildStatus| image:: https://gitlab.com/rhab/PyOTRS/badges/master/pipeline.svg
:target: https://gitlab.com/rhab/PyOTRS/commits/master
:alt: Build Status
......@@ -16,25 +16,29 @@ Overview
:target: https://gitlab.com/rhab/PyOTRS/commits/master
:alt: Coverage Report
.. |DocsBuildStatus| image:: https://readthedocs.org/projects/pyotrs/badge/?version=latest
:target: https://pyotrs.readthedocs.org/en/latest/index.html
.. |DocsBuildStatus| image:: https://readthedocs.org/projects/pyotrs/badge/?version=stable
:target: https://pyotrs.readthedocs.org/en/stable/index.html
:alt: Docs Build Status
.. |LicenseBadge| image:: https://img.shields.io/badge/license-MIT-blue.svg
:target: https://gitlab.com/rhab/PyOTRS/raw/master/LICENSE
:target: https://gitlab.com/rhab/PyOTRS/-/blob/master/LICENSE
:alt: MIT licensed
.. |PythonVersions| image:: https://img.shields.io/badge/python-2.7%2C%203.3%2C%203.4%2C%203.5%2C%203.6-blue.svg
:alt: python: 2.7, 3.4, 3.5, 3.6, 3.7
.. |PythonVersions| image:: https://img.shields.io/badge/python-2.7%2C%203.4%2C%203.5%2C%203.6%2C%203.7%2C%203.8-blue.svg
:alt: python: 2.7, 3.4, 3.5, 3.6, 3.7, 3.8
PyOTRS is a Python wrapper for accessing `OTRS <https://www.otrs.com/>`_ (Version 5, 6, 7 or 8) using the
(GenericInterface) REST API.
Warning
=======
PyOTRS is a Python wrapper for accessing `OTRS <https://www.otrs.com/>`_ (Version 5 or 6) using the
REST API.
Please upgrade PyOTRS to atleast version 0.7.0 if you are using OTRS 6.0.27, 7.0.16 or
newer. See `issue 27 <https://gitlab.com/rhab/PyOTRS/-/issues/27>`_ for more details.
Features
--------
========
Access an OTRS instance to::
......
......@@ -128,6 +128,7 @@ class HTTPError(PyOTRSError):
class Article(object):
"""PyOTRS Article class """
def __init__(self, dct):
fields = {}
for key, value in dct.items():
......@@ -300,6 +301,7 @@ class Article(object):
class Attachment(object):
"""PyOTRS Attachment class """
def __init__(self, dct):
self.__dict__ = dct
......@@ -499,6 +501,7 @@ class Ticket(object):
dynamic_fields (list): List of DynamicField objects
"""
def __init__(self, dct):
# store OTRS Top Level fields
self.fields = {}
......@@ -730,6 +733,7 @@ class SessionStore(object):
ArgumentMissingError
"""
def __init__(self, file_path=None, session_timeout=None,
value=None, created=None, expires=None):
if not file_path:
......@@ -874,6 +878,7 @@ class Client(object):
"/otrs/nph-genericinterface.pl/Webservice/"
"""
def __init__(self,
baseurl=None,
username=None,
......@@ -974,6 +979,7 @@ class Client(object):
* session_create
* session_restore_or_set_up_new # try to get session_id from a (json) file on disc
"""
def session_check_is_valid(self, session_id=None):
"""check whether session_id is currently valid
......@@ -1074,6 +1080,7 @@ class Client(object):
GenericInterface::Operation::Ticket::TicketCreate
* ticket_create
"""
def ticket_create(self,
ticket=None,
article=None,
......@@ -1131,6 +1138,7 @@ class Client(object):
* ticket_get_by_list
* ticket_get_by_number
"""
def ticket_get_by_id(self,
ticket_id,
articles=False,
......@@ -1274,6 +1282,7 @@ class Client(object):
* ticket_search
* ticket_search_full_text
"""
def ticket_search(self, dynamic_fields=None, **kwargs):
"""Search for ticket
......@@ -1341,6 +1350,7 @@ class Client(object):
* ticket_update
* ticket_update_set_pending
"""
def ticket_update(self,
ticket_id,
article=None,
......@@ -1560,6 +1570,7 @@ class Client(object):
GenericInterface::Operation::Link::LinkAdd
* link_add
"""
def link_add(self,
src_object_id,
dst_object_id,
......@@ -1604,6 +1615,7 @@ class Client(object):
GenericInterface::Operation::Link::LinkDelete
* link_delete
"""
def link_delete(self,
src_object_id,
dst_object_id,
......@@ -1645,9 +1657,10 @@ class Client(object):
GenericInterface::Operation::Link::LinkDeleteAll
* link_delete_all
"""
def link_delete_all(self,
object_id,
object_type="Ticket",):
object_type="Ticket"):
"""link_delete_all
Args:
......@@ -1676,6 +1689,7 @@ class Client(object):
GenericInterface::Operation::Link::LinkList
* link_list
"""
def link_list(self,
src_object_id,
src_object_type="Ticket",
......@@ -1727,6 +1741,7 @@ class Client(object):
GenericInterface::Operation::Link::PossibleLinkList
* link_possible_link_list
"""
def link_possible_link_list(self):
"""link_possible_link_list
......@@ -1752,6 +1767,7 @@ class Client(object):
GenericInterface::Operation::Link::PossibleObjectsList
* link_possible_objects_list
"""
def link_possible_objects_list(self,
object_type="Ticket"):
"""link_possible_objects_list
......@@ -1783,6 +1799,7 @@ class Client(object):
GenericInterface::Operation::Link::PossibleTypesList
* link_possible_types_list
"""
def link_possible_types_list(self,
src_object_type="Ticket",
dst_object_type="Ticket"):
......@@ -1878,32 +1895,58 @@ class Client(object):
if http_method not in ["DELETE", "GET", "HEAD", "PATCH", "POST", "PUT"]:
raise ValueError("invalid http_method")
headers = {"Content-Type": "application/json"}
headers = {}
if self.user_agent:
headers.update({"User-Agent": self.user_agent})
json_payload = json.dumps(payload)
# ("sending {0} to {1} as {2}".format(payload, url, http_method.upper()))
if http_method == "GET":
try:
response = requests.request(http_method.upper(),
url,
headers=headers,
data=json_payload,
proxies=self.proxies,
verify=self.https_verify,
cert=self.client_auth_cert,
auth=self.auth)
# store a copy of the request
self._request = response.request
# critical error: HTTP request resulted in an error!
except Exception as err:
# raise OTRSHTTPError("get http")
raise HTTPError("Failed to access OTRS. Check Hostname, Proxy, SSL Certificate!\n"
"Error with http communication: {0}".format(err))
# print("sending {0} to {1} as {2}".format(payload, url, http_method.upper()))
try:
response = requests.request("GET",
url,
headers=headers,
params=payload,
proxies=self.proxies,
verify=self.https_verify,
cert=self.client_auth_cert,
auth=self.auth)
# store a copy of the request
self._request = response.request
# critical error: HTTP request resulted in an error!
except Exception as err:
# raise OTRSHTTPError("get http")
raise HTTPError("Failed to access OTRS. Check Hostname, Proxy, SSL Certificate!\n"
"Error with http communication: {0}".format(err))
else:
headers.update({"Content-Type": "application/json"})
json_payload = json.dumps(payload)
# print("sending {0} to {1} as {2}".format(payload, url, http_method.upper()))
try:
response = requests.request(http_method.upper(),
url,
headers=headers,
data=json_payload,
proxies=self.proxies,
verify=self.https_verify,
cert=self.client_auth_cert,
auth=self.auth)
# store a copy of the request
self._request = response.request
# critical error: HTTP request resulted in an error!
except Exception as err:
# raise OTRSHTTPError("get http")
raise HTTPError("Failed to access OTRS. Check Hostname, Proxy, SSL Certificate!\n"
"Error with http communication: {0}".format(err))
if not response.status_code == 200:
raise HTTPError("Received HTTP Error. Check Hostname and WebServiceName.\n"
......
......@@ -4,5 +4,5 @@
# 3) we can import it into your module module
"""
__version_info__ = ('0', '6', '0')
__version_info__ = ('0', '7', '0')
__version__ = '.'.join(__version_info__)
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