Skip to content

Commit

Permalink
Change args in Netcontrol.request
Browse files Browse the repository at this point in the history
  • Loading branch information
Ecnama committed Oct 21, 2024
1 parent 8978915 commit ff0ee2a
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions backend/langate/modules/netcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,17 @@ def request(self, endpoint='', args={}):
"""
response = None

# Construct the data to be sent in the request
if len(args) == 1:
data = '/' + next(iter(args.items()))[1]
elif len(args) > 1:
data = '?' + "&".join([f"{key}={value}" for key, value in args.items()])
else:
data = ''

# Make the request
try:
# Check the type of request
if endpoint in GET_REQUESTS:
response = requests.get(self.REQUEST_URL + endpoint + data)
response = requests.get(self.REQUEST_URL + endpoint, params=args)
elif endpoint in POST_REQUESTS:
response = requests.post(self.REQUEST_URL + endpoint + data)
response = requests.post(self.REQUEST_URL + endpoint, params=args)
elif endpoint in DELETE_REQUESTS:
response = requests.delete(self.REQUEST_URL + endpoint + data)
response = requests.delete(self.REQUEST_URL + endpoint, params=args)
elif endpoint in PUT_REQUESTS:
response = requests.put(self.REQUEST_URL + endpoint + data)
response = requests.put(self.REQUEST_URL + endpoint, params=args)

response.raise_for_status()
return response.json()
Expand Down

0 comments on commit ff0ee2a

Please sign in to comment.