Skip to content

Commit

Permalink
docs: added some more details on initializing client
Browse files Browse the repository at this point in the history
  • Loading branch information
jjjermiah committed Feb 12, 2024
1 parent 8b8c7f8 commit abc2dc1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ jobs:
Codecov:
needs: Unit-Tests
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/docs'
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -68,6 +67,7 @@ jobs:

Build-Documentation:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/docs'
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down
26 changes: 25 additions & 1 deletion docs/InitializeClient.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ initialize the client when performing a query.

.. tab:: Python

To do the same in Python, run the following code:
Initializing without any credientials will use the guest account.
To use your credentials, simply pass them as arguments to the NBIAClient class.

.. tabs::

Expand Down Expand Up @@ -50,6 +51,25 @@ initialize the client when performing a query.
getCollections -u <USERNAME> -pw <PASSWORD> --prefix TCGA
Context Manager for Client
^^^^^^^^^^^^^^^^^^^^^^^^^^
The client can be used as a context manager to ensure that the client is properly logged out after use.
This is especially useful when using the client in a script with a predefined scope and lifetime to ensure graceful termination of the client.

.. tabs::

.. tab:: Python

.. code-block:: python
from nbiatoolkit import NBIAClient
with NBIAClient() as client:
client.getCollections(prefix='TCGA')
.. tab:: Command Line

The context manager is not available in the command line interface.


Logging
Expand All @@ -67,3 +87,7 @@ The default log level is 'INFO' and the available log levels are 'DEBUG', 'INFO'
client = NBIAClient(log_level='DEBUG)
client.getCollections(prefix='TCGA')
.. tab:: Command Line
Logging is not yet available in the command line interface. Feel free to open an issue on the GitHub repository if you would like to see this feature added.
34 changes: 0 additions & 34 deletions src/nbiatoolkit/nbia.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,40 +131,6 @@ def query_api(
self._log.error("Error querying API: %s", e)
raise e

# try:
# response = requests.get(url=query_url, headers=self.headers, params=params)
# response.raise_for_status() # Raise an HTTPError for bad responses
# except requests.exceptions.RequestException as e:
# self._log.error("Error querying API: %s", e)
# raise e

# if response.status_code != 200:
# self._log.error(
# "Error querying API: %s %s", response.status_code, response.reason
# )
# raise requests.exceptions.RequestException(
# f"Error querying API: {response.status_code} {response.reason}"
# )

# try:
# if response.headers.get("Content-Type") == "application/json":
# response_json: dict | list = response.json()
# return response_json
# else:
# # If response is binary data, return raw response
# response_data: bytes = response.content
# return response_data
# except JSONDecodeError as j:
# self._log.debug("Response: %s", response.text)
# if response.text == "":
# self._log.error("Response text is empty.")
# else:
# self._log.error("Error parsing response as JSON: %s", j)
# raise j
# except Exception as e:
# self._log.error("Error querying API: %s", e)
# raise e

def getCollections(self, prefix: str = "") -> Union[list[str], None]:
response = self.query_api(NBIA_ENDPOINTS.GET_COLLECTIONS)

Expand Down

0 comments on commit abc2dc1

Please sign in to comment.