Skip to content

Commit

Permalink
support story update/get
Browse files Browse the repository at this point in the history
  • Loading branch information
Lingnik committed May 17, 2017
1 parent e7648a2 commit 70903c7
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions pivotalclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ def __init__(self, api_token, account_id=None, project_id=None, api_root=None):
def _get(self, endpoint, querystring=None, with_envelope=False):
"""Issue a GET to Pivotal Tracker.
endpoint: a URL to GET
querystring: a dict of querystring parameters
Args:
endpoint: a URL to GET
querystring: a dict of querystring parameters
"""
_querystring = querystring.copy() if querystring else {}
if with_envelope:
Expand All @@ -91,15 +92,29 @@ def _get(self, endpoint, querystring=None, with_envelope=False):
def _post(self, endpoint, json):
"""Issue a POST to Pivotal Tracker.
endpoint: a URL to POST
json: the jsonifiable (e.g. dict or list) data to send to Pivotal
Args:
endpoint: a URL to POST
json: the jsonifiable (e.g. dict or list) data to send to Pivotal
"""
headers = self.auth_headers
resp = requests.post(endpoint, json=json, headers=headers)
if not resp or not 200 <= resp.status_code < 300:
raise ApiError('GET {} {}'.format(endpoint, resp.status_code))
raise ApiError('POST {} {}'.format(endpoint, resp.status_code))
return resp.json()


def _put(self, endpoint, json):
"""Issue a PUT to Pivotal Tracker.
Args:
endpoint: a URL to PUT
json: the jsonifiable (e.g. dict or list) data to send to Pivotal
"""
headers = self.auth_headers
resp = requests.put(endpoint, json=json, headers=headers)
if not resp or not 200 <= resp.status_code < 300:
raise ApiError('PUT {} {}'.format(endpoint, resp.status_code))
return resp.json()

def _get_all(self, endpoint, querystring=None):
DEFAULT_PAGE_LIMIT = 1000
_querystring = querystring.copy() if querystring else {}
Expand All @@ -122,7 +137,7 @@ def _get_all(self, endpoint, querystring=None):
# Increment the offset by the server-specified limit to get the next page.
_querystring['offset'] += _querystring['limit']
return results

def _verify_project_id_exists(self):
if not self.project_id:
caller_name = 'UNKNOWN'
Expand All @@ -141,6 +156,10 @@ def _verify_account_id_exists(self):
caller_name = inspect.stack()[1][3]
raise ApiError('Account ID not set on API connection and is required by {}().'.format(caller_name))

def get_story(self, story_id):
self._verify_project_id_exists()
return self._get(self.api_story.format(story_id))

def get_stories_by_filter(self, pivotal_filter):
self._verify_project_id_exists()
filt = self.api_filter.copy()
Expand Down Expand Up @@ -209,6 +228,12 @@ def create_story(self, story_dict):
results = self._post(uri, story_dict)
return results

def update_story(self, story_id, fields):
self._verify_project_id_exists()
uri = self.api_story.format(story_id)
results = self._put(uri, fields)
return results

@staticmethod
def _desc_for_external_story(context, template):
tmpl = '[External Story #{external_story[external_id]}]'
Expand Down

0 comments on commit 70903c7

Please sign in to comment.