bapp-api-client 0.4.1__tar.gz → 0.4.3__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.
@@ -1,6 +1,6 @@
1
1
  # Changelog
2
2
 
3
- ## 0.4.1
3
+ ## 0.4.3
4
4
 
5
5
  - Initial release.
6
6
  - Authentication: Bearer (JWT/OAuth) and Token (API key).
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bapp-api-client
3
- Version: 0.4.1
3
+ Version: 0.4.3
4
4
  Summary: BAPP Auto API Client for Python
5
5
  Project-URL: Homepage, https://www.bapp.ro
6
6
  Project-URL: Repository, https://github.com/bapp-open/sdk-python
@@ -54,15 +54,19 @@ class BappApiClient:
54
54
  host="https://panel.bapp.ro/api",
55
55
  tenant=None,
56
56
  app="account",
57
+ user_agent=None,
57
58
  ):
58
59
  self.host = host.rstrip("/")
59
60
  self.tenant = tenant
60
61
  self.app = app
62
+ self.user_agent = user_agent
61
63
  self._session = requests.Session()
62
64
  if bearer:
63
65
  self._session.headers["Authorization"] = f"Bearer {bearer}"
64
66
  elif token:
65
67
  self._session.headers["Authorization"] = f"Token {token}"
68
+ if user_agent:
69
+ self._session.headers["User-Agent"] = user_agent
66
70
 
67
71
  # -- internals -----------------------------------------------------------
68
72
 
@@ -202,7 +206,8 @@ class BappApiClient:
202
206
  })
203
207
  return views
204
208
 
205
- def get_document_url(self, record, output="html", label=None, variation=None):
209
+ def get_document_url(self, record, output="html", label=None,
210
+ variation=None, download=False):
206
211
  """Build a document render/download URL from a record.
207
212
 
208
213
  Works with both ``public_view`` and ``view_token`` formats.
@@ -217,6 +222,11 @@ class BappApiClient:
217
222
  variation: Variation code for ``public_view`` entries that
218
223
  support variations (e.g. ``"v4"``). Falls back to the
219
224
  entry's ``default_variation`` when *None*.
225
+ download: When *True* the response is sent as an attachment
226
+ (``Content-Disposition: attachment``). For ``public_view``
227
+ this appends ``&download=true``; for legacy ``view_token``
228
+ with ``output="pdf"`` this selects ``pdf.download`` instead
229
+ of ``pdf.view``.
220
230
 
221
231
  Returns:
222
232
  URL string, or *None* if the record has no view tokens.
@@ -243,14 +253,21 @@ class BappApiClient:
243
253
  v = variation or view.get("default_variation")
244
254
  if v:
245
255
  url += f"&variation={v}"
256
+ if download:
257
+ url += "&download=true"
246
258
  return url
247
259
 
248
260
  # Legacy view_token
249
- actions = {"pdf": "pdf.download", "context": "pdf.context"}
250
- action = actions.get(output, "pdf.preview")
261
+ if output == "pdf":
262
+ action = "pdf.download" if download else "pdf.view"
263
+ elif output == "context":
264
+ action = "pdf.context"
265
+ else:
266
+ action = "pdf.preview"
251
267
  return f"{self.host}/documents/{action}?token={token}"
252
268
 
253
- def get_document_content(self, record, output="html", label=None, variation=None):
269
+ def get_document_content(self, record, output="html", label=None,
270
+ variation=None, download=False):
254
271
  """Fetch document content (PDF, HTML, JPG, etc.) as bytes.
255
272
 
256
273
  Builds the URL via :meth:`get_document_url` and fetches the raw
@@ -262,6 +279,8 @@ class BappApiClient:
262
279
  ``"context"``.
263
280
  label: Select a specific view by label.
264
281
  variation: Variation code for ``public_view`` entries.
282
+ download: When *True* the server sends the response as an
283
+ attachment.
265
284
 
266
285
  Returns:
267
286
  ``bytes`` content, or *None* if the record has no view tokens.
@@ -271,6 +290,7 @@ class BappApiClient:
271
290
  """
272
291
  url = self.get_document_url(
273
292
  record, output=output, label=label, variation=variation,
293
+ download=download,
274
294
  )
275
295
  if url is None:
276
296
  return None
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "bapp-api-client"
7
- version = "0.4.1"
7
+ version = "0.4.3"
8
8
  description = "BAPP Auto API Client for Python"
9
9
  requires-python = ">=3.9"
10
10
  license = "MIT"
File without changes