Skip to content

Commit

Permalink
feat: ✨ added use_http and use_https for easy switch
Browse files Browse the repository at this point in the history
  • Loading branch information
newgene committed Nov 13, 2023
1 parent 8402b43 commit f817e78
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions biothings_client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ def __init__(self, url=None):
)
self._cached = False

def use_http(self):
"""Use http instead of https for API calls."""
if self.url:
self.url = self.url.replace("https://", "http://")

def use_https(self):
"""Use https instead of http for API calls. This is the default."""
if self.url:
self.url = self.url.replace("http://", "https://")

@staticmethod
def _dataframe(obj, dataframe, df_index=True):
"""Converts object to DataFrame (pandas)"""
Expand Down
10 changes: 10 additions & 0 deletions tests/gene.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ def setUp(self):
"1431_at",
]

def test_http(self):
# this is the default
self.mg.url.startswith("https://")
# switch to http
self.mg.use_http()
self.mg.url.startswith("http://")
# reset to default
self.mg.use_https()
self.mg.url.startswith("https://")

def test_metadata(self):
meta = self.mg.metadata()
self.assertTrue("stats" in meta)
Expand Down

0 comments on commit f817e78

Please sign in to comment.