Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflows #25

Merged
merged 4 commits into from
Oct 14, 2024
Merged
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
3 changes: 2 additions & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
- master
jobs:
Code_Analysis_Job:
if: ${{ ! github.event.pull_request.head.repo.fork }}
runs-on: ubuntu-latest
environment: test
steps:
Expand All @@ -23,4 +24,4 @@ jobs:
env:
ULTRADNS_UNIT_TEST_USERNAME: ${{ secrets.ULTRADNS_UNIT_TEST_USERNAME }}
ULTRADNS_UNIT_TEST_PASSWORD: ${{ secrets.ULTRADNS_UNIT_TEST_PASSWORD }}
ULTRADNS_UNIT_TEST_HOST_URL: ${{ secrets.ULTRADNS_UNIT_TEST_HOST_URL }}
ULTRADNS_UNIT_TEST_HOST_URL: ${{ secrets.ULTRADNS_UNIT_TEST_HOST_URL }}
6 changes: 5 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
- master
jobs:
Code_Analysis_Job:
if: ${{ ! github.event.pull_request.head.repo.fork }}
runs-on: ubuntu-latest
environment: test
steps:
Expand Down Expand Up @@ -50,6 +49,11 @@ jobs:
-
name: Creating python Package
run: hatch build
-
name: create release Tag
run: |
git tag ${{ env.RELEASE_VERSION }}
git push origin ${{ env.RELEASE_VERSION }}
-
name: Publishing python Package
uses: pypa/gh-action-pypi-publish@v1.10.1
Expand Down
2 changes: 1 addition & 1 deletion .plugin-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.1
2.2.2
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ password = os.getenv('PASSWORD')
if not username or not password:
raise ValueError("Username and password must be set in environment variables.")

client = RestApiClient(your_username, your_password)
client = RestApiClient(username, password)

domain = "udns-python-rest-client-test.com."

Expand Down
22 changes: 16 additions & 6 deletions ultra_rest_client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# store the URL and the access/refresh tokens as state
import requests
import time
from .about import get_client_user_agent

class AuthError(Exception):
Expand Down Expand Up @@ -118,6 +119,10 @@ def _do_call(self, uri, method, params=None, body=None, retry=True, files=None,
if response.status_code == requests.codes.NO_CONTENT:
return {}

if response.status_code == requests.codes.TOO_MANY:
time.sleep(1)
return self._do_call(uri, method, params, body, False)

# some endpoints have no content-type header
if 'content-type' not in response.headers:
response.headers['content-type'] = 'none'
Expand All @@ -130,14 +135,19 @@ def _do_call(self, uri, method, params=None, body=None, retry=True, files=None,
if response.headers.get('content-type') == 'application/zip':
return response.content

json_body = response.json()
# if this is a background task, add the task id (or location) to the body
if response.status_code == requests.codes.ACCEPTED:
json_body['task_id'] = response.headers.get('x-task-id')
json_body = {}
try:
json_body = response.json()

# if this is a background task, add the task id (or location) to the body
if response.status_code == requests.codes.ACCEPTED:
if 'x-task-id' in response.headers:
json_body['task_id'] = response.headers['x-task-id']
json_body.update({"task_id": response.headers['x-task-id']})
if 'location' in response.headers:
json_body['location'] = response.headers['location']
json_body.update({"location": response.headers['location']})

except requests.exceptions.JSONDecodeError:
json_body = {}

if isinstance(json_body, dict) and retry and json_body.get('errorCode') == 60001:
self._refresh()
Expand Down