pingen2sdk 2.2.0__tar.gz → 2.3.1__tar.gz

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.
Files changed (61) hide show
  1. pingen2sdk-2.3.1/.coveragerc +6 -0
  2. {pingen2sdk-2.2.0/pingen2sdk.egg-info → pingen2sdk-2.3.1}/PKG-INFO +80 -4
  3. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/README.md +78 -2
  4. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/__init__.py +4 -0
  5. pingen2sdk-2.3.1/pingen2sdk/access_token.py +29 -0
  6. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/api.py +21 -5
  7. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/api_resources/__init__.py +2 -0
  8. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/api_resources/batch_events.py +2 -2
  9. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/api_resources/batches.py +105 -11
  10. pingen2sdk-2.3.1/pingen2sdk/api_resources/ebill_events.py +30 -0
  11. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/api_resources/ebills.py +46 -2
  12. pingen2sdk-2.3.1/pingen2sdk/api_resources/email_events.py +30 -0
  13. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/api_resources/emails.py +30 -3
  14. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/api_resources/letter_events.py +2 -2
  15. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/api_resources/letters.py +2 -2
  16. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/api_resources/organisations.py +2 -2
  17. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/api_resources/user_associations.py +2 -2
  18. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/api_resources/users.py +2 -2
  19. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/api_resources/webhooks.py +2 -2
  20. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/oauth.py +50 -1
  21. pingen2sdk-2.3.1/pingen2sdk/pingen.py +87 -0
  22. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1/pingen2sdk.egg-info}/PKG-INFO +80 -4
  23. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk.egg-info/SOURCES.txt +13 -1
  24. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pyproject.toml +3 -3
  25. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/tests/api_resources/test_batches.py +128 -10
  26. pingen2sdk-2.3.1/tests/api_resources/test_ebill_events.py +86 -0
  27. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/tests/api_resources/test_ebills.py +130 -16
  28. pingen2sdk-2.3.1/tests/api_resources/test_email_events.py +86 -0
  29. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/tests/api_resources/test_emails.py +88 -16
  30. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/tests/api_resources/test_letters.py +12 -7
  31. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/tests/api_resources/test_organisations.py +0 -2
  32. pingen2sdk-2.3.1/tests/integration/__init__.py +0 -0
  33. pingen2sdk-2.3.1/tests/integration/conftest.py +118 -0
  34. pingen2sdk-2.3.1/tests/integration/support.py +103 -0
  35. pingen2sdk-2.3.1/tests/integration/test_oauth_integration.py +68 -0
  36. pingen2sdk-2.3.1/tests/integration/test_pingen_integration.py +624 -0
  37. pingen2sdk-2.3.1/tests/test_oauth.py +207 -0
  38. pingen2sdk-2.3.1/tests/test_pingen.py +124 -0
  39. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/tox.ini +8 -6
  40. pingen2sdk-2.2.0/.coveragerc +0 -4
  41. pingen2sdk-2.2.0/tests/test_oauth.py +0 -104
  42. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/LICENSE +0 -0
  43. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/MANIFEST.in +0 -0
  44. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/api_resources/file_upload.py +0 -0
  45. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/error.py +0 -0
  46. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/incoming_webhook.py +0 -0
  47. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/response.py +0 -0
  48. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk/webhook_event.py +0 -0
  49. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk.egg-info/dependency_links.txt +0 -0
  50. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk.egg-info/requires.txt +0 -0
  51. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/pingen2sdk.egg-info/top_level.txt +0 -0
  52. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/setup.cfg +0 -0
  53. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/tests/__init__.py +0 -0
  54. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/tests/api_resources/__init__.py +0 -0
  55. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/tests/api_resources/test_batch_events.py +0 -0
  56. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/tests/api_resources/test_file_upload.py +0 -0
  57. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/tests/api_resources/test_letter_events.py +0 -0
  58. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/tests/api_resources/test_user_accociations.py +0 -0
  59. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/tests/api_resources/test_users.py +0 -0
  60. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/tests/api_resources/test_webhooks.py +0 -0
  61. {pingen2sdk-2.2.0 → pingen2sdk-2.3.1}/tests/test_incoming_webhook.py +0 -0
