Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit f19c94af authored by silvari's avatar silvari
Browse files

Added new methods to leankit library and a check for the api limit when doing get requests

parent de0ced8d
Branches EDELIVERY-13982-upgrade-libraries-and-plugins
No related tags found
No related merge requests found
...@@ -145,6 +145,41 @@ def get_cards_by_board(board_id): ...@@ -145,6 +145,41 @@ def get_cards_by_board(board_id):
return leankitData return leankitData
def get_parent_cards(card_id, board_id):
"""
https://success.planview.com/Planview_LeanKit/LeanKit_API/01_v2/connections/parents
Method to list the parent cards of a specific card
:param card_id: the id of the card to list its parents
:param board_id: the id of the board to which the card belongs to
:return: list of card objects
"""
request_params = {
'board': board_id,
'limit': '100000'
}
leankitData = api._get(f'/io/card/{card_id}/connection/parents', url_params = request_params)
return leankitData
def add_parent(card_id, parent_id):
"""
https://success.planview.com/Planview_LeanKit/LeanKit_API/01_v2/connections/create
Method to add a parent connection to a card
:param card_id: the id of card to add the parent connection
:param parent_id: the id of the parent to be added as a connection
:return 201 Created
"""
request_params = {
"cardIds":[card_id],
"connections":{
"parents":[parent_id]
}
}
return api._post(f'/io/card/connections', request_params)
''' '''
def get_newer_if_exists(board_id, version, timezone='UTC'): def get_newer_if_exists(board_id, version, timezone='UTC'):
......
...@@ -3,6 +3,9 @@ import requests ...@@ -3,6 +3,9 @@ import requests
from requests import Response, Request from requests import Response, Request
from pprint import pformat from pprint import pformat
from json import dumps as json_dumps from json import dumps as json_dumps
from datetime import datetime
import pandas as pd
import time
from . import env_user from . import env_user
...@@ -39,6 +42,12 @@ class Leankit(object): ...@@ -39,6 +42,12 @@ class Leankit(object):
raise IOError("Invalid response") raise IOError("Invalid response")
else: else:
msg = 'Server responded with code {0.status_code}'.format(request) msg = 'Server responded with code {0.status_code}'.format(request)
if request.status_code == 429:
if "Retry-After" in request.headers:
retry_after = request.headers['Retry-After']#Fri, 10 Jun 2022 08:32:14 GMT
time_diff = pd.to_datetime(retry_after.rsplit(" ",1)[0]) - datetime.utcnow()
time.sleep(time_diff.total_seconds())
return self._get(url, url_params)
msg += ' ' + str(request.text) msg += ' ' + str(request.text)
raise ConnectionError(msg) raise ConnectionError(msg)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment