-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path__init__.py
More file actions
43 lines (37 loc) · 1.35 KB
/
__init__.py
File metadata and controls
43 lines (37 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import json
from urllib.parse import urlencode
import logging
from socketdev.tools import load_files
log = logging.getLogger("socketdev")
# TODO: Add types for responses. Not currently used in the CLI.
class Dependencies:
def __init__(self, api):
self.api = api
def post(self, files: list, params: dict) -> dict:
loaded_files = []
loaded_files = load_files(files, loaded_files)
path = "dependencies/upload?" + urlencode(params)
response = self.api.do_request(path=path, files=loaded_files, method="POST")
if response.status_code == 200:
result = response.json()
else:
result = {}
log.error(f"Error posting {files} to the Dependency API")
log.error(response.text)
return result
def get(
self,
limit: int = 50,
offset: int = 0,
) -> dict:
path = "dependencies/search"
payload = {"limit": limit, "offset": offset}
payload_str = json.dumps(payload)
response = self.api.do_request(path=path, method="POST", payload=payload_str)
if response.status_code == 200:
result = response.json()
else:
result = {}
log.error("Unable to retrieve Dependencies")
log.error(response.text)
return result