Skip to content

Commit

Permalink
Merge pull request #19 from gha88/remote_call_with_api_key
Browse files Browse the repository at this point in the history
  • Loading branch information
subho007 authored Dec 28, 2023
2 parents 53a68c9 + f858d34 commit 4e0390d
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions postmanparser/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,28 @@ class Collection:
info: Info = field(init=False)
item: List[Union[Item, ItemGroup]] = field(init=False)
event: List[Event] = None

def hasCollectionWrapper(self, data):
return "collection" in data

def validate(self, data):
if "info" not in data or "item" not in data:
raise MissingRequiredFieldException(
"Invalid Postman collection: Required 'info' and 'item' "
if self.hasCollectionWrapper(data):
if "info" not in data["collection"] or "item" not in data["collection"]:
raise MissingRequiredFieldException(
"Invalid API Postman collection: Required 'info' and 'item' "
"properties in 'collection' object"
)
)
else:
if "info" not in data or "item" not in data:
raise MissingRequiredFieldException(
"Invalid Postman collection: Required 'info' and 'item' "
"properties in 'collection' object"
)

def parse(self, data: dict):
self.validate(data)
if self.hasCollectionWrapper(data):
data = data["collection"]
self.item = parse_item_list(data["item"])
self.info = Info.parse(data["info"])
self.auth = Auth.parse(data["auth"]) if "auth" in data else None
Expand All @@ -53,10 +65,13 @@ def parse_from_file(self, file_path):
self.validate(data)
self.parse(data)

def parse_from_url(self, url):
def parse_from_url(self, url, key = None):
response = None
headers = None
if key is not None:
headers = {'X-Api-Key': key}
try:
response = httpx.get(url)
response = httpx.get(url, headers=headers)
except Exception:
pass
if response is None:
Expand Down

0 comments on commit 4e0390d

Please sign in to comment.