campai-api 0.1.0__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.
@@ -0,0 +1,46 @@
1
+ # SPDX-FileCopyrightText: 2026 2026 Stephan Lukasczyk <stephan@dante.de>
2
+ #
3
+ # SPDX-License-Identifier: EUPL-1.2
4
+
5
+ """Base resource definitions for synchronous and asynchronous Campai API operations."""
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import TYPE_CHECKING
10
+
11
+ if TYPE_CHECKING:
12
+ from campai_api.transport import AsyncTransport, SyncTransport
13
+
14
+
15
+ class BaseResource:
16
+ """Base class for synchronous domain resources."""
17
+
18
+ def __init__(self, transport: SyncTransport) -> None:
19
+ """Initialize resource with the given transport.
20
+
21
+ Args:
22
+ transport: Synchronous transport instance.
23
+ """
24
+ self._transport = transport
25
+
26
+ @property
27
+ def transport(self) -> SyncTransport:
28
+ """The underlying synchronous transport engine."""
29
+ return self._transport
30
+
31
+
32
+ class AsyncBaseResource:
33
+ """Base class for asynchronous domain resources."""
34
+
35
+ def __init__(self, transport: AsyncTransport) -> None:
36
+ """Initialize resource with the given asynchronous transport.
37
+
38
+ Args:
39
+ transport: Asynchronous transport instance.
40
+ """
41
+ self._transport = transport
42
+
43
+ @property
44
+ def transport(self) -> AsyncTransport:
45
+ """The underlying asynchronous transport engine."""
46
+ return self._transport
@@ -0,0 +1,226 @@
1
+ # SPDX-FileCopyrightText: 2026 2026 Stephan Lukasczyk <stephan@dante.de>
2
+ #
3
+ # SPDX-License-Identifier: EUPL-1.2
4
+
5
+ """Finance, receipt, and invoice resources for Campai API."""
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import Any
10
+
11
+ from campai_api.models.finance import (
12
+ FinanceSettings,
13
+ FinanceSettingsUpdateRequest,
14
+ InvoiceCreateRequest,
15
+ InvoiceCreateResult,
16
+ InvoiceUpdateRequest,
17
+ ReceiptsListResponse,
18
+ )
19
+ from campai_api.resources.base import AsyncBaseResource, BaseResource
20
+ from campai_api.transport import quote_path_segment
21
+
22
+
23
+ class FinanceResource(BaseResource):
24
+ """Synchronous operations for finance settings, receipts, and invoices."""
25
+
26
+ def get_settings(self, organization_id: str) -> FinanceSettings:
27
+ """Retrieve organization finance settings."""
28
+ org_id = quote_path_segment(organization_id)
29
+ return self._transport.request_model(
30
+ "GET",
31
+ f"{org_id}/finance/settings",
32
+ FinanceSettings,
33
+ )
34
+
35
+ def update_settings(
36
+ self,
37
+ organization_id: str,
38
+ settings: FinanceSettingsUpdateRequest | FinanceSettings | dict[str, Any],
39
+ ) -> dict[str, Any]:
40
+ """Update organization finance settings."""
41
+ org_id = quote_path_segment(organization_id)
42
+ res = self._transport.post(
43
+ f"{org_id}/finance/settings",
44
+ json=settings,
45
+ )
46
+ return res if isinstance(res, dict) else {}
47
+
48
+ def list_receipts(
49
+ self,
50
+ organization_id: str,
51
+ mandate_id: str,
52
+ *,
53
+ limit: int = 50,
54
+ offset: int = 0,
55
+ return_count: bool = True,
56
+ search_term: str | None = None,
57
+ sort: dict[str, Any] | None = None,
58
+ user_filter: dict[str, Any] | None = None,
59
+ view: str | None = None,
60
+ has_receipt: bool | None = None,
61
+ selection: list[str] | None = None,
62
+ ) -> ReceiptsListResponse:
63
+ """List finance receipts for an organization and mandate."""
64
+ org_id = quote_path_segment(organization_id)
65
+ m_id = quote_path_segment(mandate_id)
66
+ payload: dict[str, Any] = {
67
+ "limit": limit,
68
+ "offset": offset,
69
+ "returnCount": return_count,
70
+ }
71
+ if search_term is not None:
72
+ payload["searchTerm"] = search_term
73
+ if sort is not None:
74
+ payload["sort"] = sort
75
+ if user_filter is not None:
76
+ payload["userFilter"] = user_filter
77
+ if view is not None:
78
+ payload["view"] = view
79
+ if has_receipt is not None:
80
+ payload["hasReceipt"] = has_receipt
81
+ if selection is not None:
82
+ payload["selection"] = selection
83
+
84
+ return self._transport.request_model(
85
+ "POST",
86
+ f"{org_id}/{m_id}/finance/receipts/list",
87
+ ReceiptsListResponse,
88
+ json=payload,
89
+ )
90
+
91
+ def create_invoice(
92
+ self,
93
+ organization_id: str,
94
+ mandate_id: str,
95
+ invoice: InvoiceCreateRequest | dict[str, Any],
96
+ ) -> InvoiceCreateResult:
97
+ """Create a new invoice receipt."""
98
+ org_id = quote_path_segment(organization_id)
99
+ m_id = quote_path_segment(mandate_id)
100
+ return self._transport.request_model(
101
+ "POST",
102
+ f"{org_id}/{m_id}/receipts/invoice",
103
+ InvoiceCreateResult,
104
+ json=invoice,
105
+ )
106
+
107
+ def update_invoice(
108
+ self,
109
+ organization_id: str,
110
+ mandate_id: str,
111
+ receipt_id: str,
112
+ invoice: InvoiceUpdateRequest | InvoiceCreateRequest | dict[str, Any],
113
+ ) -> InvoiceCreateResult:
114
+ """Update an existing invoice receipt."""
115
+ org_id = quote_path_segment(organization_id)
116
+ m_id = quote_path_segment(mandate_id)
117
+ r_id = quote_path_segment(receipt_id)
118
+ return self._transport.request_model(
119
+ "POST",
120
+ f"{org_id}/{m_id}/receipts/invoice/{r_id}",
121
+ InvoiceCreateResult,
122
+ json=invoice,
123
+ )
124
+
125
+
126
+ class AsyncFinanceResource(AsyncBaseResource):
127
+ """Asynchronous operations for finance settings, receipts, and invoices."""
128
+
129
+ async def get_settings(self, organization_id: str) -> FinanceSettings:
130
+ """Retrieve organization finance settings."""
131
+ org_id = quote_path_segment(organization_id)
132
+ return await self._transport.request_model(
133
+ "GET",
134
+ f"{org_id}/finance/settings",
135
+ FinanceSettings,
136
+ )
137
+
138
+ async def update_settings(
139
+ self,
140
+ organization_id: str,
141
+ settings: FinanceSettingsUpdateRequest | FinanceSettings | dict[str, Any],
142
+ ) -> dict[str, Any]:
143
+ """Update organization finance settings."""
144
+ org_id = quote_path_segment(organization_id)
145
+ res = await self._transport.post(
146
+ f"{org_id}/finance/settings",
147
+ json=settings,
148
+ )
149
+ return res if isinstance(res, dict) else {}
150
+
151
+ async def list_receipts(
152
+ self,
153
+ organization_id: str,
154
+ mandate_id: str,
155
+ *,
156
+ limit: int = 50,
157
+ offset: int = 0,
158
+ return_count: bool = True,
159
+ search_term: str | None = None,
160
+ sort: dict[str, Any] | None = None,
161
+ user_filter: dict[str, Any] | None = None,
162
+ view: str | None = None,
163
+ has_receipt: bool | None = None,
164
+ selection: list[str] | None = None,
165
+ ) -> ReceiptsListResponse:
166
+ """List finance receipts for an organization and mandate."""
167
+ org_id = quote_path_segment(organization_id)
168
+ m_id = quote_path_segment(mandate_id)
169
+ payload: dict[str, Any] = {
170
+ "limit": limit,
171
+ "offset": offset,
172
+ "returnCount": return_count,
173
+ }
174
+ if search_term is not None:
175
+ payload["searchTerm"] = search_term
176
+ if sort is not None:
177
+ payload["sort"] = sort
178
+ if user_filter is not None:
179
+ payload["userFilter"] = user_filter
180
+ if view is not None:
181
+ payload["view"] = view
182
+ if has_receipt is not None:
183
+ payload["hasReceipt"] = has_receipt
184
+ if selection is not None:
185
+ payload["selection"] = selection
186
+
187
+ return await self._transport.request_model(
188
+ "POST",
189
+ f"{org_id}/{m_id}/finance/receipts/list",
190
+ ReceiptsListResponse,
191
+ json=payload,
192
+ )
193
+
194
+ async def create_invoice(
195
+ self,
196
+ organization_id: str,
197
+ mandate_id: str,
198
+ invoice: InvoiceCreateRequest | dict[str, Any],
199
+ ) -> InvoiceCreateResult:
200
+ """Create a new invoice receipt."""
201
+ org_id = quote_path_segment(organization_id)
202
+ m_id = quote_path_segment(mandate_id)
203
+ return await self._transport.request_model(
204
+ "POST",
205
+ f"{org_id}/{m_id}/receipts/invoice",
206
+ InvoiceCreateResult,
207
+ json=invoice,
208
+ )
209
+
210
+ async def update_invoice(
211
+ self,
212
+ organization_id: str,
213
+ mandate_id: str,
214
+ receipt_id: str,
215
+ invoice: InvoiceUpdateRequest | InvoiceCreateRequest | dict[str, Any],
216
+ ) -> InvoiceCreateResult:
217
+ """Update an existing invoice receipt."""
218
+ org_id = quote_path_segment(organization_id)
219
+ m_id = quote_path_segment(mandate_id)
220
+ r_id = quote_path_segment(receipt_id)
221
+ return await self._transport.request_model(
222
+ "POST",
223
+ f"{org_id}/{m_id}/receipts/invoice/{r_id}",
224
+ InvoiceCreateResult,
225
+ json=invoice,
226
+ )
@@ -0,0 +1,252 @@
1
+ # SPDX-FileCopyrightText: 2026 2026 Stephan Lukasczyk <stephan@dante.de>
2
+ #
3
+ # SPDX-License-Identifier: EUPL-1.2
4
+
5
+ """Members and CRM contacts resources for Campai API."""
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import TYPE_CHECKING, Any
10
+
11
+ if TYPE_CHECKING:
12
+ from collections.abc import Sequence
13
+
14
+ from campai_api.models.members import (
15
+ Contact,
16
+ ContactCreateRequest,
17
+ ContactCreateResult,
18
+ ContactsListResponse,
19
+ ContactUpdateRequest,
20
+ )
21
+ from campai_api.resources.base import AsyncBaseResource, BaseResource
22
+ from campai_api.transport import quote_path_segment
23
+
24
+
25
+ class MembersResource(BaseResource):
26
+ """Synchronous operations for CRM contacts and members."""
27
+
28
+ def list(
29
+ self,
30
+ organization_id: str,
31
+ mandate_id: str,
32
+ *,
33
+ limit: int = 50,
34
+ offset: int = 0,
35
+ return_count: bool = True,
36
+ search_term: str | None = None,
37
+ segments: Sequence[str] | None = None,
38
+ types: Sequence[str] | None = None,
39
+ team_id: str | None = None,
40
+ user_assigned: str | None = None,
41
+ user_filter: dict[str, Any] | None = None,
42
+ sort: dict[str, Any] | None = None,
43
+ selection: Sequence[str] | None = None,
44
+ ) -> ContactsListResponse:
45
+ """List CRM contacts/members for an organization and mandate."""
46
+ org_id = quote_path_segment(organization_id)
47
+ m_id = quote_path_segment(mandate_id)
48
+ payload: dict[str, Any] = {
49
+ "limit": limit,
50
+ "offset": offset,
51
+ "returnCount": return_count,
52
+ }
53
+ if search_term is not None:
54
+ payload["searchTerm"] = search_term
55
+ if segments is not None:
56
+ payload["segments"] = segments
57
+ if types is not None:
58
+ payload["types"] = types
59
+ if team_id is not None:
60
+ payload["teamId"] = team_id
61
+ if user_assigned is not None:
62
+ payload["userAssigned"] = user_assigned
63
+ if user_filter is not None:
64
+ payload["userFilter"] = user_filter
65
+ if sort is not None:
66
+ payload["sort"] = sort
67
+ if selection is not None:
68
+ payload["selection"] = selection
69
+
70
+ return self._transport.request_model(
71
+ "POST",
72
+ f"{org_id}/{m_id}/crm/contacts/list",
73
+ ContactsListResponse,
74
+ json=payload,
75
+ )
76
+
77
+ def get(
78
+ self,
79
+ organization_id: str,
80
+ mandate_id: str,
81
+ contact_id: str,
82
+ ) -> Contact:
83
+ """Retrieve a single CRM contact by ID."""
84
+ org_id = quote_path_segment(organization_id)
85
+ m_id = quote_path_segment(mandate_id)
86
+ c_id = quote_path_segment(contact_id)
87
+ return self._transport.request_model(
88
+ "GET",
89
+ f"{org_id}/{m_id}/crm/contacts/{c_id}",
90
+ Contact,
91
+ )
92
+
93
+ def create(
94
+ self,
95
+ organization_id: str,
96
+ mandate_id: str,
97
+ contact: ContactCreateRequest | dict[str, Any],
98
+ ) -> ContactCreateResult:
99
+ """Create a new CRM contact."""
100
+ org_id = quote_path_segment(organization_id)
101
+ m_id = quote_path_segment(mandate_id)
102
+ return self._transport.request_model(
103
+ "POST",
104
+ f"{org_id}/{m_id}/crm/contacts",
105
+ ContactCreateResult,
106
+ json=contact,
107
+ )
108
+
109
+ def update(
110
+ self,
111
+ organization_id: str,
112
+ mandate_id: str,
113
+ contact_id: str,
114
+ contact: ContactUpdateRequest | dict[str, Any],
115
+ ) -> dict[str, Any]:
116
+ """Update an existing CRM contact."""
117
+ org_id = quote_path_segment(organization_id)
118
+ m_id = quote_path_segment(mandate_id)
119
+ c_id = quote_path_segment(contact_id)
120
+ res = self._transport.post(
121
+ f"{org_id}/{m_id}/crm/contacts/{c_id}",
122
+ json=contact,
123
+ )
124
+ return res if isinstance(res, dict) else {}
125
+
126
+ def delete(
127
+ self,
128
+ organization_id: str,
129
+ mandate_id: str,
130
+ contact_id: str,
131
+ ) -> dict[str, Any]:
132
+ """Delete a CRM contact."""
133
+ org_id = quote_path_segment(organization_id)
134
+ m_id = quote_path_segment(mandate_id)
135
+ c_id = quote_path_segment(contact_id)
136
+ res = self._transport.delete(f"{org_id}/{m_id}/crm/contacts/{c_id}")
137
+ return res if isinstance(res, dict) else {}
138
+
139
+
140
+ class AsyncMembersResource(AsyncBaseResource):
141
+ """Asynchronous operations for CRM contacts and members."""
142
+
143
+ async def list(
144
+ self,
145
+ organization_id: str,
146
+ mandate_id: str,
147
+ *,
148
+ limit: int = 50,
149
+ offset: int = 0,
150
+ return_count: bool = True,
151
+ search_term: str | None = None,
152
+ segments: Sequence[str] | None = None,
153
+ types: Sequence[str] | None = None,
154
+ team_id: str | None = None,
155
+ user_assigned: str | None = None,
156
+ user_filter: dict[str, Any] | None = None,
157
+ sort: dict[str, Any] | None = None,
158
+ selection: Sequence[str] | None = None,
159
+ ) -> ContactsListResponse:
160
+ """List CRM contacts/members for an organization and mandate."""
161
+ org_id = quote_path_segment(organization_id)
162
+ m_id = quote_path_segment(mandate_id)
163
+ payload: dict[str, Any] = {
164
+ "limit": limit,
165
+ "offset": offset,
166
+ "returnCount": return_count,
167
+ }
168
+ if search_term is not None:
169
+ payload["searchTerm"] = search_term
170
+ if segments is not None:
171
+ payload["segments"] = segments
172
+ if types is not None:
173
+ payload["types"] = types
174
+ if team_id is not None:
175
+ payload["teamId"] = team_id
176
+ if user_assigned is not None:
177
+ payload["userAssigned"] = user_assigned
178
+ if user_filter is not None:
179
+ payload["userFilter"] = user_filter
180
+ if sort is not None:
181
+ payload["sort"] = sort
182
+ if selection is not None:
183
+ payload["selection"] = selection
184
+
185
+ return await self._transport.request_model(
186
+ "POST",
187
+ f"{org_id}/{m_id}/crm/contacts/list",
188
+ ContactsListResponse,
189
+ json=payload,
190
+ )
191
+
192
+ async def get(
193
+ self,
194
+ organization_id: str,
195
+ mandate_id: str,
196
+ contact_id: str,
197
+ ) -> Contact:
198
+ """Retrieve a single CRM contact by ID."""
199
+ org_id = quote_path_segment(organization_id)
200
+ m_id = quote_path_segment(mandate_id)
201
+ c_id = quote_path_segment(contact_id)
202
+ return await self._transport.request_model(
203
+ "GET",
204
+ f"{org_id}/{m_id}/crm/contacts/{c_id}",
205
+ Contact,
206
+ )
207
+
208
+ async def create(
209
+ self,
210
+ organization_id: str,
211
+ mandate_id: str,
212
+ contact: ContactCreateRequest | dict[str, Any],
213
+ ) -> ContactCreateResult:
214
+ """Create a new CRM contact."""
215
+ org_id = quote_path_segment(organization_id)
216
+ m_id = quote_path_segment(mandate_id)
217
+ return await self._transport.request_model(
218
+ "POST",
219
+ f"{org_id}/{m_id}/crm/contacts",
220
+ ContactCreateResult,
221
+ json=contact,
222
+ )
223
+
224
+ async def update(
225
+ self,
226
+ organization_id: str,
227
+ mandate_id: str,
228
+ contact_id: str,
229
+ contact: ContactUpdateRequest | dict[str, Any],
230
+ ) -> dict[str, Any]:
231
+ """Update an existing CRM contact."""
232
+ org_id = quote_path_segment(organization_id)
233
+ m_id = quote_path_segment(mandate_id)
234
+ c_id = quote_path_segment(contact_id)
235
+ res = await self._transport.post(
236
+ f"{org_id}/{m_id}/crm/contacts/{c_id}",
237
+ json=contact,
238
+ )
239
+ return res if isinstance(res, dict) else {}
240
+
241
+ async def delete(
242
+ self,
243
+ organization_id: str,
244
+ mandate_id: str,
245
+ contact_id: str,
246
+ ) -> dict[str, Any]:
247
+ """Delete a CRM contact."""
248
+ org_id = quote_path_segment(organization_id)
249
+ m_id = quote_path_segment(mandate_id)
250
+ c_id = quote_path_segment(contact_id)
251
+ res = await self._transport.delete(f"{org_id}/{m_id}/crm/contacts/{c_id}")
252
+ return res if isinstance(res, dict) else {}
@@ -0,0 +1,116 @@
1
+ # SPDX-FileCopyrightText: 2026 2026 Stephan Lukasczyk <stephan@dante.de>
2
+ #
3
+ # SPDX-License-Identifier: EUPL-1.2
4
+
5
+ """Webhooks resources for Campai API.
6
+
7
+ Note:
8
+ Campai REST API OpenAPI specification supports webhook triggering for
9
+ existing contacts and members (`POST /{organizationId}/oldContacts/{contactId}/triggerWebhooks`
10
+ and `POST /{organizationId}/oldMembers/{contactId}/triggerWebhooks`).
11
+ Webhook subscription management (CRUD on webhook endpoints) is not provided by the API.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ from typing import Any
17
+
18
+ from campai_api.models.webhooks import WebhookTriggerEvent
19
+ from campai_api.resources.base import AsyncBaseResource, BaseResource
20
+ from campai_api.transport import quote_path_segment
21
+
22
+
23
+ class WebhooksResource(BaseResource):
24
+ """Synchronous operations for triggering webhooks."""
25
+
26
+ def trigger_contact_webhooks(
27
+ self,
28
+ organization_id: str,
29
+ contact_id: str,
30
+ event: WebhookTriggerEvent | str,
31
+ ) -> dict[str, Any]:
32
+ """Trigger webhooks for an existing contact.
33
+
34
+ Args:
35
+ organization_id: Organization identifier.
36
+ contact_id: Contact identifier.
37
+ event: Event type ('created', 'updated', 'deleted').
38
+ """
39
+ org_id = quote_path_segment(organization_id)
40
+ c_id = quote_path_segment(contact_id)
41
+ event_str = event.value if isinstance(event, WebhookTriggerEvent) else str(event)
42
+ res = self._transport.post(
43
+ f"{org_id}/oldContacts/{c_id}/triggerWebhooks",
44
+ json={"event": event_str},
45
+ )
46
+ return res if isinstance(res, dict) else {}
47
+
48
+ def trigger_member_webhooks(
49
+ self,
50
+ organization_id: str,
51
+ contact_id: str,
52
+ event: WebhookTriggerEvent | str,
53
+ ) -> dict[str, Any]:
54
+ """Trigger webhooks for an existing member.
55
+
56
+ Args:
57
+ organization_id: Organization identifier.
58
+ contact_id: Contact / Member identifier.
59
+ event: Event type ('created', 'updated', 'deleted').
60
+ """
61
+ org_id = quote_path_segment(organization_id)
62
+ c_id = quote_path_segment(contact_id)
63
+ event_str = event.value if isinstance(event, WebhookTriggerEvent) else str(event)
64
+ res = self._transport.post(
65
+ f"{org_id}/oldMembers/{c_id}/triggerWebhooks",
66
+ json={"event": event_str},
67
+ )
68
+ return res if isinstance(res, dict) else {}
69
+
70
+
71
+ class AsyncWebhooksResource(AsyncBaseResource):
72
+ """Asynchronous operations for triggering webhooks."""
73
+
74
+ async def trigger_contact_webhooks(
75
+ self,
76
+ organization_id: str,
77
+ contact_id: str,
78
+ event: WebhookTriggerEvent | str,
79
+ ) -> dict[str, Any]:
80
+ """Trigger webhooks for an existing contact.
81
+
82
+ Args:
83
+ organization_id: Organization identifier.
84
+ contact_id: Contact identifier.
85
+ event: Event type ('created', 'updated', 'deleted').
86
+ """
87
+ org_id = quote_path_segment(organization_id)
88
+ c_id = quote_path_segment(contact_id)
89
+ event_str = event.value if isinstance(event, WebhookTriggerEvent) else str(event)
90
+ res = await self._transport.post(
91
+ f"{org_id}/oldContacts/{c_id}/triggerWebhooks",
92
+ json={"event": event_str},
93
+ )
94
+ return res if isinstance(res, dict) else {}
95
+
96
+ async def trigger_member_webhooks(
97
+ self,
98
+ organization_id: str,
99
+ contact_id: str,
100
+ event: WebhookTriggerEvent | str,
101
+ ) -> dict[str, Any]:
102
+ """Trigger webhooks for an existing member.
103
+
104
+ Args:
105
+ organization_id: Organization identifier.
106
+ contact_id: Contact / Member identifier.
107
+ event: Event type ('created', 'updated', 'deleted').
108
+ """
109
+ org_id = quote_path_segment(organization_id)
110
+ c_id = quote_path_segment(contact_id)
111
+ event_str = event.value if isinstance(event, WebhookTriggerEvent) else str(event)
112
+ res = await self._transport.post(
113
+ f"{org_id}/oldMembers/{c_id}/triggerWebhooks",
114
+ json={"event": event_str},
115
+ )
116
+ return res if isinstance(res, dict) else {}