Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file & __pycache__ should be in your .gitignore file. You should also add venv to your .gitignore file as well.

// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
Binary file added __pycache__/customer_requests.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/rental_requests.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/video_requests.cpython-39.pyc
Binary file not shown.
72 changes: 72 additions & 0 deletions customer_requests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import requests

class CustomerRequests:
def __init__(self, url="http://localhost:5000", selected_customer=None):
self.url = url
self.selected_customer = selected_customer

def create_customer(self, name=None, postal_code=None, phone=None):

query_params = {
"name" : name,
"postal_code" : postal_code,
"phone": phone
}

response = requests.post(self.url+f"/customers",json=query_params)
return response.json()

def list_all_customers(self):
response = requests.get(self.url+"/customers")
return response.json()

def get_specific_customer(self, name=None, id=None):

for customer in self.list_all_customers():

if name:
if name == customer["name"]:
id = customer["id"]
self.selected_customer = customer

elif id == customer["id"]:
self.selected_customer = customer

if not self.selected_customer:
print("That customer name or id could not be found")

return self.selected_customer

def update_customer(self, name=None, postal_code=None, phone=None):

if not name:
name = self.selected_customer["name"]

if not postal_code:
postal_code = self.selected_customer["postal_code"]

if not phone:
phone = self.selected_customer["phone"]

query_params = {
"name": name,
"postal_code": postal_code,
"phone": phone
}

response = requests.put(
self.url+f"/customers/{self.selected_customer['id']}",
json=query_params
)

self.selected_customer = response.json()
return response.json()

def delete_customer(self):
response = requests.delete(self.url+f"/customers/{self.selected_customer['id']}")
self.selected_customer = None
return response.json()

def print_customer(self):
if self.selected_customer:
print(f"Customer with id {self.selected_customer['id']} is currently selected\n")
Loading