Skip to content

Commit 48080dc

Browse files
committed
[Rest Client] Add helper method to get content
_get_response_content is to be used for chaining together response retrieval. This is useful in the case where you are querying the API and then immediately extracting some data from the response. This method is needed to account for the case where advanced mode is on and the initial get call returns a requests.Response rather than a dictionary.
1 parent e9520ab commit 48080dc

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

atlassian/rest_client.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,34 @@ def get(
362362
log.error(e)
363363
return response.text
364364

365+
def _get_response_content(
366+
self,
367+
*args,
368+
fields,
369+
**kwargs,
370+
):
371+
"""
372+
:param fields: list of tuples in the form (field_name, default value (optional)).
373+
Used for chaining dictionary value accession.
374+
E.g. [("field1", "default1"), ("field2", "default2"), ("field3", )]
375+
"""
376+
response = self.get(*args, **kwargs)
377+
if "advanced_mode" in kwargs:
378+
advanced_mode = kwargs["advanced_mode"]
379+
else:
380+
advanced_mode = self.advanced_mode
381+
382+
if not advanced_mode: # dict
383+
for field in fields:
384+
response = response.get(*field)
385+
else: # requests.Response
386+
first_field = fields[0]
387+
response = response.json().get(*first_field)
388+
for field in fields[1:]:
389+
response = response.get(*field)
390+
391+
return response
392+
365393
def post(
366394
self,
367395
path,

0 commit comments

Comments
 (0)