@@ -0,0 +1,6 @@
1
+ [run]
2
+ branch = true
3
+ parallel = true
4
+ source = pingen2sdk
5
+ omit =
6
+ tests/integration/*
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pingen2sdk
3
- Version: 2.2.0
3
+ Version: 2.3.1
4
4
  Summary: Official Python Pingen SDK for API V2
5
5
  Author-email: Pingen GmbH <info@pingen.com>
6
6
  License: BSD-3-Clause
@@ -11,14 +11,14 @@ Classifier: Intended Audience :: Developers
11
11
  Classifier: Natural Language :: English
12
12
  Classifier: Operating System :: OS Independent
13
13
  Classifier: Programming Language :: Python
14
- Classifier: Programming Language :: Python :: 3.10
15
14
  Classifier: Programming Language :: Python :: 3.11
16
15
  Classifier: Programming Language :: Python :: 3.12
17
16
  Classifier: Programming Language :: Python :: 3.13
18
17
  Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: 3.15
19
19
  Classifier: Programming Language :: Python :: Implementation :: PyPy
20
20
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
- Requires-Python: >=3.10
21
+ Requires-Python: >=3.11
22
22
  Description-Content-Type: text/markdown
23
23
  License-File: LICENSE
24
24
  Requires-Dist: requests>=2.31.0
@@ -32,7 +32,7 @@ You need to have an account in pingen and obtain oauth credentials for your desi
32
32
 
33
33
  How to obtain these are described here: https://api.pingen.com/documentation#section/Authentication/How-to-obtain-a-Client-ID
34
34
 
35
- Python 3.10+
35
+ Python 3.11+
36
36
 
37
37
  # Installation
38
38
 
@@ -52,6 +52,44 @@ This SDK supports staging as well. **When initiating the resource** (see Usage),
52
52
 
53
53
  The simplest way to integrate is using the client credentials grant (see https://api.pingen.com/documentation#section/Authentication/Which-grant-type-should-i-use)
54
54
 
55
+ ### Recommended: the `Pingen` client
56
+
57
+ Create a `Pingen` client once with your credentials and obtain resources from it.
58
+ The access token is fetched once, reused across all resources and refreshed
59
+ automatically before it expires, so you never pass a token or the staging flag
60
+ around:
61
+
62
+ ```python
63
+ import pingen2sdk
64
+
65
+ pingen = pingen2sdk.Pingen(
66
+ client_id="YOUR_CLIENT_ID",
67
+ client_secret="YOUR_SECRET",
68
+ use_staging=True,
69
+ scope="letter batch webhook organisation_read email ebill",
70
+ )
71
+
72
+ organisationList = pingen.organisations().get_collection()
73
+ organisation_id = organisationList.data["data"][0]["id"]
74
+
75
+ response = pingen.letters(organisation_id).upload_and_create(
76
+ "./letter.pdf",
77
+ "sdk.pdf",
78
+ "left",
79
+ False,
80
+ "fast",
81
+ "simplex",
82
+ "color",
83
+ )
84
+
85
+ letter_id = response.data["data"]["id"]
86
+ ```
87
+
88
+ ### Manual token handling
89
+
90
+ You can also obtain a token yourself and pass it (as a string) to each resource.
91
+ This still works and is fully supported:
92
+
55
93
  ```python
56
94
  import pingen2sdk
57
95
 
@@ -85,6 +123,10 @@ response = LettersEndpoint.upload_and_create(
85
123
  letter_id = response.data["data"]["id"]
86
124
  ```
87
125
 
126
+ > Tip: pass the `pingen2sdk.OAuth` instance (instead of a raw token string) to any
127
+ > resource constructor to get the same automatic token reuse and refresh without
128
+ > using the `Pingen` client.
129
+
88
130
  # Examples & Docs
89
131
 
90
132
  Our API Docs are here: https://api.pingen.com/documentation
@@ -125,3 +167,37 @@ with:
125
167
  ```sh
126
168
  tox -e fmt
127
169
  ```
170
+
171
+ ## Integration tests
172
+
173
+ `tests/integration` contains an end-to-end suite that runs against the real
174
+ Pingen **staging** API (organisations, letters, batches, webhooks, emails,
175
+ e-bills and user endpoints). It is marked with the `integration` marker and is
176
+ therefore **excluded from the normal test run** – it never runs unless you ask
177
+ for it explicitly.
178
+
179
+ 1. Copy the credentials template and fill in your staging OAuth credentials:
180
+
181
+ ```sh
182
+ cp .env.example .env
183
+ ```
184
+
185
+ Fill in `PINGEN2_CLIENT_ID` and `PINGEN2_CLIENT_SECRET`. Optionally set
186
+ `PINGEN2_ORGANISATION_ID` to run against a specific organisation (handy when
187
+ your credentials have access to several); when left empty the first
188
+ organisation returned by the API is used.
189
+
190
+ (`.env` is git-ignored. The values can also be supplied as real environment
191
+ variables, e.g. in CI.)
192
+
193
+ 2. Run only the integration suite:
194
+
195
+ ```sh
196
+ pytest -m integration tests/integration
197
+ ```
198
+
199
+ If no credentials are configured, every integration test is skipped rather than
200
+ failing, so `pytest -m integration` is safe to run anywhere. The cancel / delete
201
+ / update steps assert strictly against the real API and therefore need the
202
+ deliverable to reach the required state (they rely on the committed
203
+ `test_simulate_cancellable.pdf` document and short `time.sleep` waits).
@@ -4,7 +4,7 @@ You need to have an account in pingen and obtain oauth credentials for your desi
4
4
 
5
5
  How to obtain these are described here: https://api.pingen.com/documentation#section/Authentication/How-to-obtain-a-Client-ID
6
6
 
7
- Python 3.10+
7
+ Python 3.11+
8
8
 
9
9
  # Installation
10
10
 
@@ -24,6 +24,44 @@ This SDK supports staging as well. **When initiating the resource** (see Usage),
24
24
 
25
25
  The simplest way to integrate is using the client credentials grant (see https://api.pingen.com/documentation#section/Authentication/Which-grant-type-should-i-use)
26
26
 
27
+ ### Recommended: the `Pingen` client
28
+
29
+ Create a `Pingen` client once with your credentials and obtain resources from it.
30
+ The access token is fetched once, reused across all resources and refreshed
31
+ automatically before it expires, so you never pass a token or the staging flag
32
+ around:
33
+
34
+ ```python
35
+ import pingen2sdk
36
+
37
+ pingen = pingen2sdk.Pingen(
38
+ client_id="YOUR_CLIENT_ID",
39
+ client_secret="YOUR_SECRET",
40
+ use_staging=True,
41
+ scope="letter batch webhook organisation_read email ebill",
42
+ )
43
+
44
+ organisationList = pingen.organisations().get_collection()
45
+ organisation_id = organisationList.data["data"][0]["id"]
46
+
47
+ response = pingen.letters(organisation_id).upload_and_create(
48
+ "./letter.pdf",
49
+ "sdk.pdf",
50
+ "left",
51
+ False,
52
+ "fast",
53
+ "simplex",
54
+ "color",
55
+ )
56
+
57
+ letter_id = response.data["data"]["id"]
58
+ ```
59
+
60
+ ### Manual token handling
61
+
62
+ You can also obtain a token yourself and pass it (as a string) to each resource.
63
+ This still works and is fully supported:
64
+
27
65
  ```python
28
66
  import pingen2sdk
29
67
 
@@ -57,6 +95,10 @@ response = LettersEndpoint.upload_and_create(
57
95
  letter_id = response.data["data"]["id"]
58
96
  ```
59
97
 
98
+ > Tip: pass the `pingen2sdk.OAuth` instance (instead of a raw token string) to any
99
+ > resource constructor to get the same automatic token reuse and refresh without
100
+ > using the `Pingen` client.
101
+
60
102
  # Examples & Docs
61
103
 
62
104
  Our API Docs are here: https://api.pingen.com/documentation
@@ -96,4 +138,38 @@ with:
96
138
 
97
139
  ```sh
98
140
  tox -e fmt
99
- ```
141
+ ```
142
+
143
+ ## Integration tests
144
+
145
+ `tests/integration` contains an end-to-end suite that runs against the real
146
+ Pingen **staging** API (organisations, letters, batches, webhooks, emails,
147
+ e-bills and user endpoints). It is marked with the `integration` marker and is
148
+ therefore **excluded from the normal test run** – it never runs unless you ask
149
+ for it explicitly.
150
+
151
+ 1. Copy the credentials template and fill in your staging OAuth credentials:
152
+
153
+ ```sh
154
+ cp .env.example .env
155
+ ```
156
+
157
+ Fill in `PINGEN2_CLIENT_ID` and `PINGEN2_CLIENT_SECRET`. Optionally set
158
+ `PINGEN2_ORGANISATION_ID` to run against a specific organisation (handy when
159
+ your credentials have access to several); when left empty the first
160
+ organisation returned by the API is used.
161
+
162
+ (`.env` is git-ignored. The values can also be supplied as real environment
163
+ variables, e.g. in CI.)
164
+
165
+ 2. Run only the integration suite:
166
+
167
+ ```sh
168
+ pytest -m integration tests/integration
169
+ ```
170
+
171
+ If no credentials are configured, every integration test is skipped rather than
172
+ failing, so `pytest -m integration` is safe to run anywhere. The cancel / delete
173
+ / update steps assert strictly against the real API and therefore need the
174
+ deliverable to reach the required state (they rely on the committed
175
+ `test_simulate_cancellable.pdf` document and short `time.sleep` waits).
@@ -13,6 +13,7 @@ auth_staging: str = "https://identity-staging.pingen.com"
13
13
  request_timeout: int = 20
14
14
 
15
15
  # OAuth
16
+ from pingen2sdk.access_token import AccessToken
16
17
  from pingen2sdk.oauth import OAuth
17
18
 
18
19
  # PingenResponse
@@ -27,6 +28,9 @@ from pingen2sdk.api import APIRequestor
27
28
  # API Resources
28
29
  from pingen2sdk.api_resources import *
29
30
 
31
+ # Pingen high-level client
32
+ from pingen2sdk.pingen import Pingen
33
+
30
34
  # PingenWebhook
31
35
  from pingen2sdk.webhook_event import WebhookEvent
32
36
 
@@ -0,0 +1,29 @@
1
+ import time
2
+
3
+ from typing import Optional
4
+
5
+
6
+ class AccessToken(object):
7
+ access_token: str
8
+ token_type: str
9
+ expires_in: int
10
+ issued_at: float
11
+
12
+ def __init__(
13
+ self,
14
+ access_token: str,
15
+ expires_in: int,
16
+ token_type: str = "Bearer",
17
+ issued_at: Optional[float] = None,
18
+ ):
19
+ self.access_token = access_token
20
+ self.expires_in = int(expires_in)
21
+ self.token_type = token_type
22
+ self.issued_at = issued_at if issued_at is not None else time.time()
23
+
24
+ @property
25
+ def expires_at(self) -> float:
26
+ return self.issued_at + self.expires_in
27
+
28
+ def is_expired(self, buffer_seconds: int = 300) -> bool:
29
+ return time.time() >= (self.expires_at - buffer_seconds)
@@ -2,7 +2,7 @@ import requests
2
2
  import pingen2sdk
3
3
 
4
4
  from io import IOBase, BytesIO
5
- from typing import Any, Dict, Mapping, Optional, cast
5
+ from typing import Any, Dict, Mapping, Optional, Union, cast
6
6
  from requests.models import PreparedRequest
7
7
 
8
8
 
@@ -18,17 +18,28 @@ def _response_interpreter(
18
18
 
19
19
 
20
20
  class APIRequestor(object):
21
- access_token: str
22
21
  api_base: str
23
22
  user_agent: str = "PINGEN.SDK.PYTHON"
24
23
 
25
- def __init__(self, access_token: str, use_staging: Optional[bool] = False):
24
+ def __init__(
25
+ self,
26
+ access_token: Union[str, "pingen2sdk.OAuth"],
27
+ use_staging: Optional[bool] = False,
28
+ ):
26
29
  if use_staging is False:
27
30
  self.api_base = pingen2sdk.api_production
28
31
  else:
29
32
  self.api_base = pingen2sdk.api_staging
30
33
 
31
- self.access_token = access_token
34
+ self._token_source = access_token
35
+
36
+ @property
37
+ def access_token(self) -> str:
38
+ source = self._token_source
39
+ if hasattr(source, "get_access_token"):
40
+ return source.get_access_token()
41
+
42
+ return source
32
43
 
33
44
  def perform_get_request(
34
45
  self,
@@ -90,9 +101,14 @@ class APIRequestor(object):
90
101
 
91
102
  return _response_interpreter(r.text, r.status_code, r.headers)
92
103
 
93
- def perform_delete_request(self, url: str) -> pingen2sdk.PingenResponse:
104
+ def perform_delete_request(
105
+ self,
106
+ url: str,
107
+ payload: Optional[str] = None,
108
+ ) -> pingen2sdk.PingenResponse:
94
109
  r = requests.delete(
95
110
  self.prepare_path(url),
111
+ data=payload,
96
112
  headers=self.request_headers(),
97
113
  timeout=pingen2sdk.request_timeout,
98
114
  )
@@ -11,4 +11,6 @@ from pingen2sdk.api_resources.batches import Batches as Batches
11
11
  from pingen2sdk.api_resources.batch_events import BatchEvents as BatchEvents
12
12
  from pingen2sdk.api_resources.webhooks import Webhooks as Webhooks
13
13
  from pingen2sdk.api_resources.ebills import Ebills as Ebills
14
+ from pingen2sdk.api_resources.ebill_events import EbillEvents as EbillEvents
14
15
  from pingen2sdk.api_resources.emails import Emails as Emails
16
+ from pingen2sdk.api_resources.email_events import EmailEvents as EmailEvents
@@ -1,6 +1,6 @@
1
1
  import pingen2sdk
2
2
 
3
- from typing import Any, Mapping, Optional
3
+ from typing import Any, Mapping, Optional, Union
4
4
 
5
5
 
6
6
  class BatchEvents(object):
@@ -10,7 +10,7 @@ class BatchEvents(object):
10
10
  def __init__(
11
11
  self,
12
12
  organisation_id: str,
13
- access_token: str,
13
+ access_token: Union[str, "pingen2sdk.OAuth"],
14
14
  use_staging: bool = False,
15
15
  ):
16
16
  self.organisation_id = organisation_id
@@ -1,7 +1,7 @@
1
1
  import pingen2sdk
2
2
  import json
3
3
 
4
- from typing import Any, Mapping, Optional, List
4
+ from typing import Any, Dict, Mapping, Optional, List, Union
5
5
  from typing_extensions import Literal
6
6
 
7
7
 
@@ -9,7 +9,7 @@ class Batches(object):
9
9
  def __init__(
10
10
  self,
11
11
  organisation_id: str,
12
- access_token: str,
12
+ access_token: Union[str, "pingen2sdk.OAuth"],
13
13
  use_staging: bool = False,
14
14
  ):
15
15
  self.organisation_id = organisation_id
@@ -69,6 +69,7 @@ class Batches(object):
69
69
  grouping_options_split_position: Optional[
70
70
  Literal["first_page", "last_page"]
71
71
  ] = None,
72
+ channel_type: Optional[Literal["post", "email", "ebill"]] = None,
72
73
  ) -> pingen2sdk.PingenResponse:
73
74
  file_upload = pingen2sdk.FileUpload(self.api_requestor)
74
75
  file_url, file_url_signature = file_upload.request_file_upload()
@@ -86,6 +87,7 @@ class Batches(object):
86
87
  grouping_options_split_size,
87
88
  grouping_options_split_separator,
88
89
  grouping_options_split_position,
90
+ channel_type,
89
91
  )
90
92
 
91
93
  def create(
@@ -120,8 +122,14 @@ class Batches(object):
120
122
  grouping_options_split_position: Optional[
121
123
  Literal["first_page", "last_page"]
122
124
  ] = None,
125
+ channel_type: Optional[Literal["post", "email", "ebill"]] = None,
123
126
  ) -> pingen2sdk.PingenResponse:
124
- attributes = {
127
+ """Create a batch from an uploaded file.
128
+
129
+ ``grouping_options_split_position`` is required by the API when
130
+ ``grouping_options_split_type`` is ``custom`` or ``qr_invoice``.
131
+ """
132
+ attributes: Dict[str, Any] = {
125
133
  "file_url": file_url,
126
134
  "file_url_signature": file_url_signature,
127
135
  "name": name,
@@ -132,6 +140,9 @@ class Batches(object):
132
140
  "grouping_options_split_type": grouping_options_split_type,
133
141
  }
134
142
 
143
+ if channel_type is not None:
144
+ attributes["channel_type"] = channel_type
145
+
135
146
  if grouping_options_split_size is not None:
136
147
  attributes["grouping_options_split_size"] = grouping_options_split_size
137
148
 
@@ -153,22 +164,87 @@ class Batches(object):
153
164
  def send(
154
165
  self,
155
166
  batch_id: str,
156
- delivery_product: Mapping[str, str],
157
- print_mode: str,
158
- print_spectrum: str,
167
+ channel_type: Literal["post", "email", "ebill"] = "post",
168
+ delivery_product: Optional[str] = None,
169
+ print_mode: Optional[str] = None,
170
+ print_spectrum: Optional[str] = None,
159
171
  ) -> pingen2sdk.PingenResponse:
172
+ """Submit a batch for delivery.
173
+
174
+ The request payload depends on the batch ``channel_type``:
175
+
176
+ * ``post`` – requires ``delivery_product``
177
+ (``fast`` / ``cheap`` / ``bulk`` / ``premium`` / ``registered``),
178
+ ``print_mode`` (``simplex`` / ``duplex``) and
179
+ ``print_spectrum`` (``color`` / ``grayscale``).
180
+ * ``email`` – ``delivery_product`` defaults to ``electronic_email``.
181
+ * ``ebill`` – ``delivery_product`` defaults to ``electronic_ebill``.
182
+ """
183
+ attributes: Dict[str, Any] = {}
184
+
185
+ if channel_type == "email":
186
+ attributes["delivery_product"] = delivery_product or "electronic_email"
187
+ elif channel_type == "ebill":
188
+ attributes["delivery_product"] = delivery_product or "electronic_ebill"
189
+ else:
190
+ attributes["delivery_product"] = delivery_product
191
+ attributes["print_mode"] = print_mode
192
+ attributes["print_spectrum"] = print_spectrum
193
+
160
194
  return self.api_requestor.perform_patch_request(
161
195
  "/organisations/%s/batches/%s/send" % (self.organisation_id, batch_id),
196
+ json.dumps(
197
+ {
198
+ "data": {
199
+ "id": batch_id,
200
+ "type": "batches_channel_%s_send" % channel_type,
201
+ "attributes": attributes,
202
+ }
203
+ }
204
+ ),
205
+ )
206
+
207
+ def update(
208
+ self,
209
+ batch_id: str,
210
+ name: Optional[str] = None,
211
+ icon: Optional[
212
+ Literal[
213
+ "campaign",
214
+ "megaphone",
215
+ "wave-hand",
216
+ "flash",
217
+ "rocket",
218
+ "bell",
219
+ "percent-tag",
220
+ "percent-badge",
221
+ "present",
222
+ "receipt",
223
+ "document",
224
+ "information",
225
+ "calendar",
226
+ "newspaper",
227
+ "crown",
228
+ "virus",
229
+ ]
230
+ ] = None,
231
+ ) -> pingen2sdk.PingenResponse:
232
+ attributes: Dict[str, Any] = {}
233
+
234
+ if name is not None:
235
+ attributes["name"] = name
236
+
237
+ if icon is not None:
238
+ attributes["icon"] = icon
239
+
240
+ return self.api_requestor.perform_patch_request(
241
+ "/organisations/%s/batches/%s" % (self.organisation_id, batch_id),
162
242
  json.dumps(
163
243
  {
164
244
  "data": {
165
245
  "id": batch_id,
166
246
  "type": "batches",
167
- "attributes": {
168
- "delivery_products": delivery_product,
169
- "print_mode": print_mode,
170
- "print_spectrum": print_spectrum,
171
- },
247
+ "attributes": attributes,
172
248
  }
173
249
  }
174
250
  ),
@@ -185,9 +261,27 @@ class Batches(object):
185
261
  def delete(
186
262
  self,
187
263
  batch_id: str,
264
+ with_deliverables: bool = True,
188
265
  ) -> pingen2sdk.PingenResponse:
266
+ """Delete a batch.
267
+
268
+ ``with_deliverables`` controls whether the deliverables contained in the
269
+ batch are deleted as well (``True``) or kept as individual deliverables
270
+ (``False``).
271
+ """
189
272
  return self.api_requestor.perform_delete_request(
190
273
  "/organisations/%s/batches/%s" % (self.organisation_id, batch_id),
274
+ json.dumps(
275
+ {
276
+ "data": {
277
+ "type": "batches",
278
+ "id": batch_id,
279
+ "attributes": {
280
+ "with_deliverables": with_deliverables,
281
+ },
282
+ }
283
+ }
284
+ ),
191
285
  )
192
286
 
193
287
  def edit(
@@ -0,0 +1,30 @@
1
+ import pingen2sdk
2
+
3
+ from typing import Any, Mapping, Optional, Union
4
+
5
+
6
+ class EbillEvents(object):
7
+ organisation_id: str
8
+ api_requestor: pingen2sdk.APIRequestor
9
+
10
+ def __init__(
11
+ self,
12
+ organisation_id: str,
13
+ access_token: Union[str, "pingen2sdk.OAuth"],
14
+ use_staging: bool = False,
15
+ ):
16
+ self.organisation_id = organisation_id
17
+ self.api_requestor = pingen2sdk.APIRequestor(access_token, use_staging)
18
+
19
+ def get_collection(
20
+ self,
21
+ ebill_id: str,
22
+ params: Optional[Mapping[str, Any]] = None,
23
+ supplied_headers: Optional[Mapping[str, str]] = None,
24
+ ) -> pingen2sdk.PingenResponse:
25
+ return self.api_requestor.perform_get_request(
26
+ "/organisations/%s/deliveries/ebills/%s/events"
27
+ % (self.organisation_id, ebill_id),
28
+ params,
29
+ supplied_headers,
30
+ )
@@ -1,14 +1,15 @@
1
1
  import pingen2sdk
2
2
  import json
3
3
 
4
- from typing import Any, Mapping, Optional, Dict
4
+ from io import IOBase
5
+ from typing import Any, Mapping, Optional, Dict, Union
5
6
 
6
7
 
7
8
  class Ebills(object):
8
9
  def __init__(
9
10
  self,
10
11
  organisation_id: str,
11
- access_token: str,
12
+ access_token: Union[str, "pingen2sdk.OAuth"],
12
13
  use_staging: bool = False,
13
14
  ):
14
15
  self.organisation_id = organisation_id
@@ -91,3 +92,46 @@ class Ebills(object):
91
92
  "/organisations/%s/deliveries/ebills" % self.organisation_id,
92
93
  json.dumps(payload),
93
94
  )
95
+
96
+ def send(
97
+ self,
98
+ ebill_id: str,
99
+ ) -> pingen2sdk.PingenResponse:
100
+ return self.api_requestor.perform_patch_request(
101
+ "/organisations/%s/deliveries/ebills/%s/send"
102
+ % (self.organisation_id, ebill_id),
103
+ json.dumps(
104
+ {
105
+ "data": {
106
+ "id": ebill_id,
107
+ "type": "ebills",
108
+ }
109
+ }
110
+ ),
111
+ )
112
+
113
+ def cancel(
114
+ self,
115
+ ebill_id: str,
116
+ ) -> pingen2sdk.PingenResponse:
117
+ return self.api_requestor.perform_cancel_request(
118
+ "/organisations/%s/deliveries/ebills/%s/cancel"
119
+ % (self.organisation_id, ebill_id),
120
+ )
121
+
122
+ def delete(
123
+ self,
124
+ ebill_id: str,
125
+ ) -> pingen2sdk.PingenResponse:
126
+ return self.api_requestor.perform_delete_request(
127
+ "/organisations/%s/deliveries/ebills/%s" % (self.organisation_id, ebill_id),
128
+ )
129
+
130
+ def get_file(
131
+ self,
132
+ ebill_id: str,
133
+ ) -> IOBase:
134
+ return self.api_requestor.perform_stream_request(
135
+ "/organisations/%s/deliveries/ebills/%s/file"
136
+ % (self.organisation_id, ebill_id),
137
+ )
@@ -0,0 +1,30 @@
1
+ import pingen2sdk
2
+
3
+ from typing import Any, Mapping, Optional, Union
4
+
5
+
6
+ class EmailEvents(object):
7
+ organisation_id: str
8
+ api_requestor: pingen2sdk.APIRequestor
9
+
10
+ def __init__(
11
+ self,
12
+ organisation_id: str,
13
+ access_token: Union[str, "pingen2sdk.OAuth"],
14
+ use_staging: bool = False,
15
+ ):
16
+ self.organisation_id = organisation_id
17
+ self.api_requestor = pingen2sdk.APIRequestor(access_token, use_staging)
18
+
19
+ def get_collection(
20
+ self,
21
+ email_id: str,
22
+ params: Optional[Mapping[str, Any]] = None,
23
+ supplied_headers: Optional[Mapping[str, str]] = None,
24
+ ) -> pingen2sdk.PingenResponse:
25
+ return self.api_requestor.perform_get_request(
26
+ "/organisations/%s/deliveries/emails/%s/events"
27
+ % (self.organisation_id, email_id),
28
+ params,
29
+ supplied_headers,
30
+ )