Skip to content

Commit 67dfb41

Browse files
committed
Added functionality to the ApiContext to save and restore a context to and from JSON data
1 parent 356d5ca commit 67dfb41

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

bunq/sdk/context.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,30 +254,38 @@ def session_context(self):
254254

255255
return self._session_context
256256

257-
def save(self, path=None):
257+
def save(self, path=None, to_json=False):
258258
"""
259259
:type path: str
260+
:type to_json: bool
260261
261262
:rtype: None
262263
"""
263264

264265
if path is None:
265266
path = self._PATH_API_CONTEXT_DEFAULT
266267

268+
if to_json:
269+
return converter.class_to_json(self)
270+
267271
with open(path, self._FILE_MODE_WRITE) as file:
268272
file.write(converter.class_to_json(self))
269273

270274
@classmethod
271-
def restore(cls, path=None):
275+
def restore(cls, path=None, json_data=None):
272276
"""
273277
:type path: str
278+
:type json_data: str
274279
275280
:rtype: ApiContext
276281
"""
277282

278283
if path is None:
279284
path = cls._PATH_API_CONTEXT_DEFAULT
280285

286+
if json_data is not None:
287+
return converter.json_to_class(ApiContext, json_data)
288+
281289
with open(path, cls._FILE_MODE_READ) as file:
282290
return converter.json_to_class(ApiContext, file.read())
283291

0 commit comments

Comments
 (0)