Skip to content

Commit

Permalink
Merge pull request #25 from ultradns/workflows
Browse files Browse the repository at this point in the history
Workflows
  • Loading branch information
stevedejong authored Oct 14, 2024
2 parents 073f6bf + cc7ed36 commit a28d891
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
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/[email protected]
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

0 comments on commit a28d891

Please sign in to comment.