Skip to content

Commit adbf222

Browse files
committed
update branch with recent changes in master
2 parents 8bc1a5d + cb13112 commit adbf222

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
help = "Make a DELETE request to an API",
5555
action = 'store_true')
5656

57-
5857
parser.add_argument("-p",
5958
"--playbook",
6059
help="View and organise the playbook",

src/arguments/api_test.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,60 @@ def get_request(cls):
5959
"the localhost server is active or not")
6060
except Exception as e:
6161
print(e)
62+
@classmethod
63+
def delete_endpoint_request(cls):
64+
request_url = cls.default_url
65+
request_headers = cls.default_headers
66+
input_url = input('Enter URL: ')
67+
input_headers = input('Enter Headers: ')
68+
if input_url != '':
69+
request_url = input_url
70+
if input_headers != '':
71+
try:
72+
request_headers = json.loads(input_headers)
73+
except Exception:
74+
print("Failed to parse Input Headers")
75+
# Check whether the request_url has an endpoint or not
76+
has_endpoint = cls.__check_endpoint(request_url)
77+
78+
# Check if http:// or https:// is present in request_url
79+
has_protocol = cls.__check_protocol(request_url)
80+
81+
if not(has_protocol):
82+
request_url = "https://" + request_url
6283

84+
# Ask the user for endpoint if not present in request_url
85+
if not(has_endpoint):
86+
if(request_url[-1] == '/'):
87+
endpoint = input("Input endpoint " +
88+
"(Without the starting slash): ")
89+
else:
90+
endpoint = input("Input endpoint (With the starting slash): ")
91+
request_url += endpoint
92+
93+
print("Trying ...\u26A1")
94+
try:
95+
response = requests.delete(request_url, headers=request_headers)
96+
print(f"Reponse Status Code: {response.status_code}")
97+
response_data = json.loads(response.content)
98+
parsed_json = json.dumps(response_data, indent=4)
99+
output_json = highlight(parsed_json, lexers.JsonLexer(),
100+
formatters.TerminalFormatter())
101+
print(output_json)
102+
103+
store_data = input('Store response data? (Y/N): ')
104+
if(store_data == 'Y' or store_data == 'y'):
105+
with open('response_data.json', 'w') as jsonFile:
106+
json.dump(response_data, jsonFile, indent=4)
107+
print("Response data stored in response_data.json")
108+
109+
except requests.exceptions.InvalidSchema:
110+
print("Check whether the URL is valid or check if " +
111+
"the localhost server is active or not")
112+
except Exception as e:
113+
print(e)
114+
115+
# Make GET request and store the response in response_data.json
63116
@classmethod
64117
def delete_endpoint_request(cls):
65118
request_url = cls.default_url
@@ -92,6 +145,7 @@ def delete_endpoint_request(cls):
92145
request_url += endpoint
93146

94147
print("Trying ...\u26A1")
148+
# Makes a DELETE request to the given endpoint
95149
try:
96150
response = requests.delete(request_url, headers=request_headers)
97151
print(f"Reponse Status Code: {response.status_code}")

src/arguments/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,6 @@ def search_for_results(self, save=False):
9898
filename = SaveSearchResults(data)
9999
print(
100100
colored(f"\U0001F604 Answers successfully saved into {filename}",
101-
"green"))
101+
"green"),
102102
colored("\U0001F604 Answers successfully saved into" +\
103103
filename, "green"))

0 commit comments

Comments
 (0)