Skip to content

Commit

Permalink
Added portal_utils.Portal.head method
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed Aug 22, 2024
1 parent 0fe4f08 commit 2539c5f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ dcicutils
Change Log
----------

8.14.3
======

* 2024-08-22 (dmichaels)
* Added portal_utils.Portal.head method.


8.14.2
======
* Corrected requests version (to ^2.27.0 from 2.31.0) on pyproject.toml to not be pinned; but doing
Expand Down
11 changes: 11 additions & 0 deletions dcicutils/portal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,17 @@ def post_metadata(self, object_type: str, data: dict, check_only: bool = False)
add_on="check_only=True" if check_only else "")
return self.post(f"/{object_type}{'?check_only=True' if check_only else ''}", data).json()

def head(self, url: str, follow: bool = False, raise_exception: bool = False, **kwargs) -> Optional[int]:
try:
response = requests.head(self.url(url), **self._kwargs(**kwargs))
if response and response.status_code in [301, 302, 303, 307, 308] and (follow is True):
response = response.follow()
return response.status_code
except Exception as e:
if raise_exception is True:
raise e
return None

def get_health(self) -> OptionalResponse:
return self.get("/health")

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicutils"
version = "8.14.2"
version = "8.14.2.1b1" # TODO: To become 8.14.3
description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources"
authors = ["4DN-DCIC Team <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 2539c5f

Please sign in to comment.