Skip to content
This repository was archived by the owner on Jun 29, 2022. It is now read-only.

Commit 5bb772a

Browse files
committed
Adds timeout and error handling to request
1 parent ccbaa95 commit 5bb772a

File tree

7 files changed

+43
-31
lines changed

7 files changed

+43
-31
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## v2.2.0 (2021-02-20)
4+
5+
* Adds timeout on HTTP requests
6+
* Adds try/except block arround HTTP requests
7+
* Changes internal function name from `response` to `_make_http_request`
8+
39
## v2.1.0 (2021-02-05)
410

511
* Changed all classmethods to staticmethods

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
setuptools.setup(
1111
name='tuneuptechnology',
12-
version='2.1.0',
12+
version='2.2.0',
1313
description='The Python client library for the Tuneup Technology App.',
1414
long_description=long_description,
1515
long_description_content_type="text/markdown",

tuneuptechnology/client.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
import requests
22

3-
VERSION = '2.1.0'
4-
API_BASE_URL = "https://app.tuneuptechnology.com/api/"
5-
63

74
class Client():
5+
VERSION = '2.1.0'
6+
API_BASE_URL = "https://app.tuneuptechnology.com/api/"
7+
88
@staticmethod
9-
def response(data, endpoint):
9+
def _make_http_request(data, endpoint):
1010
"""Build the API request and return it to the method invoking it"""
1111
headers = {
12-
'User-Agent': f'TuneupTechnologyApp/PythonClient/{VERSION}'
12+
'User-Agent': f'TuneupTechnologyApp/PythonClient/{Client.VERSION}'
1313
}
14-
request = requests.post(
15-
endpoint,
16-
data=data,
17-
headers=headers,
18-
)
14+
15+
try:
16+
request = requests.post(
17+
endpoint,
18+
data=data,
19+
headers=headers,
20+
timeout=10,
21+
)
22+
except Exception as error:
23+
raise Exception(error)
24+
1925
return request

tuneuptechnology/customer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ class Customer(Client):
66
def create(data):
77
"""Create a customer based on the data passed"""
88
endpoint = f'{Client.API_BASE_URL}customers/create'
9-
response = Client.response(data, endpoint)
9+
response = Client._make_http_request(data, endpoint)
1010
return response.json()
1111

1212
@staticmethod
1313
def all(data):
1414
"""Retrieve all customers"""
1515
endpoint = f'{Client.API_BASE_URL}customers'
16-
response = Client.response(data, endpoint)
16+
response = Client._make_http_request(data, endpoint)
1717
return response.json()
1818

1919
@staticmethod
2020
def retrieve(data):
2121
"""Retrieve a single customer"""
2222
endpoint = f'{Client.API_BASE_URL}customers/{data["id"]}'
23-
response = Client.response(data, endpoint)
23+
response = Client._make_http_request(data, endpoint)
2424
return response.json()
2525

2626
@staticmethod
2727
def update(data):
2828
"""Update a customer with the passed params"""
2929
endpoint = f'{Client.API_BASE_URL}customers/{data["id"]}/update'
30-
response = Client.response(data, endpoint)
30+
response = Client._make_http_request(data, endpoint)
3131
return response.json()
3232

3333
@staticmethod
3434
def delete(data):
3535
"""Delete a customer with the ID passed"""
3636
endpoint = f'{Client.API_BASE_URL}customers/{data["id"]}/delete'
37-
response = Client.response(data, endpoint)
37+
response = Client._make_http_request(data, endpoint)
3838
return response.json()

tuneuptechnology/inventory.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ class Inventory(Client):
66
def create(data):
77
"""Create an inventory item based on the data passed"""
88
endpoint = f'{Client.API_BASE_URL}inventory/create'
9-
response = Client.response(data, endpoint)
9+
response = Client._make_http_request(data, endpoint)
1010
return response.json()
1111

1212
@staticmethod
1313
def all(data):
1414
"""Retrieve all inventory"""
1515
endpoint = f'{Client.API_BASE_URL}inventorys'
16-
response = Client.response(data, endpoint)
16+
response = Client._make_http_request(data, endpoint)
1717
return response.json()
1818

1919
@staticmethod
2020
def retrieve(data):
2121
"""Retrieve a single inventory item"""
2222
endpoint = f'{Client.API_BASE_URL}inventory/{data["id"]}'
23-
response = Client.response(data, endpoint)
23+
response = Client._make_http_request(data, endpoint)
2424
return response.json()
2525

2626
@staticmethod
2727
def update(data):
2828
"""Update an inventory item with the passed params"""
2929
endpoint = f'{Client.API_BASE_URL}inventory/{data["id"]}/update'
30-
response = Client.response(data, endpoint)
30+
response = Client._make_http_request(data, endpoint)
3131
return response.json()
3232

3333
@staticmethod
3434
def delete(data):
3535
"""Delete an inventory item with the ID passed"""
3636
endpoint = f'{Client.API_BASE_URL}inventory/{data["id"]}/delete'
37-
response = Client.response(data, endpoint)
37+
response = Client._make_http_request(data, endpoint)
3838
return response.json()

tuneuptechnology/location.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ class Location(Client):
66
def create(data):
77
"""Create a location based on the data passed"""
88
endpoint = f'{Client.API_BASE_URL}locations/create'
9-
response = Client.response(data, endpoint)
9+
response = Client._make_http_request(data, endpoint)
1010
return response.json()
1111

1212
@staticmethod
1313
def all(data):
1414
"""Retrieve all locations"""
1515
endpoint = f'{Client.API_BASE_URL}locations'
16-
response = Client.response(data, endpoint)
16+
response = Client._make_http_request(data, endpoint)
1717
return response.json()
1818

1919
@staticmethod
2020
def retrieve(data):
2121
"""Retrieve a single location"""
2222
endpoint = f'{Client.API_BASE_URL}locations/{data["id"]}'
23-
response = Client.response(data, endpoint)
23+
response = Client._make_http_request(data, endpoint)
2424
return response.json()
2525

2626
@staticmethod
2727
def update(data):
2828
"""Update a location with the passed params"""
2929
endpoint = f'{Client.API_BASE_URL}locations/{data["id"]}/update'
30-
response = Client.response(data, endpoint)
30+
response = Client._make_http_request(data, endpoint)
3131
return response.json()
3232

3333
@staticmethod
3434
def delete(data):
3535
"""Delete a location with the ID passed"""
3636
endpoint = f'{Client.API_BASE_URL}locations/{data["id"]}/delete'
37-
response = Client.response(data, endpoint)
37+
response = Client._make_http_request(data, endpoint)
3838
return response.json()

tuneuptechnology/ticket.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ class Ticket(Client):
66
def create(data):
77
"""Create a ticket based on the data passed"""
88
endpoint = f'{Client.API_BASE_URL}tickets/create'
9-
response = Client.response(data, endpoint)
9+
response = Client._make_http_request(data, endpoint)
1010
return response.json()
1111

1212
@staticmethod
1313
def all(data):
1414
"""Retrieve all tickets"""
1515
endpoint = f'{Client.API_BASE_URL}tickets'
16-
response = Client.response(data, endpoint)
16+
response = Client._make_http_request(data, endpoint)
1717
return response.json()
1818

1919
@staticmethod
2020
def retrieve(data):
2121
"""Retrieve a single ticket"""
2222
endpoint = f'{Client.API_BASE_URL}tickets/{data["id"]}'
23-
response = Client.response(data, endpoint)
23+
response = Client._make_http_request(data, endpoint)
2424
return response.json()
2525

2626
@staticmethod
2727
def update(data):
2828
"""Update a ticket with the passed params"""
2929
endpoint = f'{Client.API_BASE_URL}tickets/{data["id"]}/update'
30-
response = Client.response(data, endpoint)
30+
response = Client._make_http_request(data, endpoint)
3131
return response.json()
3232

3333
@staticmethod
3434
def delete(data):
3535
"""Delete a ticket with the ID passed"""
3636
endpoint = f'{Client.API_BASE_URL}tickets/{data["id"]}/delete'
37-
response = Client.response(data, endpoint)
37+
response = Client._make_http_request(data, endpoint)
3838
return response.json()

0 commit comments

Comments
 (0)