mss-python 0.1.1__tar.gz → 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mss_python-0.1.1 → mss_python-0.1.3}/PKG-INFO +1 -1
- {mss_python-0.1.1 → mss_python-0.1.3}/setup.py +1 -1
- mss_python-0.1.3/src/mss_python/client.py +111 -0
- mss_python-0.1.3/src/mss_python/request/__init__.py +0 -0
- mss_python-0.1.1/src/request/methods.py → mss_python-0.1.3/src/mss_python/request/method_names.py +1 -22
- mss_python-0.1.3/src/mss_python/request/methods.py +23 -0
- {mss_python-0.1.1/src → mss_python-0.1.3/src/mss_python}/request/types_mss.py +5 -4
- {mss_python-0.1.1 → mss_python-0.1.3}/src/mss_python.egg-info/PKG-INFO +1 -1
- mss_python-0.1.3/src/mss_python.egg-info/SOURCES.txt +13 -0
- mss_python-0.1.3/src/mss_python.egg-info/top_level.txt +1 -0
- mss_python-0.1.1/src/mss_python.egg-info/SOURCES.txt +0 -10
- mss_python-0.1.1/src/mss_python.egg-info/top_level.txt +0 -1
- {mss_python-0.1.1 → mss_python-0.1.3}/LICENSE +0 -0
- {mss_python-0.1.1 → mss_python-0.1.3}/README.md +0 -0
- {mss_python-0.1.1 → mss_python-0.1.3}/setup.cfg +0 -0
- {mss_python-0.1.1/src/request → mss_python-0.1.3/src/mss_python}/__init__.py +0 -0
- {mss_python-0.1.1 → mss_python-0.1.3}/src/mss_python.egg-info/dependency_links.txt +0 -0
|
@@ -36,7 +36,7 @@ setup(
|
|
|
36
36
|
# For a discussion on single-sourcing the version across setup.py and the
|
|
37
37
|
# project code, see
|
|
38
38
|
# https://packaging.python.org/guides/single-sourcing-package-version/
|
|
39
|
-
version="0.1.
|
|
39
|
+
version="0.1.3", # Required
|
|
40
40
|
# This is a one-line description or tagline of what your project does. This
|
|
41
41
|
# corresponds to the "Summary" metadata field:
|
|
42
42
|
# https://packaging.python.org/specifications/core-metadata/#summary
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import xmltodict
|
|
3
|
+
import xml.etree.ElementTree as ET
|
|
4
|
+
|
|
5
|
+
from .request.methods import Method
|
|
6
|
+
from .request.types_mss import Root, BaseType, Credentials, Search, MethodName, Literal
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# maybe recursion should be used instead of doing if checks?
|
|
10
|
+
def change_structure(root: Root, child: BaseType):
|
|
11
|
+
if child.tag == "root":
|
|
12
|
+
return child
|
|
13
|
+
|
|
14
|
+
if child.tag == "request":
|
|
15
|
+
root.request = child
|
|
16
|
+
|
|
17
|
+
elif child.tag == "search":
|
|
18
|
+
root.request.search = child
|
|
19
|
+
|
|
20
|
+
elif child.tag == "order":
|
|
21
|
+
root.request.order = child
|
|
22
|
+
|
|
23
|
+
elif child.tag == "options":
|
|
24
|
+
root.request.options = child
|
|
25
|
+
|
|
26
|
+
elif child.tag == "logging":
|
|
27
|
+
root.request.logging = child
|
|
28
|
+
|
|
29
|
+
elif child.tag == "header":
|
|
30
|
+
root.header = child
|
|
31
|
+
|
|
32
|
+
return root
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class Client:
|
|
36
|
+
def __init__(
|
|
37
|
+
self, cred: Credentials, lang: list, elements: list | None = None
|
|
38
|
+
) -> None:
|
|
39
|
+
self.cred = cred
|
|
40
|
+
self.lang = Search(lang)
|
|
41
|
+
|
|
42
|
+
def request(
|
|
43
|
+
self,
|
|
44
|
+
url: str,
|
|
45
|
+
method_name: MethodName,
|
|
46
|
+
data: BaseType | None = None,
|
|
47
|
+
_print: Literal[True, False] = False,
|
|
48
|
+
) -> dict:
|
|
49
|
+
"""
|
|
50
|
+
Makes a post request to the given URL with the specified data and method name.
|
|
51
|
+
|
|
52
|
+
data: ElementTree with the data required in the XML
|
|
53
|
+
url: Service URL
|
|
54
|
+
method: Method to be executed by the service
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
method = Method(method_name)
|
|
58
|
+
|
|
59
|
+
root = method.get_base_xml(self.cred, self.lang)
|
|
60
|
+
|
|
61
|
+
if data is None:
|
|
62
|
+
root = change_structure(root, data)
|
|
63
|
+
|
|
64
|
+
if _print is True:
|
|
65
|
+
print(ET.tostring(root.request.to_xml(), encoding="unicode"))
|
|
66
|
+
|
|
67
|
+
response = requests.post(
|
|
68
|
+
url,
|
|
69
|
+
data=ET.tostring(root.to_xml(), encoding="unicode"),
|
|
70
|
+
headers={"Content-Type": "application/xml"},
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
responseRoot = xmltodict.parse(response.content)
|
|
74
|
+
error = responseRoot["root"]["header"]["error"]
|
|
75
|
+
if int(error["code"]) > 0:
|
|
76
|
+
raise Exception(
|
|
77
|
+
f'MSS returned an error: code {error["code"]}, message: "{error["message"]}"'
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
return refine_response(responseRoot["root"], method_name)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def refine_response(resp: dict, meth: MethodName) -> dict:
|
|
84
|
+
if meth == MethodName.GetHotelList:
|
|
85
|
+
return refine_getHotelList(resp)
|
|
86
|
+
|
|
87
|
+
return resp
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def refine_getHotelList(resp: dict) -> dict:
|
|
91
|
+
if resp["result"] is None:
|
|
92
|
+
return resp
|
|
93
|
+
elif "hotel" not in resp["result"] or resp["result"]["hotel"] is None:
|
|
94
|
+
return resp
|
|
95
|
+
elif resp["result"]["hotel"] is list:
|
|
96
|
+
resp["result"]["hotel"] = [resp["result"]["hotel"]]
|
|
97
|
+
|
|
98
|
+
for hotel in resp["result"]["hotel"]:
|
|
99
|
+
ensure_list_value(hotel, "pictures", "picture")
|
|
100
|
+
ensure_list_value(hotel, "gallery", "picture")
|
|
101
|
+
ensure_list_value(hotel, "feature_view", "feature")
|
|
102
|
+
ensure_list_value(hotel, "pos", "id_pos")
|
|
103
|
+
|
|
104
|
+
return resp
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def ensure_list_value(hotel: dict, parent_fld: str, child_fld: str) -> None:
|
|
108
|
+
if parent_fld not in hotel:
|
|
109
|
+
hotel[parent_fld] = {child_fld: []}
|
|
110
|
+
elif hotel[parent_fld][child_fld] is list:
|
|
111
|
+
hotel[parent_fld][child_fld] = [hotel[parent_fld][child_fld]]
|
|
File without changes
|
mss_python-0.1.1/src/request/methods.py → mss_python-0.1.3/src/mss_python/request/method_names.py
RENAMED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
from
|
|
2
|
-
import xml.etree.ElementTree as ET
|
|
3
|
-
from request.types_mss import * # might need change
|
|
1
|
+
from enum import Enum
|
|
4
2
|
|
|
5
3
|
|
|
6
4
|
class MethodName(Enum):
|
|
@@ -28,22 +26,3 @@ class MethodName(Enum):
|
|
|
28
26
|
GetHotelPictureGroups = "getHotelPictureGroups"
|
|
29
27
|
GetOptionalServices = "getOptionalServices"
|
|
30
28
|
ValidateCoupon = "validateCoupon"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class Method:
|
|
34
|
-
def __init__(self, name: MethodName):
|
|
35
|
-
self.name = name
|
|
36
|
-
|
|
37
|
-
def get_base_xml(self, cred: Credentials, lang: Search) -> Root:
|
|
38
|
-
"""
|
|
39
|
-
Returns an XML (ElementTree) with the mandatory elements needed for the request.
|
|
40
|
-
|
|
41
|
-
cred: XML Credentials Element (username, password, source)
|
|
42
|
-
|
|
43
|
-
lang: XML Search Element with the language element defined
|
|
44
|
-
"""
|
|
45
|
-
|
|
46
|
-
header = Header(cred, self.name)
|
|
47
|
-
req = Request(lang)
|
|
48
|
-
root = Root(header, req)
|
|
49
|
-
return root
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from .method_names import MethodName
|
|
4
|
+
from .types_mss import Credentials, Search, Root, Header, Request
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Method:
|
|
8
|
+
def __init__(self, name: MethodName):
|
|
9
|
+
self.name = name
|
|
10
|
+
|
|
11
|
+
def get_base_xml(self, cred: Credentials, lang: Search) -> Root:
|
|
12
|
+
"""
|
|
13
|
+
Returns an XML (ElementTree) with the mandatory elements needed for the request.
|
|
14
|
+
|
|
15
|
+
cred: XML Credentials Element (username, password, source)
|
|
16
|
+
|
|
17
|
+
lang: XML Search Element with the language element defined
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
header = Header(cred, self.name)
|
|
21
|
+
req = Request(lang)
|
|
22
|
+
root = Root(header, req)
|
|
23
|
+
return root
|
|
@@ -4,7 +4,8 @@ from enum import Enum, IntFlag
|
|
|
4
4
|
from typing import Literal
|
|
5
5
|
import xml.etree.ElementTree as ET
|
|
6
6
|
from abc import ABC
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
from .method_names import MethodName
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
def get_child_xml(value, field, root):
|
|
@@ -35,8 +36,8 @@ class BaseType(ABC):
|
|
|
35
36
|
root = ET.Element(self.tag)
|
|
36
37
|
# root.append(self.search.to_xml())
|
|
37
38
|
|
|
38
|
-
for
|
|
39
|
-
get_child_xml(value,
|
|
39
|
+
for field_, value in vars(self).items():
|
|
40
|
+
get_child_xml(value, field_, root)
|
|
40
41
|
|
|
41
42
|
return root
|
|
42
43
|
|
|
@@ -624,7 +625,7 @@ class SpecialTheme(Enum):
|
|
|
624
625
|
ThemeIDBicycleTouring = 86
|
|
625
626
|
ThemeIDEBike = 87
|
|
626
627
|
|
|
627
|
-
##These values were theme_bit
|
|
628
|
+
## These values were theme_bit
|
|
628
629
|
# Hiking = 1
|
|
629
630
|
# Cycling = 2
|
|
630
631
|
# Family = 4
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
src/mss_python/__init__.py
|
|
5
|
+
src/mss_python/client.py
|
|
6
|
+
src/mss_python.egg-info/PKG-INFO
|
|
7
|
+
src/mss_python.egg-info/SOURCES.txt
|
|
8
|
+
src/mss_python.egg-info/dependency_links.txt
|
|
9
|
+
src/mss_python.egg-info/top_level.txt
|
|
10
|
+
src/mss_python/request/__init__.py
|
|
11
|
+
src/mss_python/request/method_names.py
|
|
12
|
+
src/mss_python/request/methods.py
|
|
13
|
+
src/mss_python/request/types_mss.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mss_python
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
LICENSE
|
|
2
|
-
README.md
|
|
3
|
-
setup.py
|
|
4
|
-
src/mss_python.egg-info/PKG-INFO
|
|
5
|
-
src/mss_python.egg-info/SOURCES.txt
|
|
6
|
-
src/mss_python.egg-info/dependency_links.txt
|
|
7
|
-
src/mss_python.egg-info/top_level.txt
|
|
8
|
-
src/request/__init__.py
|
|
9
|
-
src/request/methods.py
|
|
10
|
-
src/request/types_mss.py
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
request
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|