pingen2sdk 0.2.0__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 (38) hide show
  1. pingen2sdk-0.2.0/.coveragerc +4 -0
  2. pingen2sdk-0.2.0/LICENSE +24 -0
  3. pingen2sdk-0.2.0/MANIFEST.in +2 -0
  4. pingen2sdk-0.2.0/PKG-INFO +126 -0
  5. pingen2sdk-0.2.0/README.md +99 -0
  6. pingen2sdk-0.2.0/pingen2sdk/__init__.py +28 -0
  7. pingen2sdk-0.2.0/pingen2sdk/api.py +146 -0
  8. pingen2sdk-0.2.0/pingen2sdk/api_resources/__init__.py +11 -0
  9. pingen2sdk-0.2.0/pingen2sdk/api_resources/batch_events.py +29 -0
  10. pingen2sdk-0.2.0/pingen2sdk/api_resources/batches.py +219 -0
  11. pingen2sdk-0.2.0/pingen2sdk/api_resources/file_upload.py +31 -0
  12. pingen2sdk-0.2.0/pingen2sdk/api_resources/letter_events.py +40 -0
  13. pingen2sdk-0.2.0/pingen2sdk/api_resources/letters.py +204 -0
  14. pingen2sdk-0.2.0/pingen2sdk/api_resources/organisations.py +37 -0
  15. pingen2sdk-0.2.0/pingen2sdk/api_resources/user_associations.py +25 -0
  16. pingen2sdk-0.2.0/pingen2sdk/api_resources/users.py +25 -0
  17. pingen2sdk-0.2.0/pingen2sdk/error.py +33 -0
  18. pingen2sdk-0.2.0/pingen2sdk/oauth.py +82 -0
  19. pingen2sdk-0.2.0/pingen2sdk/response.py +23 -0
  20. pingen2sdk-0.2.0/pingen2sdk.egg-info/PKG-INFO +126 -0
  21. pingen2sdk-0.2.0/pingen2sdk.egg-info/SOURCES.txt +36 -0
  22. pingen2sdk-0.2.0/pingen2sdk.egg-info/dependency_links.txt +1 -0
  23. pingen2sdk-0.2.0/pingen2sdk.egg-info/requires.txt +3 -0
  24. pingen2sdk-0.2.0/pingen2sdk.egg-info/top_level.txt +1 -0
  25. pingen2sdk-0.2.0/pyproject.toml +33 -0
  26. pingen2sdk-0.2.0/setup.cfg +4 -0
  27. pingen2sdk-0.2.0/tests/__init__.py +0 -0
  28. pingen2sdk-0.2.0/tests/api_resources/__init__.py +0 -0
  29. pingen2sdk-0.2.0/tests/api_resources/test_batch_events.py +62 -0
  30. pingen2sdk-0.2.0/tests/api_resources/test_batches.py +437 -0
  31. pingen2sdk-0.2.0/tests/api_resources/test_file_upload.py +46 -0
  32. pingen2sdk-0.2.0/tests/api_resources/test_letter_events.py +86 -0
  33. pingen2sdk-0.2.0/tests/api_resources/test_letters.py +539 -0
  34. pingen2sdk-0.2.0/tests/api_resources/test_organisations.py +139 -0
  35. pingen2sdk-0.2.0/tests/api_resources/test_user_accociations.py +78 -0
  36. pingen2sdk-0.2.0/tests/api_resources/test_users.py +72 -0
  37. pingen2sdk-0.2.0/tests/test_oauth.py +103 -0
  38. pingen2sdk-0.2.0/tox.ini +32 -0
