Compare commits

...

4 commits

4 changed files with 13 additions and 9 deletions

1
.gitignore vendored
View file

@ -15,6 +15,7 @@ Homestead.yaml
npm-debug.log npm-debug.log
yarn-error.log yarn-error.log
public/robots.txt public/robots.txt
__pycache__
# OS generated files # # OS generated files #
###################### ######################

View file

@ -47,7 +47,9 @@ class Client:
# Close socket connection when class instance removed # Close socket connection when class instance removed
def __del__(self): def __del__(self):
self._socket.close() # Close socket if connected
if (self._con == Connection.AF_UNIX):
self._socket.close()
# Resolve connection type from endpoint string. # Resolve connection type from endpoint string.
# If the string is a valid URL we will treat it as HTTP otherwise we will assume it's a path on disk to a UNIX socket file. # If the string is a valid URL we will treat it as HTTP otherwise we will assume it's a path on disk to a UNIX socket file.
@ -64,9 +66,9 @@ class Client:
"Content-Type": "application/json" "Content-Type": "application/json"
} }
# Append Authentication header if API key is provided # Append Authorization header if API key is provided
if (self._key): if (self._key):
headers["Authentication"] = f"Bearer {self._key}" headers["Authorization"] = f"Bearer {self._key}"
return headers return headers
@ -75,9 +77,9 @@ class Client:
# Remove leading "/" if present, as it's already present in self._endpoint # Remove leading "/" if present, as it's already present in self._endpoint
endpoint = endpoint if endpoint[-1] != "/" else endpoint[:-1] endpoint = endpoint if endpoint[-1] != "/" else endpoint[:-1]
resp = requests.request(method.name, self._endpoint + endpoint, headers=self.http_headers(), data=json.dumps(payload)) resp = requests.request(method.name, self._endpoint + endpoint, verify=self._https_peer_verify, headers=self.http_headers(), data=json.dumps(payload))
# Return response as tuple of response code and response body as plain text # Return response as tuple of response code and response body as decoded JSON (mixed)
return (resp.status_code, resp.text) return (resp.status_code, json.loads(resp.text))
def socket_txn(self, endpoint: str, method: Union[Method, str] = None, payload: list = None) -> tuple: def socket_txn(self, endpoint: str, method: Union[Method, str] = None, payload: list = None) -> tuple:
data = f'["{endpoint}","{method.name}","{json.dumps(payload)}"]' data = f'["{endpoint}","{method.name}","{json.dumps(payload)}"]'

View file

@ -1,2 +1,3 @@
# the "install_requires" array should also be updated when changing this # the "install_requires" array should also be updated when changing this
validators validators
requests

View file

@ -2,12 +2,12 @@ from setuptools import setup, find_packages
setup( setup(
name = "reflect-client", name = "reflect-client",
version = "1.0.1", version = "1.1.2",
description = "Python library for communicating with an API built with Reflect over HTTP or UNIX sockets", description = "Python library for communicating with an API built with Reflect over HTTP or UNIX sockets",
author = "Victor Westerlund", author = "Victor Westerlund",
author_email = "victor.vesterlund@gmail.com", author_email = "victor.vesterlund@gmail.com",
url = "https://github.com/victorwesterlund/reflect-client-python", url = "https://github.com/victorwesterlund/reflect-client-python",
packages = ["reflect_client"], packages = ["reflect_client"],
# The requirement.txt file should also be updated when changing this # The requirement.txt file should also be updated when changing this
install_requires = ["validators"] install_requires = ["validators", "requests"]
) )