Skip to content

Commit

Permalink
🐛 Regen endpoints to support fixed Pagination params
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoshify committed Sep 18, 2023
1 parent 11b6047 commit ebad6f3
Show file tree
Hide file tree
Showing 1,710 changed files with 2,347 additions and 10,556 deletions.
25 changes: 11 additions & 14 deletions src/pyconnectwise/clients/automate_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import base64
from datetime import datetime

from pyconnectwise.clients.connectwise_client import ConnectWiseClient
from pyconnectwise.config import Config
from pyconnectwise.endpoints.automate.ClientsEndpoint import ClientsEndpoint
from pyconnectwise.endpoints.automate.CommandsEndpoint import CommandsEndpoint
from pyconnectwise.endpoints.automate.ComputersEndpoint import ComputersEndpoint
Expand All @@ -24,24 +28,14 @@
from pyconnectwise.endpoints.automate.UserclassesEndpoint import UserclassesEndpoint
from pyconnectwise.endpoints.automate.UsersEndpoint import UsersEndpoint

from pyconnectwise.clients.connectwise_client import ConnectWiseClient
from pyconnectwise.config import Config


class ConnectWiseAutomateAPIClient(ConnectWiseClient):
"""
ConnectWise Automate API client. Handles the connection to the ConnectWise Automate API
and the configuration of all the available endpoints.
"""