@@ -0,0 +1,4 @@
1
+ [run]
2
+ branch = true
3
+ parallel = true
4
+ source = pingen2sdk
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2023, Pingen GmbH
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of the <organization> nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,2 @@
1
+ include .coveragerc LICENSE DESCRIPTION.rst README.md tox.ini
2
+ recursive-include tests *.py
@@ -0,0 +1,126 @@
1
+ Metadata-Version: 2.1
2
+ Name: pingen2sdk
3
+ Version: 0.2.0
4
+ Summary: Official Python Pingen SDK for API V2
5
+ Author-email: Pingen GmbH <info@pingen.com>
6
+ License: BSD-3-Clause
7
+ Project-URL: Homepage, https://github.com/pingencom/pingen2-sdk-python
8
+ Project-URL: Bug Tracker, https://github.com/pingencom/pingen2-sdk-python/issues
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Natural Language :: English
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Python: >=3.8
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: requests>=2.31.0
25
+ Requires-Dist: typing-extensions
26
+ Requires-Dist: response
27
+
28
+ # Requirements
29
+
30
+ You need to have an account in pingen and obtain oauth credentials for your desired grant type (usually client_credentials).
31
+
32
+ How to obtain these are described here: https://api.pingen.com/documentation#section/Authentication/How-to-obtain-a-Client-ID
33
+
34
+ Python 3.8+
35
+
36
+ # Installation
37
+
38
+ You don't need this source code unless you want to modify the package. If you just want to use the package, just run:
39
+
40
+ ```sh
41
+ pip install --upgrade pingen2sdk
42
+ ```
43
+
44
+ # Environments
45
+
46
+ We have two Environments available: Production and Staging (see https://api.pingen.com/documentation#section/Basics/Environments)
47
+
48
+ This SDK supports staging as well. **When initiating the resource** (see Usage), the optional 'staging' attribute should be set, **as well as when creating an endpoint object**.
49
+
50
+ # Usage
51
+
52
+ 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)
53
+
54
+ ```python
55
+ import pingen2sdk
56
+
57
+ pingen2sdk.client_id = "YOUR_CLIENT_ID"
58
+ pingen2sdk.client_secret = "YOU_SECRET"
59
+
60
+ resp = pingen2sdk.OAuth.get_token(
61
+ use_staging=True,
62
+ grant_type="client_credentials",
63
+ scope="letter batch webhook organisation_read",
64
+ )
65
+
66
+ access_token = resp["access_token"]
67
+
68
+ organisationList = pingen2sdk.Organisations(access_token, True).get_collection()
69
+
70
+ organisation_id = organisationList.data["data"][0]["id"]
71
+
72
+ LettersEndpoint = pingen2sdk.Letters(organisation_id, access_token, True)
73
+
74
+ response = LettersEndpoint.upload_and_create_letter(
75
+ "./letter.pdf",
76
+ "sdk.pdf",
77
+ "left",
78
+ False,
79
+ "fast",
80
+ "simplex",
81
+ "color",
82
+ )
83
+
84
+ letter_id = response.data["data"]["id"]
85
+ ```
86
+
87
+ # Examples & Docs
88
+
89
+ Our API Docs are here: https://api.pingen.com/documentation
90
+
91
+ On the right-hand side of every endpoint you can see request samples for Python and other languages, which you can copy and paste into your application.
92
+
93
+ # Bugreport & Contribution
94
+
95
+ If you find a bug, please either create a ticket in github, or initiate a pull request.
96
+
97
+ # Versioning
98
+
99
+ We adhere to semantic (major.minor.patch) versioning (https://semver.org/). This means that:
100
+ * Patch (x.x.patch) versions fix bugs
101
+ * Minor (x.minor.x) versions introduce new, backwards compatible features or improve existing code.
102
+ * Major (major.x.x) versions introduce radical changes which are not backwards compatible.
103
+
104
+ In your automation or procedure you can always safely update patch & minor versions without the risk of your application failing.
105
+
106
+ # Testing
107
+
108
+ Run all tests for a specific Python version (modify `-e` according to your Python target):
109
+
110
+ ```sh
111
+ tox -e py312
112
+ ```
113
+
114
+ Run the linter with:
115
+
116
+ ```sh
117
+ tox -e lint
118
+ ```
119
+
120
+ The library uses Black for code formatting. Code must be formatted
121
+ with Black before PRs are submitted, otherwise CI will fail. Run the formatter
122
+ with:
123
+
124
+ ```sh
125
+ tox -e fmt
126
+ ```
@@ -0,0 +1,99 @@
1
+ # Requirements
2
+
3
+ You need to have an account in pingen and obtain oauth credentials for your desired grant type (usually client_credentials).
4
+
5
+ How to obtain these are described here: https://api.pingen.com/documentation#section/Authentication/How-to-obtain-a-Client-ID
6
+
7
+ Python 3.8+
8
+
9
+ # Installation
10
+
11
+ You don't need this source code unless you want to modify the package. If you just want to use the package, just run:
12
+
13
+ ```sh
14
+ pip install --upgrade pingen2sdk
15
+ ```
16
+
17
+ # Environments
18
+
19
+ We have two Environments available: Production and Staging (see https://api.pingen.com/documentation#section/Basics/Environments)
20
+
21
+ This SDK supports staging as well. **When initiating the resource** (see Usage), the optional 'staging' attribute should be set, **as well as when creating an endpoint object**.
22
+
23
+ # Usage
24
+
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
+
27
+ ```python
28
+ import pingen2sdk
29
+
30
+ pingen2sdk.client_id = "YOUR_CLIENT_ID"
31
+ pingen2sdk.client_secret = "YOU_SECRET"
32
+
33
+ resp = pingen2sdk.OAuth.get_token(
34
+ use_staging=True,
35
+ grant_type="client_credentials",
36
+ scope="letter batch webhook organisation_read",
37
+ )
38
+
39
+ access_token = resp["access_token"]
40
+
41
+ organisationList = pingen2sdk.Organisations(access_token, True).get_collection()
42
+
43
+ organisation_id = organisationList.data["data"][0]["id"]
44
+
45
+ LettersEndpoint = pingen2sdk.Letters(organisation_id, access_token, True)
46
+
47
+ response = LettersEndpoint.upload_and_create_letter(
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
+ # Examples & Docs
61
+
62
+ Our API Docs are here: https://api.pingen.com/documentation
63
+
64
+ On the right-hand side of every endpoint you can see request samples for Python and other languages, which you can copy and paste into your application.
65
+
66
+ # Bugreport & Contribution
67
+
68
+ If you find a bug, please either create a ticket in github, or initiate a pull request.
69
+
70
+ # Versioning
71
+
72
+ We adhere to semantic (major.minor.patch) versioning (https://semver.org/). This means that:
73
+ * Patch (x.x.patch) versions fix bugs
74
+ * Minor (x.minor.x) versions introduce new, backwards compatible features or improve existing code.
75
+ * Major (major.x.x) versions introduce radical changes which are not backwards compatible.
76
+
77
+ In your automation or procedure you can always safely update patch & minor versions without the risk of your application failing.
78
+
79
+ # Testing
80
+
81
+ Run all tests for a specific Python version (modify `-e` according to your Python target):
82
+
83
+ ```sh
84
+ tox -e py312
85
+ ```
86
+
87
+ Run the linter with:
88
+
89
+ ```sh
90
+ tox -e lint
91
+ ```
92
+
93
+ The library uses Black for code formatting. Code must be formatted
94
+ with Black before PRs are submitted, otherwise CI will fail. Run the formatter
95
+ with:
96
+
97
+ ```sh
98
+ tox -e fmt
99
+ ```
@@ -0,0 +1,28 @@
1
+ # flake8: noqa
2
+ from typing import Optional
3
+
4
+ import os
5
+
6
+ api_key: Optional[str] = None
7
+ client_id: Optional[str] = None
8
+ client_secret: Optional[str] = None
9
+ api_production: str = "https://api.pingen.com"
10
+ auth_production: str = "https://identity.pingen.com"
11
+ api_staging: str = "https://api-staging.pingen.com"
12
+ auth_staging: str = "https://identity-staging.pingen.com"
13
+ request_timeout: int = 20
14
+
15
+ # OAuth
16
+ from pingen2sdk.oauth import OAuth
17
+
18
+ # PingenResponse
19
+ from pingen2sdk.response import PingenResponse
20
+
21
+ # PingenError
22
+ from pingen2sdk.error import PingenError
23
+
24
+ # APIRequestor
25
+ from pingen2sdk.api import APIRequestor
26
+
27
+ # API Resources
28
+ from pingen2sdk.api_resources import *
@@ -0,0 +1,146 @@
1
+ import requests
2
+ import pingen2sdk
3
+
4
+ from io import IOBase, BytesIO
5
+ from typing import Any, Dict, Mapping, Optional, cast
6
+ from requests.models import PreparedRequest
7
+
8
+
9
+ def _response_interpreter(
10
+ body: Dict,
11
+ status_code: int,
12
+ headers: Mapping[str, str],
13
+ ) -> pingen2sdk.PingenResponse:
14
+ if 200 <= status_code < 310:
15
+ return pingen2sdk.PingenResponse(body, status_code, headers)
16
+ else:
17
+ raise pingen2sdk.PingenError(None, body, status_code, headers)
18
+
19
+
20
+ class APIRequestor(object):
21
+ access_token: str
22
+ api_base: str
23
+ user_agent: str = "PINGEN.SDK.PYTHON"
24
+
25
+ def __init__(self, access_token: str, use_staging: Optional[bool] = False):
26
+ if use_staging is False:
27
+ self.api_base = pingen2sdk.api_production
28
+ else:
29
+ self.api_base = pingen2sdk.api_staging
30
+
31
+ self.access_token = access_token
32
+
33
+ def perform_get_request(
34
+ self,
35
+ url: str,
36
+ params: Optional[Mapping[str, Any]] = None,
37
+ supplied_headers: Optional[Mapping[str, str]] = None,
38
+ ) -> pingen2sdk.PingenResponse:
39
+ r = requests.get(
40
+ self.prepare_path(url, params),
41
+ headers=self.request_headers(supplied_headers),
42
+ timeout=pingen2sdk.request_timeout,
43
+ )
44
+
45
+ return _response_interpreter(r.text, r.status_code, r.headers)
46
+
47
+ @staticmethod
48
+ def perform_put_request(
49
+ url: str,
50
+ file: BytesIO,
51
+ ):
52
+ requests.put(url, data=file)
53
+
54
+ def perform_post_request(
55
+ self,
56
+ url: str,
57
+ payload: str,
58
+ supplied_headers: Optional[Mapping[str, str]] = None,
59
+ ) -> pingen2sdk.PingenResponse:
60
+ r = requests.post(
61
+ self.prepare_path(url),
62
+ payload,
63
+ headers=self.request_headers(supplied_headers),
64
+ timeout=pingen2sdk.request_timeout,
65
+ )
66
+
67
+ return _response_interpreter(r.text, r.status_code, r.headers)
68
+
69
+ def perform_patch_request(
70
+ self,
71
+ url: str,
72
+ payload: str,
73
+ supplied_headers: Optional[Mapping[str, str]] = None,
74
+ ) -> pingen2sdk.PingenResponse:
75
+ r = requests.patch(
76
+ self.prepare_path(url),
77
+ payload,
78
+ headers=self.request_headers(supplied_headers),
79
+ timeout=pingen2sdk.request_timeout,
80
+ )
81
+
82
+ return _response_interpreter(r.text, r.status_code, r.headers)
83
+
84
+ def perform_cancel_request(self, url: str) -> pingen2sdk.PingenResponse:
85
+ r = requests.patch(
86
+ self.prepare_path(url),
87
+ headers=self.request_headers(),
88
+ timeout=pingen2sdk.request_timeout,
89
+ )
90
+
91
+ return _response_interpreter(r.text, r.status_code, r.headers)
92
+
93
+ def perform_delete_request(self, url: str) -> pingen2sdk.PingenResponse:
94
+ r = requests.delete(
95
+ self.prepare_path(url),
96
+ headers=self.request_headers(),
97
+ timeout=pingen2sdk.request_timeout,
98
+ )
99
+
100
+ return _response_interpreter(r.text, r.status_code, r.headers)
101
+
102
+ def perform_stream_request(
103
+ self,
104
+ url: str,
105
+ ) -> IOBase:
106
+ response = requests.get(
107
+ self.prepare_path(url),
108
+ headers=self.request_headers(),
109
+ timeout=pingen2sdk.request_timeout,
110
+ stream=True,
111
+ )
112
+
113
+ return cast(IOBase, response.text)
114
+
115
+ def prepare_path(
116
+ self,
117
+ url: str,
118
+ params: Optional[Mapping[str, Any]] = None,
119
+ ) -> str:
120
+ path = "%s%s" % (self.api_base, url)
121
+
122
+ request = PreparedRequest()
123
+ request.prepare_url(path, params)
124
+
125
+ return request.url
126
+
127
+ def request_headers(
128
+ self,
129
+ supplied_headers: Optional[Mapping[str, str]] = None,
130
+ ) -> Mapping[str, str]:
131
+ supplied_headers_dict: Optional[Dict[str, str]] = (
132
+ dict(supplied_headers) if supplied_headers is not None else None
133
+ )
134
+
135
+ headers = {
136
+ "User-Agent": self.user_agent,
137
+ "Authorization": "Bearer {}".format(self.access_token),
138
+ "Content-Type": "application/vnd.api+json",
139
+ "Accept": "application/vnd.api+json",
140
+ }
141
+
142
+ if supplied_headers_dict is not None:
143
+ for key, value in supplied_headers_dict.items():
144
+ headers[key] = value
145
+
146
+ return headers
@@ -0,0 +1,11 @@
1
+ # flake8: noqa
2
+ from pingen2sdk.api_resources.letters import Letters as Letters
3
+ from pingen2sdk.api_resources.file_upload import FileUpload as FileUpload
4
+ from pingen2sdk.api_resources.letter_events import LetterEvents as LetterEvents
5
+ from pingen2sdk.api_resources.users import Users as Users
6
+ from pingen2sdk.api_resources.user_associations import (
7
+ UserAssociations as UserAssociations,
8
+ )
9
+ from pingen2sdk.api_resources.organisations import Organisations as Organisations
10
+ from pingen2sdk.api_resources.batches import Batches as Batches
11
+ from pingen2sdk.api_resources.batch_events import BatchEvents as BatchEvents
@@ -0,0 +1,29 @@
1
+ import pingen2sdk
2
+
3
+ from typing import Any, Mapping, Optional
4
+
5
+
6
+ class BatchEvents(object):
7
+ organisation_id: str
8
+ api_requestor: pingen2sdk.APIRequestor
9
+
10
+ def __init__(
11
+ self,
12
+ organisation_id: str,
13
+ access_token: str,
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
+ batch_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/batches/%s/events" % (self.organisation_id, batch_id),
27
+ params,
28
+ supplied_headers,
29
+ )
@@ -0,0 +1,219 @@
1
+ import pingen2sdk
2
+ import json
3
+
4
+ from typing import Any, Mapping, Optional, List
5
+ from typing_extensions import Literal
6
+
7
+
8
+ class Batches(object):
9
+ def __init__(
10
+ self,
11
+ organisation_id: str,
12
+ access_token: str,
13
+ use_staging: bool = False,
14
+ ):
15
+ self.organisation_id = organisation_id
16
+ self.api_requestor = pingen2sdk.APIRequestor(access_token, use_staging)
17
+
18
+ def get_details(
19
+ self,
20
+ batch_id: str,
21
+ params: Optional[Mapping[str, Any]] = None,
22
+ supplied_headers: Optional[Mapping[str, str]] = None,
23
+ ) -> pingen2sdk.PingenResponse:
24
+ return self.api_requestor.perform_get_request(
25
+ "/organisations/%s/batches/%s" % (self.organisation_id, batch_id),
26
+ params,
27
+ supplied_headers,
28
+ )
29
+
30
+ def get_collection(
31
+ self,
32
+ params: Optional[Mapping[str, Any]] = None,
33
+ supplied_headers: Optional[Mapping[str, str]] = None,
34
+ ) -> pingen2sdk.PingenResponse:
35
+ return self.api_requestor.perform_get_request(
36
+ "/organisations/%s/batches" % self.organisation_id,
37
+ params,
38
+ supplied_headers,
39
+ )
40
+
41
+ def upload_and_create_batch(
42
+ self,
43
+ path_to_file: str,
44
+ name: str,
45
+ icon: Literal[
46
+ "campaign",
47
+ "megaphone",
48
+ "wave-hand",
49
+ "flash",
50
+ "rocket",
51
+ "bell",
52
+ "percent-tag",
53
+ "percent-badge",
54
+ "present",
55
+ "receipt",
56
+ "document",
57
+ "information",
58
+ "calendar",
59
+ "newspaper",
60
+ "crown",
61
+ "virus",
62
+ ],
63
+ file_original_name: str,
64
+ address_position: Literal["left", "right"],
65
+ grouping_type: Literal["zip", "merge"],
66
+ grouping_options_split_type: Literal["file", "page", "custom", "qr_invoice"],
67
+ grouping_options_split_size: Optional[int] = None,
68
+ grouping_options_split_separator: Optional[str] = None,
69
+ grouping_options_split_position: Optional[
70
+ Literal["first_page", "last_page"]
71
+ ] = None,
72
+ ) -> pingen2sdk.PingenResponse:
73
+ file_upload = pingen2sdk.FileUpload(self.api_requestor)
74
+ file_url, file_url_signature = file_upload.request_file_upload()
75
+ file_upload.put_file(path_to_file, file_url)
76
+
77
+ return self.create_batch(
78
+ file_url,
79
+ file_url_signature,
80
+ name,
81
+ icon,
82
+ file_original_name,
83
+ address_position,
84
+ grouping_type,
85
+ grouping_options_split_type,
86
+ grouping_options_split_size,
87
+ grouping_options_split_separator,
88
+ grouping_options_split_position,
89
+ )
90
+
91
+ def create_batch(
92
+ self,
93
+ file_url: str,
94
+ file_url_signature: str,
95
+ name: str,
96
+ icon: Literal[
97
+ "campaign",
98
+ "megaphone",
99
+ "wave-hand",
100
+ "flash",
101
+ "rocket",
102
+ "bell",
103
+ "percent-tag",
104
+ "percent-badge",
105
+ "present",
106
+ "receipt",
107
+ "document",
108
+ "information",
109
+ "calendar",
110
+ "newspaper",
111
+ "crown",
112
+ "virus",
113
+ ],
114
+ file_original_name: str,
115
+ address_position: Literal["left", "right"],
116
+ grouping_type: Literal["zip", "merge"],
117
+ grouping_options_split_type: Literal["file", "page", "custom", "qr_invoice"],
118
+ grouping_options_split_size: Optional[int] = None,
119
+ grouping_options_split_separator: Optional[str] = None,
120
+ grouping_options_split_position: Optional[
121
+ Literal["first_page", "last_page"]
122
+ ] = None,
123
+ ) -> pingen2sdk.PingenResponse:
124
+ attributes = {
125
+ "file_url": file_url,
126
+ "file_url_signature": file_url_signature,
127
+ "name": name,
128
+ "icon": icon,
129
+ "file_original_name": file_original_name,
130
+ "address_position": address_position,
131
+ "grouping_type": grouping_type,
132
+ "grouping_options_split_type": grouping_options_split_type,
133
+ }
134
+
135
+ if grouping_options_split_size is not None:
136
+ attributes["grouping_options_split_size"] = grouping_options_split_size
137
+
138
+ if grouping_options_split_separator is not None:
139
+ attributes[
140
+ "grouping_options_split_separator"
141
+ ] = grouping_options_split_separator
142
+
143
+ if grouping_options_split_position is not None:
144
+ attributes[
145
+ "grouping_options_split_position"
146
+ ] = grouping_options_split_position
147
+
148
+ return self.api_requestor.perform_post_request(
149
+ "/organisations/%s/batches" % self.organisation_id,
150
+ json.dumps({"data": {"type": "batches", "attributes": attributes}}),
151
+ )
152
+
153
+ def send_batch(
154
+ self,
155
+ batch_id: str,
156
+ delivery_product: Mapping[str, str],
157
+ print_mode: str,
158
+ print_spectrum: str,
159
+ ) -> pingen2sdk.PingenResponse:
160
+ return self.api_requestor.perform_patch_request(
161
+ "/organisations/%s/batches/%s/send" % (self.organisation_id, batch_id),
162
+ json.dumps(
163
+ {
164
+ "data": {
165
+ "id": batch_id,
166
+ "type": "batches",
167
+ "attributes": {
168
+ "delivery_products": delivery_product,
169
+ "print_mode": print_mode,
170
+ "print_spectrum": print_spectrum,
171
+ },
172
+ }
173
+ }
174
+ ),
175
+ )
176
+
177
+ def cancel_batch(
178
+ self,
179
+ batch_id: str,
180
+ ) -> pingen2sdk.PingenResponse:
181
+ return self.api_requestor.perform_cancel_request(
182
+ "/organisations/%s/batches/%s/cancel" % (self.organisation_id, batch_id),
183
+ )
184
+
185
+ def delete_batch(
186
+ self,
187
+ batch_id: str,
188
+ ) -> pingen2sdk.PingenResponse:
189
+ return self.api_requestor.perform_delete_request(
190
+ "/organisations/%s/batches/%s" % (self.organisation_id, batch_id),
191
+ )
192
+
193
+ def edit_batch(
194
+ self,
195
+ batch_id: str,
196
+ paper_types: List[str],
197
+ ) -> pingen2sdk.PingenResponse:
198
+ return self.api_requestor.perform_patch_request(
199
+ "/organisations/%s/batches/%s" % (self.organisation_id, batch_id),
200
+ json.dumps(
201
+ {
202
+ "data": {
203
+ "id": batch_id,
204
+ "type": "batches",
205
+ "attributes": {
206
+ "paper_types": paper_types,
207
+ },
208
+ }
209
+ }
210
+ ),
211
+ )
212
+
213
+ def get_statistics(
214
+ self,
215
+ batch_id: str,
216
+ ) -> pingen2sdk.PingenResponse:
217
+ return self.api_requestor.perform_get_request(
218
+ "/organisations/%s/batches/%s/statistics" % (self.organisation_id, batch_id)
219
+ )