From f817e788ec66abcb7daa6b6f2875e61bc25827db Mon Sep 17 00:00:00 2001 From: Chunlei Wu Date: Mon, 13 Nov 2023 15:11:04 -0800 Subject: [PATCH] feat: :sparkles: added use_http and use_https for easy switch --- biothings_client/base.py | 10 ++++++++++ tests/gene.py | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/biothings_client/base.py b/biothings_client/base.py index 7affd0b..1dc094e 100644 --- a/biothings_client/base.py +++ b/biothings_client/base.py @@ -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)""" diff --git a/tests/gene.py b/tests/gene.py index d6c7ea0..b217b8b 100644 --- a/tests/gene.py +++ b/tests/gene.py @@ -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)