Skip to content

Commit ae6d7d3

Browse files
changing endpoint property to str and moving HttpEndpoint to __build_http_request
1 parent 205bc84 commit ae6d7d3

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

socketlabs/injectionapi/core/httpendpoint.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1+
from urllib.parse import urlparse
2+
13
class HttpEndpoint(object):
24
"""
35
The HTTP endpoint
46
"""
57

6-
def __init__(self, host: str = None, url: str = None):
8+
def __init__(self, url: str):
79
"""
810
Create an instance of the HttpEndpoint class
911
:param host: the host name
1012
:type host: str
1113
:param url: the url
1214
:type url: str
1315
"""
14-
self._host = host
15-
self._url = url
16+
parsed_url = urlparse(url)
17+
self._host = parsed_url.hostname
18+
self._url = parsed_url.path
19+
1620

1721
@property
1822
def url(self):

socketlabs/injectionapi/socketlabsclient.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self, server_id: int, api_key: str, proxy: Proxy = None):
3838
self._http_proxy = proxy
3939
self._request_timeout = 120
4040
self._number_of_retries = 0
41-
self._http_endpoint = HttpEndpoint("inject.socketlabs.com", "/api/v1/email")
41+
self._http_endpoint = "https://inject.socketlabs.com/api/v1/email"
4242

4343
@property
4444
def endpoint(self):
@@ -49,8 +49,8 @@ def endpoint(self):
4949
"""
5050
return self._http_endpoint
5151

52-
@property.setter
53-
def endpoint(self, http_endpoint: HttpEndpoint):
52+
@endpoint.setter
53+
def endpoint(self, http_endpoint: str):
5454
"""
5555
The SocketLabs Injection API endpoint
5656
:return the Http Endpoint for the request
@@ -101,7 +101,8 @@ def __build_http_request(self, authentication: str):
101101
:return the HttpRequest object to use for the request
102102
:rtype HttpRequest
103103
"""
104-
req = HttpRequest(HttpRequest.HttpRequestMethod.POST, self.__endpoint, self.request_timeout, authentication)
104+
endpoint = HttpEndpoint(self.endpoint)
105+
req = HttpRequest(HttpRequest.HttpRequestMethod.POST, endpoint, self.request_timeout, authentication)
105106
if self._http_proxy is not None:
106107
req.proxy = self._http_proxy
107108
return req

0 commit comments

Comments
 (0)