alfred-python 0.6.3__py3-none-any.whl → 0.6.4__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.
alfred/rest/jobs/v1.py CHANGED
@@ -1,5 +1,6 @@
1
1
  # Native imports
2
- from typing import Text
2
+ import json
3
+ from typing import Any, Dict, Text
3
4
 
4
5
  # Project imports
5
6
  from alfred.rest.jobs.typed import CreateJobDict
@@ -29,7 +30,7 @@ class Jobs(JobsBase):
29
30
  - job_id: Unique identifier of the Job.
30
31
  """
31
32
  parsed_resp, _ = self.http_client.get(f"/api/job/detail/{job_id}")
32
- return parsed_resp
33
+ return self.__normalize_job_response(parsed_resp)
33
34
 
34
35
  def get_all(self, page_size: int = None, current_page: int = None):
35
36
  """
@@ -45,4 +46,68 @@ class Jobs(JobsBase):
45
46
  if current_page:
46
47
  params["currentPage"] = current_page
47
48
  parsed_resp, _ = self.http_client.get("/api/job/all", params=params)
48
- return parsed_resp
49
+ return self.__normalize_job_response(parsed_resp)
50
+
51
+ def __normalize_job_response(self, payload: Any):
52
+ """
53
+ Normalize job payloads returned by job endpoints.
54
+
55
+ Supports direct job objects as well as wrapped responses where jobs
56
+ are returned under a `result` key.
57
+ """
58
+ if isinstance(payload, list):
59
+ return [self.__normalize_job(item) for item in payload]
60
+
61
+ if not isinstance(payload, dict):
62
+ return payload
63
+
64
+ response = dict(payload)
65
+ result = response.get("result")
66
+
67
+ if isinstance(result, list):
68
+ response["result"] = [self.__normalize_job(item) for item in result]
69
+ return response
70
+
71
+ if isinstance(result, dict):
72
+ response["result"] = self.__normalize_job(result)
73
+ return response
74
+
75
+ return self.__normalize_job(response)
76
+
77
+ def __normalize_job(self, job: Any):
78
+ """
79
+ Normalize a single job object and coerce its metadata to a dictionary.
80
+ """
81
+ if not isinstance(job, dict):
82
+ return job
83
+
84
+ normalized_job = dict(job)
85
+ normalized_job["metadata"] = self.__normalize_metadata(
86
+ normalized_job.get("metadata")
87
+ )
88
+ return normalized_job
89
+
90
+ @staticmethod
91
+ def __normalize_metadata(metadata: Any) -> Dict[str, Any]:
92
+ """
93
+ Convert upstream job metadata into a dictionary when possible.
94
+
95
+ Metadata may arrive as a JSON-encoded string, an already parsed
96
+ dictionary, or an empty/invalid value. Non-dictionary results are
97
+ normalized to an empty dictionary.
98
+ """
99
+ if isinstance(metadata, dict):
100
+ return metadata
101
+
102
+ if not metadata or not isinstance(metadata, str):
103
+ return {}
104
+
105
+ try:
106
+ parsed_metadata = json.loads(metadata)
107
+ except (TypeError, ValueError, json.JSONDecodeError):
108
+ return {}
109
+
110
+ if isinstance(parsed_metadata, dict):
111
+ return parsed_metadata
112
+
113
+ return {}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: alfred-python
3
- Version: 0.6.3
3
+ Version: 0.6.4
4
4
  Summary: Python library designed to simplify and streamline interactions with the Alfred API
5
5
  Author-email: Tagshelf LLC <support@tagshelf.com>
6
6
  License: Copyright (c) 2018 The Python Packaging Authority
@@ -20,7 +20,7 @@ alfred/rest/files/v1.py,sha256=QYx23G9SLLihJQ1J4cIeDK03i-pS0oaSabqgmdnAdOc,2926
20
20
  alfred/rest/jobs/__init__.py,sha256=J4A3kCoeiVnhzso9rIEwYyhkmMXBmC7E6oJ_s-cQ_O8,383
21
21
  alfred/rest/jobs/base.py,sha256=016SM_9_BFms5Of2nWKa1jX-cT5HlbBdq15r2mHFb6Y,789
22
22
  alfred/rest/jobs/typed.py,sha256=w0t6LfZbyawad8Zz6bTywc-RrvuRIL7R2L4hRHTe3ew,429
23
- alfred/rest/jobs/v1.py,sha256=X_dowgRW6jErtSnCC3gIbGp8RMJTFgFMS32NNKarmzQ,1334
23
+ alfred/rest/jobs/v1.py,sha256=C7jU-Dcs4gMAXQQ1ahv42iwIKYubGPMH-p8eNivrOTY,3402
24
24
  alfred/rest/sessions/__init__.py,sha256=w3Q30swToFUOrlPn8q-PzGOiqCYGpoCiBv75Ae1j-tk,344
25
25
  alfred/rest/sessions/base.py,sha256=vVBMJVfd_LXBXGQ_udBUtclwK7Lf_Uck_8OPQngn7qU,410
26
26
  alfred/rest/sessions/v1.py,sha256=xcJEVKR9-mZeiAdQznIjp_Loz6JktzUnQmp2cBAnpbc,735
@@ -28,8 +28,8 @@ alfred/typings/__init__.py,sha256=F7iVP8Wv4FPfqlwFRR8M381Q55IYChCiTANYr1vgDDw,34
28
28
  alfred/typings/misc.py,sha256=m2i4ktYiX8U6Hx00os9b6hSP9k6t_Y7DdAppE8hFJCc,216
29
29
  alfred/utils/__init__.py,sha256=oCoKgEKGX2kefjKNrv5GgDaTY2JQRHXqr-VPeIC9u2Q,35
30
30
  alfred/utils/logging.py,sha256=7pcLpP-klfv1FhgMp1WIc8BKEHQlOhrj7qjGYYw31cc,2333
31
- alfred_python-0.6.3.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
32
- alfred_python-0.6.3.dist-info/METADATA,sha256=6vLR_uRjjQDMCHCAHEVQYjnrzODDuiIiJSq03jzlIDw,17845
33
- alfred_python-0.6.3.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
34
- alfred_python-0.6.3.dist-info/top_level.txt,sha256=ciQlts3Jwu5HdzhiQYDhjDGMoxlI9_CcqBEgc6PBE5U,7
35
- alfred_python-0.6.3.dist-info/RECORD,,
31
+ alfred_python-0.6.4.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
32
+ alfred_python-0.6.4.dist-info/METADATA,sha256=YkIhaj4Kox8qdfGmnwfVftPszP9oerSX6tngqPyBj4M,17845
33
+ alfred_python-0.6.4.dist-info/WHEEL,sha256=BNRMDyzLkkcmlv0J8ppDQkk2VED33SesJDynr9ED1gc,91
34
+ alfred_python-0.6.4.dist-info/top_level.txt,sha256=ciQlts3Jwu5HdzhiQYDhjDGMoxlI9_CcqBEgc6PBE5U,7
35
+ alfred_python-0.6.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.3.2)
2
+ Generator: setuptools (75.3.4)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5