mirror of
https://codeberg.org/reflect/reflect-client-python.git
synced 2025-09-14 09:33:41 +02:00
Compare commits
No commits in common. "master" and "1.0.1" have entirely different histories.
4 changed files with 9 additions and 13 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -15,7 +15,6 @@ 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 #
|
||||||
######################
|
######################
|
||||||
|
|
|
@ -47,9 +47,7 @@ class Client:
|
||||||
|
|
||||||
# Close socket connection when class instance removed
|
# Close socket connection when class instance removed
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
# Close socket if connected
|
self._socket.close()
|
||||||
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.
|
||||||
|
@ -66,9 +64,9 @@ class Client:
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Append Authorization header if API key is provided
|
# Append Authentication header if API key is provided
|
||||||
if (self._key):
|
if (self._key):
|
||||||
headers["Authorization"] = f"Bearer {self._key}"
|
headers["Authentication"] = f"Bearer {self._key}"
|
||||||
|
|
||||||
return headers
|
return headers
|
||||||
|
|
||||||
|
@ -77,9 +75,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, verify=self._https_peer_verify, headers=self.http_headers(), data=json.dumps(payload))
|
resp = requests.request(method.name, self._endpoint + endpoint, headers=self.http_headers(), data=json.dumps(payload))
|
||||||
# Return response as tuple of response code and response body as decoded JSON (mixed)
|
# Return response as tuple of response code and response body as plain text
|
||||||
return (resp.status_code, json.loads(resp.text))
|
return (resp.status_code, 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)}"]'
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
# 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
|
|
4
setup.py
4
setup.py
|
@ -2,12 +2,12 @@ from setuptools import setup, find_packages
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name = "reflect-client",
|
name = "reflect-client",
|
||||||
version = "1.1.2",
|
version = "1.0.1",
|
||||||
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", "requests"]
|
install_requires = ["validators"]
|
||||||
)
|
)
|
Loading…
Add table
Reference in a new issue