Coverage for centralnicreseller / apiconnector / socketconfig.py: 100%
38 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-21 15:25 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-21 15:25 +0000
1# -*- coding: utf-8 -*-
2"""
3 centralnicreseller.apiconnector.socketconfig
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 This module covers all necessary functionality to
6 pre-configure http communication with our Backend System.
7 :copyright: © 2024 Team Internet Group PLC.
8 :license: MIT, see LICENSE for more details.
9"""
11from urllib.parse import quote, unquote
14class SocketConfig(object):
15 """
16 The SocketConfig class helps to configure the http communcation with our Backend System.
17 """
19 def __init__(self):
20 # account name
21 self.__login = None
22 # account password
23 self.__pw = None
24 # API session id
25 self.__sessionid = None
26 # API persistent connection for session
27 self.__persistent = None
29 def getPOSTData(self):
30 """
31 Create POST data string out of connection data
32 """
33 data = []
34 tpl = "{0}={1}&"
35 keys = ["__login", "__pw", "__sessionid", "__persistent"]
37 for key in keys:
38 item = getattr(self, "_SocketConfig" + key)
39 if item:
40 if key == "__persistent":
41 data.append(tpl.format(quote(key[2:]), quote(item)))
42 else:
43 data.append(tpl.format(quote("s_" + key[2:]), quote(item)))
45 return "".join(data)
47 def getSession(self):
48 """
49 Get API Session ID in use
50 """
51 return self.__sessionid
53 def getLogin(self):
54 """
55 get account login to use
56 """
57 return self.__login
59 def setLogin(self, value):
60 """
61 Set account name to use
62 """
63 self.__login = value
64 return self
66 def setPassword(self, value):
67 """
68 Set account password to use
69 """
70 self.__sessionid = None
71 self.__pw = value
72 return self
74 def setSession(self, value):
75 """
76 Set API Session ID to use
77 """
78 self.__pw = None
79 self.__persistent = None
80 self.__sessionid = value
81 return self
83 def setPersistent(self):
84 """
85 Set API persistent connection for session
86 """
87 self.__sessionid = None
88 self.__persistent = "1"
89 return self