Skip to content

Merging functions for My Workspace and other workspaces #3

@rem-bou

Description

@rem-bou

Hi @ChristianPresley ,

What do you think of the idea to merge into a single function calls to My Workspace or specific workspaces?
For example getting datasets, there are 2 functions in dataset.py: get_datasets(self) and get_datasets_in_workspace(self, workspace_name: str). the only difference is passing the workspace id in the url after retrieving it.

That would reduce number of line of code and it would simplify usage by having one function for several cases. In the eventually of the addition of admin calls, adding functions would duplicate the code and functions even more. If interested, the idea on how it could be implemented. Happy to submit a pull request for that. I've worked a little bit on the dataset.py file already

# https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/get-datasets
# https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/get-datasets-in-group
def get_datasets(self, workspace_name: str = None) -> List:
        self.client.check_token_expiration()
        
        url_extension = ''
        if workspace_name:
            self.workspaces.get_workspace_id(workspace_name)
            url_extension = "groups/" + self.workspaces.workspace[workspace_name] + '/'

        url = self.client.base_url + url_extension + "datasets"
        
        response = requests.get(url, headers = self.client.json_headers)

        if response.status_code == self.client.http_ok_code:
            logging.info("Successfully retrieved datasets.")
            self.datasets = response.json()["value"]
            return self.datasets
        else:
            logging.error("Failed to retrieve datasets.")
            self.client.force_raise_http_error(response)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions