anaplan-sdk 0.4.5__py3-none-any.whl → 0.5.0a2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,8 @@
1
+ import logging
1
2
  from typing import Any, Literal
2
3
 
3
- import httpx
4
-
5
- from anaplan_sdk._base import (
6
- _BaseClient,
4
+ from anaplan_sdk._services import (
5
+ _HttpService,
7
6
  connection_body_payload,
8
7
  construct_payload,
9
8
  integration_payload,
@@ -27,12 +26,14 @@ from anaplan_sdk.models.cloud_works import (
27
26
 
28
27
  from ._cw_flow import _FlowClient
29
28
 
29
+ logger = logging.getLogger("anaplan_sdk")
30
+
30
31
 
31
- class _CloudWorksClient(_BaseClient):
32
- def __init__(self, client: httpx.Client, retry_count: int) -> None:
32
+ class _CloudWorksClient:
33
+ def __init__(self, http: _HttpService) -> None:
34
+ self._http = http
33
35
  self._url = "https://api.cloudworks.anaplan.com/2/0/integrations"
34
- self._flow = _FlowClient(client, retry_count)
35
- super().__init__(retry_count, client)
36
+ self._flow = _FlowClient(self._http)
36
37
 
37
38
  @property
38
39
  def flows(self) -> _FlowClient:
@@ -41,14 +42,14 @@ class _CloudWorksClient(_BaseClient):
41
42
  """
42
43
  return self._flow
43
44
 
44
- def list_connections(self) -> list[Connection]:
45
+ def get_connections(self) -> list[Connection]:
45
46
  """
46
47
  List all Connections available in CloudWorks.
47
48
  :return: A list of connections.
48
49
  """
49
50
  return [
50
51
  Connection.model_validate(e)
51
- for e in self._get_paginated(f"{self._url}/connections", "connections")
52
+ for e in self._http.get_paginated(f"{self._url}/connections", "connections")
52
53
  ]
53
54
 
54
55
  def create_connection(self, con_info: ConnectionInput | dict[str, Any]) -> str:
@@ -59,10 +60,12 @@ class _CloudWorksClient(_BaseClient):
59
60
  against the ConnectionInput model before sending the request.
60
61
  :return: The ID of the new connection.
61
62
  """
62
- res = self._post(
63
+ res = self._http.post(
63
64
  f"{self._url}/connections", json=construct_payload(ConnectionInput, con_info)
64
65
  )
65
- return res["connections"]["connectionId"]
66
+ connection_id = res["connections"]["connectionId"]
67
+ logger.info(f"Created connection '{connection_id}'.")
68
+ return connection_id
66
69
 
67
70
  def update_connection(self, con_id: str, con_info: ConnectionBody | dict[str, Any]) -> None:
68
71
  """
@@ -72,7 +75,7 @@ class _CloudWorksClient(_BaseClient):
72
75
  as when initially creating the connection again. If you want to update only some of
73
76
  the details, use the `patch_connection` method instead.
74
77
  """
75
- self._put(f"{self._url}/connections/{con_id}", json=connection_body_payload(con_info))
78
+ self._http.put(f"{self._url}/connections/{con_id}", json=connection_body_payload(con_info))
76
79
 
77
80
  def patch_connection(self, con_id: str, body: dict[str, Any]) -> None:
78
81
  """
@@ -81,16 +84,17 @@ class _CloudWorksClient(_BaseClient):
81
84
  :param body: The name and details of the connection. You can pass all the same details as
82
85
  when initially creating the connection again, or just any one of them.
83
86
  """
84
- self._patch(f"{self._url}/connections/{con_id}", json=body)
87
+ self._http.patch(f"{self._url}/connections/{con_id}", json=body)
85
88
 
86
89
  def delete_connection(self, con_id: str) -> None:
87
90
  """
88
91
  Delete an existing connection in CloudWorks.
89
92
  :param con_id: The ID of the connection to delete.
90
93
  """
91
- self._delete(f"{self._url}/connections/{con_id}")
94
+ self._http.delete(f"{self._url}/connections/{con_id}")
95
+ logger.info(f"Deleted connection '{con_id}'.")
92
96
 
93
- def list_integrations(
97
+ def get_integrations(
94
98
  self, sort_by_name: Literal["ascending", "descending"] = "ascending"
95
99
  ) -> list[Integration]:
96
100
  """
@@ -101,7 +105,7 @@ class _CloudWorksClient(_BaseClient):
101
105
  params = {"sortBy": "name" if sort_by_name == "ascending" else "-name"}
102
106
  return [
103
107
  Integration.model_validate(e)
104
- for e in self._get_paginated(f"{self._url}", "integrations", params=params)
108
+ for e in self._http.get_paginated(f"{self._url}", "integrations", params=params)
105
109
  ]
106
110
 
107
111
  def get_integration(self, integration_id: str) -> SingleIntegration:
@@ -114,7 +118,7 @@ class _CloudWorksClient(_BaseClient):
114
118
  :return: The details of the integration, without the integration type.
115
119
  """
116
120
  return SingleIntegration.model_validate(
117
- (self._get(f"{self._url}/{integration_id}"))["integration"]
121
+ (self._http.get(f"{self._url}/{integration_id}"))["integration"]
118
122
  )
119
123
 
120
124
  def create_integration(
@@ -141,7 +145,11 @@ class _CloudWorksClient(_BaseClient):
141
145
  :return: The ID of the new integration.
142
146
  """
143
147
  json = integration_payload(body)
144
- return (self._post(f"{self._url}", json=json))["integration"]["integrationId"]
148
+ integration_id = (self._http.post(f"{self._url}", json=json))["integration"][
149
+ "integrationId"
150
+ ]
151
+ logger.info(f"Created integration '{integration_id}'.")
152
+ return integration_id
145
153
 
146
154
  def update_integration(
147
155
  self, integration_id: str, body: IntegrationInput | IntegrationProcessInput | dict[str, Any]
@@ -154,7 +162,7 @@ class _CloudWorksClient(_BaseClient):
154
162
  of the details, use the `patch_integration` method instead.
155
163
  """
156
164
  json = integration_payload(body)
157
- self._put(f"{self._url}/{integration_id}", json=json)
165
+ self._http.put(f"{self._url}/{integration_id}", json=json)
158
166
 
159
167
  def run_integration(self, integration_id: str) -> str:
160
168
  """
@@ -162,14 +170,17 @@ class _CloudWorksClient(_BaseClient):
162
170
  :param integration_id: The ID of the integration to run.
163
171
  :return: The ID of the run instance.
164
172
  """
165
- return (self._post_empty(f"{self._url}/{integration_id}/run"))["run"]["id"]
173
+ run_id = (self._http.post_empty(f"{self._url}/{integration_id}/run"))["run"]["id"]
174
+ logger.info(f"Started integration run '{run_id}' for integration '{integration_id}'.")
175
+ return run_id
166
176
 
167
177
  def delete_integration(self, integration_id: str) -> None:
168
178
  """
169
179
  Delete an existing integration in CloudWorks.
170
180
  :param integration_id: The ID of the integration to delete.
171
181
  """
172
- self._delete(f"{self._url}/{integration_id}")
182
+ self._http.delete(f"{self._url}/{integration_id}")
183
+ logger.info(f"Deleted integration '{integration_id}'.")
173
184
 
174
185
  def get_run_history(self, integration_id: str) -> list[RunSummary]:
175
186
  """
@@ -179,7 +190,7 @@ class _CloudWorksClient(_BaseClient):
179
190
  """
180
191
  return [
181
192
  RunSummary.model_validate(e)
182
- for e in (self._get(f"{self._url}/runs/{integration_id}"))["history_of_runs"].get(
193
+ for e in (self._http.get(f"{self._url}/runs/{integration_id}"))["history_of_runs"].get(
183
194
  "runs", []
184
195
  )
185
196
  ]
@@ -190,7 +201,7 @@ class _CloudWorksClient(_BaseClient):
190
201
  :param run_id: The ID of the run to retrieve.
191
202
  :return: The details of the run.
192
203
  """
193
- return RunStatus.model_validate((self._get(f"{self._url}/run/{run_id}"))["run"])
204
+ return RunStatus.model_validate((self._http.get(f"{self._url}/run/{run_id}"))["run"])
194
205
 
195
206
  def get_run_error(self, run_id: str) -> RunError | None:
196
207
  """
@@ -199,7 +210,7 @@ class _CloudWorksClient(_BaseClient):
199
210
  :param run_id: The ID of the run to retrieve.
200
211
  :return: The details of the run error.
201
212
  """
202
- run = self._get(f"{self._url}/runerror/{run_id}")
213
+ run = self._http.get(f"{self._url}/runerror/{run_id}")
203
214
  return RunError.model_validate(run["runs"]) if run.get("runs") else None
204
215
 
205
216
  def create_schedule(
@@ -212,10 +223,11 @@ class _CloudWorksClient(_BaseClient):
212
223
  dictionary as per the documentation. If a dictionary is passed, it will be validated
213
224
  against the ScheduleInput model before sending the request.
214
225
  """
215
- self._post(
226
+ self._http.post(
216
227
  f"{self._url}/{integration_id}/schedule",
217
228
  json=schedule_payload(integration_id, schedule),
218
229
  )
230
+ logger.info(f"Created schedule for integration '{integration_id}'.")
219
231
 
220
232
  def update_schedule(
221
233
  self, integration_id: str, schedule: ScheduleInput | dict[str, Any]
@@ -227,10 +239,11 @@ class _CloudWorksClient(_BaseClient):
227
239
  dictionary as per the documentation. If a dictionary is passed, it will be validated
228
240
  against the ScheduleInput model before sending the request.
229
241
  """
230
- self._put(
242
+ self._http.put(
231
243
  f"{self._url}/{integration_id}/schedule",
232
244
  json=schedule_payload(integration_id, schedule),
233
245
  )
246
+ logger.info(f"Updated schedule for integration '{integration_id}'.")
234
247
 
235
248
  def set_schedule_status(
236
249
  self, integration_id: str, status: Literal["enabled", "disabled"]
@@ -240,14 +253,16 @@ class _CloudWorksClient(_BaseClient):
240
253
  :param integration_id: The ID of the integration to schedule.
241
254
  :param status: The status of the schedule. This can be either "enabled" or "disabled".
242
255
  """
243
- self._post_empty(f"{self._url}/{integration_id}/schedule/status/{status}")
256
+ self._http.post_empty(f"{self._url}/{integration_id}/schedule/status/{status}")
257
+ logger.info(f"Set schedule status to '{status}' for integration '{integration_id}'.")
244
258
 
245
259
  def delete_schedule(self, integration_id: str) -> None:
246
260
  """
247
261
  Delete an integration schedule in CloudWorks. A schedule must already exist.
248
262
  :param integration_id: The ID of the integration to schedule.
249
263
  """
250
- self._delete(f"{self._url}/{integration_id}/schedule")
264
+ self._http.delete(f"{self._url}/{integration_id}/schedule")
265
+ logger.info(f"Deleted schedule for integration '{integration_id}'.")
251
266
 
252
267
  def get_notification_config(
253
268
  self, notification_id: str | None = None, integration_id: str | None = None
@@ -266,7 +281,7 @@ class _CloudWorksClient(_BaseClient):
266
281
  if integration_id:
267
282
  notification_id = (self.get_integration(integration_id)).notification_id
268
283
  return NotificationConfig.model_validate(
269
- (self._get(f"{self._url}/notification/{notification_id}"))["notifications"]
284
+ (self._http.get(f"{self._url}/notification/{notification_id}"))["notifications"]
270
285
  )
271
286
 
272
287
  def create_notification_config(self, config: NotificationInput | dict[str, Any]) -> str:
@@ -280,10 +295,12 @@ class _CloudWorksClient(_BaseClient):
280
295
  validated against the NotificationConfig model before sending the request.
281
296
  :return: The ID of the new notification configuration.
282
297
  """
283
- res = self._post(
298
+ res = self._http.post(
284
299
  f"{self._url}/notification", json=construct_payload(NotificationInput, config)
285
300
  )
286
- return res["notification"]["notificationId"]
301
+ notification_id = res["notification"]["notificationId"]
302
+ logger.info(f"Created notification configuration '{notification_id}'.")
303
+ return notification_id
287
304
 
288
305
  def update_notification_config(
289
306
  self, notification_id: str, config: NotificationInput | dict[str, Any]
@@ -298,7 +315,7 @@ class _CloudWorksClient(_BaseClient):
298
315
  a dictionary as per the documentation. If a dictionary is passed, it will be
299
316
  validated against the NotificationConfig model before sending the request.
300
317
  """
301
- self._put(
318
+ self._http.put(
302
319
  f"{self._url}/notification/{notification_id}",
303
320
  json=construct_payload(NotificationInput, config),
304
321
  )
@@ -317,7 +334,8 @@ class _CloudWorksClient(_BaseClient):
317
334
  raise ValueError("Either notification_id or integration_id must be specified.")
318
335
  if integration_id:
319
336
  notification_id = (self.get_integration(integration_id)).notification_id
320
- self._delete(f"{self._url}/notification/{notification_id}")
337
+ self._http.delete(f"{self._url}/notification/{notification_id}")
338
+ logger.info(f"Deleted notification configuration '{notification_id}'.")
321
339
 
322
340
  def get_import_error_dump(self, run_id: str) -> bytes:
323
341
  """
@@ -329,7 +347,7 @@ class _CloudWorksClient(_BaseClient):
329
347
  :param run_id: The ID of the run to retrieve.
330
348
  :return: The error dump.
331
349
  """
332
- return self._get_binary(f"{self._url}/run/{run_id}/dump")
350
+ return self._http.get_binary(f"{self._url}/run/{run_id}/dump")
333
351
 
334
352
  def get_process_error_dump(self, run_id: str, action_id: int | str) -> bytes:
335
353
  """
@@ -339,4 +357,4 @@ class _CloudWorksClient(_BaseClient):
339
357
  :param action_id: The ID of the action to retrieve. This can be found in the RunError.
340
358
  :return: The error dump.
341
359
  """
342
- return self._get_binary(f"{self._url}/run/{run_id}/process/import/{action_id}/dumps")
360
+ return self._http.get_binary(f"{self._url}/run/{run_id}/process/import/{action_id}/dumps")
@@ -1,17 +1,18 @@
1
+ import logging
1
2
  from typing import Any
2
3
 
3
- import httpx
4
-
5
- from anaplan_sdk._base import _BaseClient, construct_payload
4
+ from anaplan_sdk._services import _HttpService, construct_payload
6
5
  from anaplan_sdk.models.flows import Flow, FlowInput, FlowSummary
7
6
 
7
+ logger = logging.getLogger("anaplan_sdk")
8
+
8
9
 
9
- class _FlowClient(_BaseClient):
10
- def __init__(self, client: httpx.Client, retry_count: int) -> None:
10
+ class _FlowClient:
11
+ def __init__(self, http: _HttpService) -> None:
12
+ self._http = http
11
13
  self._url = "https://api.cloudworks.anaplan.com/2/0/integrationflows"
12
- super().__init__(retry_count, client)
13
14
 
14
- def list_flows(self, current_user_only: bool = False) -> list[FlowSummary]:
15
+ def get_flows(self, current_user_only: bool = False) -> list[FlowSummary]:
15
16
  """
16
17
  List all flows in CloudWorks.
17
18
  :param current_user_only: Filters the flows to only those created by the current user.
@@ -20,7 +21,9 @@ class _FlowClient(_BaseClient):
20
21
  params = {"myIntegrations": 1 if current_user_only else 0}
21
22
  return [
22
23
  FlowSummary.model_validate(e)
23
- for e in self._get_paginated(self._url, "integrationFlows", page_size=25, params=params)
24
+ for e in self._http.get_paginated(
25
+ self._url, "integrationFlows", page_size=25, params=params
26
+ )
24
27
  ]
25
28
 
26
29
  def get_flow(self, flow_id: str) -> Flow:
@@ -30,7 +33,7 @@ class _FlowClient(_BaseClient):
30
33
  :param flow_id: The ID of the flow to get.
31
34
  :return: The Flow object.
32
35
  """
33
- return Flow.model_validate((self._get(f"{self._url}/{flow_id}"))["integrationFlow"])
36
+ return Flow.model_validate((self._http.get(f"{self._url}/{flow_id}"))["integrationFlow"])
34
37
 
35
38
  def run_flow(self, flow_id: str, only_steps: list[str] = None) -> str:
36
39
  """
@@ -43,11 +46,13 @@ class _FlowClient(_BaseClient):
43
46
  """
44
47
  url = f"{self._url}/{flow_id}/run"
45
48
  res = (
46
- self._post(url, json={"stepsToRun": only_steps})
49
+ self._http.post(url, json={"stepsToRun": only_steps})
47
50
  if only_steps
48
- else self._post_empty(url)
51
+ else self._http.post_empty(url)
49
52
  )
50
- return res["run"]["id"]
53
+ run_id = res["run"]["id"]
54
+ logger.info(f"Started flow run '{run_id}' for flow '{flow_id}'.")
55
+ return run_id
51
56
 
52
57
  def create_flow(self, flow: FlowInput | dict[str, Any]) -> str:
53
58
  """
@@ -57,8 +62,10 @@ class _FlowClient(_BaseClient):
57
62
  :param flow: The flow to create. This can be a FlowInput object or a dictionary.
58
63
  :return: The ID of the created flow.
59
64
  """
60
- res = self._post(self._url, json=construct_payload(FlowInput, flow))
61
- return res["integrationFlow"]["integrationFlowId"]
65
+ res = self._http.post(self._url, json=construct_payload(FlowInput, flow))
66
+ flow_id = res["integrationFlow"]["integrationFlowId"]
67
+ logger.info(f"Created flow '{flow_id}'.")
68
+ return flow_id
62
69
 
63
70
  def update_flow(self, flow_id: str, flow: FlowInput | dict[str, Any]) -> None:
64
71
  """
@@ -67,7 +74,8 @@ class _FlowClient(_BaseClient):
67
74
  :param flow_id: The ID of the flow to update.
68
75
  :param flow: The flow to update. This can be a FlowInput object or a dictionary.
69
76
  """
70
- self._put(f"{self._url}/{flow_id}", json=construct_payload(FlowInput, flow))
77
+ self._http.put(f"{self._url}/{flow_id}", json=construct_payload(FlowInput, flow))
78
+ logger.info(f"Updated flow '{flow_id}'.")
71
79
 
72
80
  def delete_flow(self, flow_id: str) -> None:
73
81
  """
@@ -75,4 +83,5 @@ class _FlowClient(_BaseClient):
75
83
  the flow is running or if it has any running steps.
76
84
  :param flow_id: The ID of the flow to delete.
77
85
  """
78
- self._delete(f"{self._url}/{flow_id}")
86
+ self._http.delete(f"{self._url}/{flow_id}")
87
+ logger.info(f"Deleted flow '{flow_id}'.")