Skip to content

Commit f34f210

Browse files
author
João Guerreiro
committed
feat(pygitguardian): add to_json and to_dict methods
1 parent fdb2105 commit f34f210

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ for name in glob.glob("**/*"):
8080
scan, status_code = client.multi_content_scan(to_scan)
8181
```
8282

83+
### Transform results to dict or JSON
84+
85+
Any model in `py-gitguardian` can be turned to a JSON string or a dictionary using
86+
the `to_dict` and `to_json` methods.
87+
88+
```py
89+
from pygitguardian.models import Detail
90+
91+
detail = Detail("Invalid API Key.")
92+
print(detail.to_dict())
93+
print(detail.to_json())
94+
```
95+
8396
### Dependencies
8497

8598
Py-gitguardian depends on these excellent libraries:

pygitguardian/__init__.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
11
"""PyGitGuardian API Client"""
22
from .client import GGClient
3-
from .models import (
4-
Detail,
5-
DetailSchema,
6-
DocumentSchema,
7-
Match,
8-
PolicyBreak,
9-
ScanResult,
10-
ScanResultSchema,
11-
)
123

134

145
__version__ = "1.0.3"
156
GGClient._version = __version__
167

178
__all__ = [
18-
"Detail",
19-
"DetailSchema",
20-
"DocumentSchema",
219
"GGClient",
22-
"Match",
23-
"PolicyBreak",
24-
"ScanResult",
25-
"ScanResultSchema",
2610
]

pygitguardian/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def __init__(
152152
index_end: Optional[int] = None,
153153
**kwargs
154154
):
155+
super().__init__()
155156
self.match = match
156157
self.match_type = match_type
157158
self.line_start = line_start
@@ -198,6 +199,7 @@ class PolicyBreak(Base):
198199
SCHEMA = PolicyBreakSchema()
199200

200201
def __init__(self, break_type: str, policy: str, matches: List[Match], **kwargs):
202+
super().__init__()
201203
self.break_type = break_type
202204
self.policy = policy
203205
self.matches = matches

0 commit comments

Comments
 (0)