def __init__(
self,
automate_url: str,
client_id: str,
username: str,
password: str,
config: Config = None
):
def __init__(self, automate_url: str, client_id: str, username: str, password: str, config: Config = None):
"""
Initializes the client with the given credentials and optionally a specific codebase.
If no codebase is given, it tries to get it from the API.
Expand Down Expand Up @@ -104,9 +98,12 @@ def _get_access_token(self) -> str:
"""
Performs a request to the ConnectWise Automate API to obtain an access token.
"""
auth_response = self._make_request("POST", f"{self._get_url()}/apitoken",
data={"UserName": self.username, "Password": self.password},
headers={"Content-Type": "application/json", "ClientId": self.client_id})
auth_response = self._make_request(
"POST",
f"{self._get_url()}/apitoken",
data={"UserName": self.username, "Password": self.password},
headers={"Content-Type": "application/json", "ClientId": self.client_id},
)
auth_resp_json = auth_response.json()
token = auth_resp_json["AccessToken"]
self.token_expiry_time = datetime.fromisoformat(auth_resp_json["ExpirationDate"])
Expand Down
12 changes: 7 additions & 5 deletions src/pyconnectwise/clients/manage_client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import base64

from pyconnectwise.clients.connectwise_client import ConnectWiseClient
from pyconnectwise.config import Config

from pyconnectwise.endpoints.manage.CompanyEndpoint import CompanyEndpoint
from pyconnectwise.endpoints.manage.ConfigurationsEndpoint import ConfigurationsEndpoint
from pyconnectwise.endpoints.manage.ExpenseEndpoint import ExpenseEndpoint
Expand Down Expand Up @@ -30,7 +30,7 @@ def __init__(
public_key: str,
private_key: str,
codebase: str | None = None,
config: Config = None
config: Config = None,
):
"""
Initializes the client with the given credentials and optionally a specific codebase.
Expand All @@ -43,7 +43,7 @@ def __init__(
public_key (str): Your ConnectWise Manage API Public key.
private_key (str): Your ConnectWise Manage API Private key.
codebase (str, optional): Your ConnectWise Manage Codebase. If not provided, it will be fetched from the API. Defaults to None.
config (Config, optional): Optional additional configuration for API interactions.
config (Config, optional): Optional additional configuration for API interactions
"""
self.client_id: str = client_id
self.company_name: str = company_name
Expand All @@ -61,7 +61,7 @@ def __init__(
company_name=company_name,
headers=self._get_headers(),
)
self.codebase: str = codebase_request.strip('/')
self.codebase: str = codebase_request.strip("/")

# Initializing endpoints
self.company = CompanyEndpoint(self)
Expand All @@ -86,7 +86,9 @@ def _get_url(self) -> str:
"""
return f"https://{self.manage_url}/{self.codebase}/apis/3.0"

def _try_get_codebase_from_api(self, manage_url: str, company_name: str, headers: dict[str, str]) -> str | None:
def _try_get_codebase_from_api(
self, manage_url: str, company_name: str, headers: dict[str, str]
) -> str | None:
"""
Tries to retrieve the codebase from the API using the provided company url, company name and headers.
Expand Down
6 changes: 1 addition & 5 deletions src/pyconnectwise/endpoints/automate/ClientsEndpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ def paginated(
params["page"] = page
params["pageSize"] = page_size
return PaginatedResponse(
super()._make_request("GET", params=params),
LabTechClient,
self,
page,
page_size,
super()._make_request("GET", params=params), LabTechClient, self, page, page_size, params
)

def get(self, data: dict[str, Any] = {}, params: dict[str, int | str] = {}) -> list[LabTechClient]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def paginated(
params["page"] = page
params["pageSize"] = page_size
return PaginatedResponse(
super()._make_request("GET", params=params),
LabTechDocument,
self,
page,
page_size,
super()._make_request("GET", params=params), LabTechDocument, self, page, page_size, params
)

def get(self, data: dict[str, Any] = {}, params: dict[str, int | str] = {}) -> list[LabTechDocument]:
Expand Down
8 changes: 2 additions & 6 deletions src/pyconnectwise/endpoints/automate/ClientsIdEndpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def __init__(self, client, parent_endpoint=None):
super().__init__(client, "{id}", parent_endpoint=parent_endpoint)

self.productkeys = self._register_child_endpoint(ClientsIdProductkeysEndpoint(client, parent_endpoint=self))
self.documents = self._register_child_endpoint(ClientsIdDocumentsEndpoint(client, parent_endpoint=self))
self.licenses = self._register_child_endpoint(ClientsIdLicensesEndpoint(client, parent_endpoint=self))
self.permissions = self._register_child_endpoint(ClientsIdPermissionsEndpoint(client, parent_endpoint=self))
self.documents = self._register_child_endpoint(ClientsIdDocumentsEndpoint(client, parent_endpoint=self))

def paginated(
self, page: int, page_size: int, params: dict[str, int | str] = {}
Expand All @@ -34,11 +34,7 @@ def paginated(
params["page"] = page
params["pageSize"] = page_size
return PaginatedResponse(
super()._make_request("GET", params=params),
LabTechClient,
self,
page,
page_size,
super()._make_request("GET", params=params), LabTechClient, self, page, page_size, params
)

def get(self, data: dict[str, Any] = {}, params: dict[str, int | str] = {}) -> LabTechClient:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def paginated(
params["page"] = page
params["pageSize"] = page_size
return PaginatedResponse(
super()._make_request("GET", params=params),
LabTechManagedLicense,
self,
page,
page_size,
super()._make_request("GET", params=params), LabTechManagedLicense, self, page, page_size, params
)

def get(self, data: dict[str, Any] = {}, params: dict[str, int | str] = {}) -> list[LabTechManagedLicense]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def paginated(
params["page"] = page
params["pageSize"] = page_size
return PaginatedResponse(
super()._make_request("GET", params=params),
LabTechProductKey,
self,
page,
page_size,
super()._make_request("GET", params=params), LabTechProductKey, self, page, page_size, params
)

def get(self, data: dict[str, Any] = {}, params: dict[str, int | str] = {}) -> list[LabTechProductKey]:
Expand Down
6 changes: 1 addition & 5 deletions src/pyconnectwise/endpoints/automate/CommandsEndpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ def paginated(
params["page"] = page
params["pageSize"] = page_size
return PaginatedResponse(
super()._make_request("GET", params=params),
LabTechCommand,
self,
page,
page_size,
super()._make_request("GET", params=params), LabTechCommand, self, page, page_size, params
)

def get(self, data: dict[str, Any] = {}, params: dict[str, int | str] = {}) -> list[LabTechCommand]:
Expand Down
6 changes: 1 addition & 5 deletions src/pyconnectwise/endpoints/automate/CommandsIdEndpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def paginated(
params["page"] = page
params["pageSize"] = page_size
return PaginatedResponse(
super()._make_request("GET", params=params),
LabTechCommand,
self,
page,
page_size,
super()._make_request("GET", params=params), LabTechCommand, self, page, page_size, params
)

def get(self, data: dict[str, Any] = {}, params: dict[str, int | str] = {}) -> LabTechCommand:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def paginated(
params["page"] = page
params["pageSize"] = page_size
return PaginatedResponse(
super()._make_request("GET", params=params),
LabTechComputerMenu,
self,
page,
page_size,
super()._make_request("GET", params=params), LabTechComputerMenu, self, page, page_size, params
)

def get(self, data: dict[str, Any] = {}, params: dict[str, int | str] = {}) -> list[LabTechComputerMenu]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def paginated(
params["page"] = page
params["pageSize"] = page_size
return PaginatedResponse(
super()._make_request("GET", params=params),
LabTechComputerChassis,
self,
page,
page_size,
super()._make_request("GET", params=params), LabTechComputerChassis, self, page, page_size, params
)

def get(self, data: dict[str, Any] = {}, params: dict[str, int | str] = {}) -> list[LabTechComputerChassis]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def paginated(
params["page"] = page
params["pageSize"] = page_size
return PaginatedResponse(
super()._make_request("GET", params=params),
LabTechComputerDrive,
self,
page,
page_size,
super()._make_request("GET", params=params), LabTechComputerDrive, self, page, page_size, params
)

def get(self, data: dict[str, Any] = {}, params: dict[str, int | str] = {}) -> list[LabTechComputerDrive]:
Expand Down
10 changes: 3 additions & 7 deletions src/pyconnectwise/endpoints/automate/ComputersEndpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class ComputersEndpoint(ConnectWiseEndpoint):
def __init__(self, client, parent_endpoint=None):
super().__init__(client, "Computers", parent_endpoint=parent_endpoint)

self.chassis = self._register_child_endpoint(ComputersChassisEndpoint(client, parent_endpoint=self))
self.software = self._register_child_endpoint(ComputersSoftwareEndpoint(client, parent_endpoint=self))
self.memoryslots = self._register_child_endpoint(ComputersMemoryslotsEndpoint(client, parent_endpoint=self))
self.drives = self._register_child_endpoint(ComputersDrivesEndpoint(client, parent_endpoint=self))
self.chassis = self._register_child_endpoint(ComputersChassisEndpoint(client, parent_endpoint=self))
self.software = self._register_child_endpoint(ComputersSoftwareEndpoint(client, parent_endpoint=self))
self.maintenancemodes = self._register_child_endpoint(
ComputersMaintenancemodesEndpoint(client, parent_endpoint=self)
)
Expand Down Expand Up @@ -52,11 +52,7 @@ def paginated(
params["page"] = page
params["pageSize"] = page_size
return PaginatedResponse(
super()._make_request("GET", params=params),
LabTechComputer,
self,
page,
page_size,
super()._make_request("GET", params=params), LabTechComputer, self, page, page_size, params
)

def get(self, data: dict[str, Any] = {}, params: dict[str, int | str] = {}) -> list[LabTechComputer]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class ComputersIdAlertsuspensionsEndpoint(ConnectWiseEndpoint):
def __init__(self, client, parent_endpoint=None):
super().__init__(client, "Alertsuspensions", parent_endpoint=parent_endpoint)

self.maintenancewindow = self._register_child_endpoint(
ComputersIdAlertsuspensionsMaintenancewindowEndpoint(client, parent_endpoint=self)
)
self.templatediversion = self._register_child_endpoint(
ComputersIdAlertsuspensionsTemplatediversionEndpoint(client, parent_endpoint=self)
)
self.maintenancewindow = self._register_child_endpoint(
ComputersIdAlertsuspensionsMaintenancewindowEndpoint(client, parent_endpoint=self)
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def paginated(
params["page"] = page
params["pageSize"] = page_size
return PaginatedResponse(
super()._make_request("GET", params=params),
LabTechComputerBios,
self,
page,
page_size,
super()._make_request("GET", params=params), LabTechComputerBios, self, page, page_size, params
)

def get(self, data: dict[str, Any] = {}, params: dict[str, int | str] = {}) -> LabTechComputerBios:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def paginated(
params["page"] = page
params["pageSize"] = page_size
return PaginatedResponse(
super()._make_request("GET", params=params),
LabTechCommandExecute,
self,
page,
page_size,
super()._make_request("GET", params=params), LabTechCommandExecute, self, page, page_size, params
)

def get(self, data: dict[str, Any] = {}, params: dict[str, int | str] = {}) -> list[LabTechCommandExecute]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def paginated(
params["page"] = page
params["pageSize"] = page_size
return PaginatedResponse(
super()._make_request("GET", params=params),
AutomateCommandHistory,
self,
page,
page_size,
super()._make_request("GET", params=params), AutomateCommandHistory, self, page, page_size, params
)

def get(self, data: dict[str, Any] = {}, params: dict[str, int | str] = {}) -> list[AutomateCommandHistory]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def paginated(
params["page"] = page
params["pageSize"] = page_size
return PaginatedResponse(
super()._make_request("GET", params=params),
LabTechComputerPatchingPolicy,
self,
page,
page_size,
super()._make_request("GET", params=params), LabTechComputerPatchingPolicy, self, page, page_size, params
)

def get(self, data: dict[str, Any] = {}, params: dict[str, int | str] = {}) -> list[LabTechComputerPatchingPolicy]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def paginated(
params["page"] = page
params["pageSize"] = page_size
return PaginatedResponse(
super()._make_request("GET", params=params),
LabTechComputerDevice,
self,
page,
page_size,
super()._make_request("GET", params=params), LabTechComputerDevice, self, page, page_size, params
)

def get(self, data: dict[str, Any] = {}, params: dict[str, int | str] = {}) -> list[LabTechComputerDevice]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def paginated(
params["page"] = page
params["pageSize"] = page_size
return PaginatedResponse(
super()._make_request("GET", params=params),
LabTechComputerDriver,
self,
page,
page_size,
super()._make_request("GET", params=params), LabTechComputerDriver, self, page, page_size, params
)

def get(self, data: dict[str, Any] = {}, params: dict[str, int | str] = {}) -> list[LabTechComputerDriver]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def paginated(
params["page"] = page
params["pageSize"] = page_size
return PaginatedResponse(
super()._make_request("GET", params=params),
LabTechSmartData,
self,
page,
page_size,
super()._make_request("GET", params=params), LabTechSmartData, self, page, page_size, params
)

def get(self, data: dict[str, Any] = {}, params: dict[str, int | str] = {}) -> list[LabTechSmartData]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def paginated(
self,
page,
page_size,
params,
)

def get(
Expand Down
Loading

0 comments on commit ebad6f3

Please sign in to comment.