2019-02-05 15:10:31 +00:00
|
|
|
from typing import Any, Dict, List
|
2018-04-03 10:56:07 +00:00
|
|
|
import requests
|
|
|
|
|
2019-02-05 15:10:31 +00:00
|
|
|
from . import _BASE_URL, _headers, _with_token
|
2018-04-03 10:56:07 +00:00
|
|
|
|
2019-02-05 15:10:31 +00:00
|
|
|
|
|
|
|
@_with_token
|
2018-04-03 10:56:07 +00:00
|
|
|
def get(token: str, story_id: int = None) -> Dict[str, Any]:
|
2019-09-04 14:42:23 +00:00
|
|
|
r = requests.get(f"{_BASE_URL}/stories/{story_id}", headers=_headers(token))
|
2018-04-03 10:56:07 +00:00
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
2019-02-05 15:10:31 +00:00
|
|
|
@_with_token
|
|
|
|
def put_story(story_id: int, token: str, **kwargs: Any) -> Dict[str, Any]:
|
2019-09-04 14:42:23 +00:00
|
|
|
r = requests.put(
|
|
|
|
f"{_BASE_URL}/stories/{story_id}", headers=_headers(token), json=kwargs
|
|
|
|
)
|
2018-04-24 00:32:22 +00:00
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
2019-02-05 15:10:31 +00:00
|
|
|
@_with_token
|
2019-09-04 14:42:23 +00:00
|
|
|
def get_tasks(project_id: int, story_id: int, token: str) -> List[Dict[str, Any]]:
|
|
|
|
url = f"{_BASE_URL}/projects/{project_id}/stories/{story_id}/tasks"
|
2019-02-05 15:10:31 +00:00
|
|
|
r = requests.get(url, headers=_headers(token))
|
2018-04-03 10:56:07 +00:00
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
2019-02-05 15:10:31 +00:00
|
|
|
@_with_token
|
2019-09-04 14:42:23 +00:00
|
|
|
def get_comments(project_id: int, story_id: int, token: str) -> List[Dict[str, Any]]:
|
|
|
|
url = f"{_BASE_URL}/projects/{project_id}/stories/{story_id}/comments"
|
2019-02-05 15:10:31 +00:00
|
|
|
r = requests.get(url, headers=_headers(token))
|
2018-04-03 10:56:07 +00:00
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
2019-02-05 15:10:31 +00:00
|
|
|
@_with_token
|
2019-09-04 14:42:23 +00:00
|
|
|
def get_blockers(project_id: int, story_id: int, token: str) -> List[Dict[str, Any]]:
|
|
|
|
url = f"{_BASE_URL}/projects/{project_id}/stories/{story_id}/blockers"
|
2019-02-05 15:10:31 +00:00
|
|
|
r = requests.get(url, headers=_headers(token))
|
2019-09-04 14:42:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
@_with_token
|
|
|
|
def post(project_id: int, token: str, **kwargs: Any) -> Dict[str, Any]:
|
|
|
|
r = requests.post(
|
|
|
|
f"{_BASE_URL}/projects/{project_id}/stories",
|
|
|
|
headers={"X-TrackerToken": token},
|
|
|
|
json=kwargs,
|
|
|
|
)
|
|
|
|
r.raise_for_status()
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
|
|
@_with_token
|
|
|
|
def post_blocker(
|
|
|
|
token: str, project_id: int, story_id: int, token: str, **kwargs
|
|
|
|
) -> Dict[str, Any]:
|
|
|
|
r = requests.post(
|
|
|
|
f"{_BASE_URL}/projects/{project_id}/stories/{story_id}/blockers",
|
|
|
|
headers={"X-TrackerToken": token},
|
|
|
|
json=kwargs,
|
|
|
|
)
|
|
|
|
r.raise_for_status()
|
2018-04-03 10:56:07 +00:00
|
|
|
return r.json()
|