Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions memoq/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ def __len__(self):
class MemoQServer(object):
"""Class that represents a memoQ server."""

def __init__(self, base_url: str):
def __init__(self, base_url: str, api_key: str):
"""
Initializer for the class.

:param base_url: Base URL for the memoQ server. For example, 'http://localhost:8080'
"""
self.base_url = base_url
self.api_key = api_key
self._all_projects = None
self._api_endpoints = {}
self._light_resources = None
Expand All @@ -84,7 +85,7 @@ def __repr__(self) -> str:

:returns: A str representing the memoQ server.
"""
return f"{self.__class__.__qualname__}(base_url='{self.base_url}')"
return f"{self.__class__.__qualname__}(base_url='{self.base_url}',api_key='{self.api_key}')"

def __str__(self) -> str:
"""
Expand All @@ -100,7 +101,8 @@ def _light_resource_service(self):
try:
return self._api_endpoints[light_resource_service_key]
except KeyError:
self._api_endpoints[light_resource_service_key] = MemoQLightResourceService(self.base_url)
self._api_endpoints[light_resource_service_key] = MemoQLightResourceService(
self.base_url, self.api_key)
return self._api_endpoints[light_resource_service_key]

@property
Expand All @@ -109,7 +111,8 @@ def _live_docs_service(self):
try:
return self._api_endpoints[live_docs_service_key]
except KeyError:
self._api_endpoints[live_docs_service_key] = MemoQLiveDocsService(self.base_url)
self._api_endpoints[live_docs_service_key] = MemoQLiveDocsService(
self.base_url, self.api_key)
return self._api_endpoints[live_docs_service_key]

@property
Expand All @@ -118,7 +121,8 @@ def _security_service(self):
try:
return self._api_endpoints[security_service_key]
except KeyError:
self._api_endpoints[security_service_key] = MemoQSecurityService(self.base_url)
self._api_endpoints[security_service_key] = MemoQSecurityService(
self.base_url, self.api_key)
return self._api_endpoints[security_service_key]

@property
Expand All @@ -127,7 +131,8 @@ def _server_project_service(self):
try:
return self._api_endpoints[server_project_service_key]
except KeyError:
self._api_endpoints[server_project_service_key] = MemoQServerProjectService(self.base_url)
self._api_endpoints[server_project_service_key] = MemoQServerProjectService(
self.base_url, self.api_key)
return self._api_endpoints[server_project_service_key]

@property
Expand Down Expand Up @@ -218,7 +223,8 @@ def light_resources(self) -> LightResources:
:returns: A LightResources instance, suitable for running dict style lookups.
"""
if self._light_resources is None:
self._light_resources = LightResources(self._light_resource_service)
self._light_resources = LightResources(
self._light_resource_service)
return self._light_resources

@property
Expand Down
51 changes: 30 additions & 21 deletions memoq/webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from abc import ABC, abstractmethod
from urllib.parse import urljoin

from zeep import CachingClient # https://python-zeep.readthedocs.io/en/master/client.html#caching-of-wsdl-and-xsd-files
# https://python-zeep.readthedocs.io/en/master/client.html#caching-of-wsdl-and-xsd-files
from zeep import CachingClient, xsd


DEFAULT_BASE_URL = 'http://localhost:8080'
Expand All @@ -22,14 +23,21 @@ class MemoQWebServiceBase(ABC):
Abstract Base Class for memoQ Web Service API Services.
"""

def __init__(self, base_url: str = None):
def __init__(self, base_url: str = None, api_key: str = None):
"""
Initializer for the class.

:param base_url: Base URL of the memoQ Web Service API, as a string. For example: "http://localhost:8080"
"""
self.base_url = base_url if base_url is not None else DEFAULT_BASE_URL
self.__client = CachingClient(wsdl=self.service_url)

client = CachingClient(wsdl=self.service_url)

if api_key:
header = xsd.ComplexType([xsd.Element('ApiKey', xsd.String())])
client.set_default_soapheaders([header(ApiKey=api_key)])

self.__client = client

def __dir__(self) -> list:
"""
Expand Down Expand Up @@ -74,13 +82,13 @@ class MemoQAsynchronousTasksService(MemoQWebServiceBase):
https://docs.memoq.com/current/api-docs/wsapi/memoqservices/tasksservice.html
"""

def __init__(self, base_url: str = None):
def __init__(self, base_url: str = None, api_key: str = None):
"""
Initializer for the class.

:param base_url: Base URL of the memoQ Web Service API, as a string. For example: "http://localhost:8080"
"""
super().__init__(base_url)
super().__init__(base_url, api_key)

@property
def service_url(self) -> str:
Expand All @@ -101,13 +109,13 @@ class MemoQELMService(MemoQWebServiceBase):
https://docs.memoq.com/current/api-docs/wsapi/memoqservices/elmservice.html
"""

def __init__(self, base_url: str = None):
def __init__(self, base_url: str = None, api_key: str = None):
"""
Initializer for the class.

:param base_url: Base URL of the memoQ Web Service API, as a string. For example: "http://localhost:8080"
"""
super().__init__(base_url)
super().__init__(base_url, api_key)

@property
def service_url(self) -> str:
Expand All @@ -128,13 +136,13 @@ class MemoQFileManagerService(MemoQWebServiceBase):
https://docs.memoq.com/current/api-docs/wsapi/memoqservices/filemanagerservice.html
"""

def __init__(self, base_url: str = None):
def __init__(self, base_url: str = None, api_key: str = None):
"""
Initializer for the class.

:param base_url: Base URL of the memoQ Web Service API, as a string. For example: "http://localhost:8080"
"""
super().__init__(base_url)
super().__init__(base_url, api_key)

@property
def service_url(self) -> str:
Expand All @@ -155,13 +163,13 @@ class MemoQLightResourceService(MemoQWebServiceBase):
https://docs.memoq.com/current/api-docs/wsapi/memoqservices/lightresourceservice.html
"""

def __init__(self, base_url: str = None):
def __init__(self, base_url: str = None, api_key: str = None):
"""
Initializer for the class.

:param base_url: Base URL of the memoQ Web Service API, as a string. For example: "http://localhost:8080"
"""
super().__init__(base_url)
super().__init__(base_url, api_key)

@property
def service_url(self) -> str:
Expand All @@ -182,13 +190,13 @@ class MemoQLiveDocsService(MemoQWebServiceBase):
https://docs.memoq.com/current/api-docs/wsapi/memoqservices/livedocsservice.html
"""

def __init__(self, base_url: str = None):
def __init__(self, base_url: str = None, api_key: str = None):
"""
Initializer for the class.

:param base_url: Base URL of the memoQ Web Service API, as a string. For example: "http://localhost:8080"
"""
super().__init__(base_url)
super().__init__(base_url, api_key)

@property
def service_url(self) -> str:
Expand All @@ -209,13 +217,13 @@ class MemoQSecurityService(MemoQWebServiceBase):
https://docs.memoq.com/current/api-docs/wsapi/memoqservices/securityservice.html
"""

def __init__(self, base_url: str = None):
def __init__(self, base_url: str = None, api_key: str = None):
"""
Initializer for the class.

:param base_url: Base URL of the memoQ Web Service API, as a string. For example: "http://localhost:8080"
"""
super().__init__(base_url)
super().__init__(base_url, api_key)

@property
def service_url(self) -> str:
Expand All @@ -236,13 +244,14 @@ class MemoQServerProjectService(MemoQWebServiceBase):
https://docs.memoq.com/current/api-docs/wsapi/memoqservices/serverprojectservice.html
"""

def __init__(self, base_url: str = None):
def __init__(self, base_url: str = None, api_key: str = None):
"""
Initializer for the class.

:param base_url: Base URL of the memoQ Web Service API, as a string. For example: "http://localhost:8080"
"""
super().__init__(base_url)
print("adsdasdadas")
Copy link

@vasokot vasokot Feb 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this???

super().__init__(base_url, api_key)

@property
def service_url(self) -> str:
Expand All @@ -263,13 +272,13 @@ class MemoQTBService(MemoQWebServiceBase):
https://docs.memoq.com/current/api-docs/wsapi/memoqservices/tbservice.html
"""

def __init__(self, base_url: str = None):
def __init__(self, base_url: str = None, api_key: str = None):
"""
Initializer for the class.

:param base_url: Base URL of the memoQ Web Service API, as a string. For example: "http://localhost:8080"
"""
super().__init__(base_url)
super().__init__(base_url, api_key)

@property
def service_url(self) -> str:
Expand All @@ -290,13 +299,13 @@ class MemoQTMService(MemoQWebServiceBase):
https://docs.memoq.com/current/api-docs/wsapi/memoqservices/tmservice.html
"""

def __init__(self, base_url: str = None):
def __init__(self, base_url: str = None, api_key: str = None):
"""
Initializer for the class.

:param base_url: Base URL of the memoQ Web Service API, as a string. For example: "http://localhost:8080"
"""
super().__init__(base_url)
super().__init__(base_url, api_key)

@property
def service_url(self) -> str:
Expand Down