Skip to content

Commit

Permalink
include beeminder api error text in exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Nov 6, 2019
1 parent 0c3b33d commit e8a37b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions pyminder/beeminder.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ def update_goal(self, goal_name, slug=None, title=None, yaxis=None, secret=None,
def get_datapoints(self, goal_name):
return self._call(f'/users/{self._user}/goals/{goal_name}/datapoints.json')

def create_datapoint(self, goal_name, value, timestamp, comment=None):
def create_datapoint(
self,
goal_name: str,
value: float,
unix_timestamp: float,
comment: str = None
):
return self._call(f'/users/{self._user}/goals/{goal_name}/datapoints.json', data={
value: value,
timestamp: timestamp,
unix_timestamp: unix_timestamp,
comment: comment
}, method="POST")

Expand Down Expand Up @@ -97,7 +103,7 @@ def _call(self, endpoint, data=None, method='GET'):
result = requests.put(url, data)

if not result.status_code == requests.codes.ok:
raise Exception(f'API request failed with code {result.status_code}')
raise Exception(f'API request failed with code {result.status_code}: {result.text}')

# self._persist_result(endpoint, result)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# This call to setup() does all the work
setup(
name="pyminder",
version="0.3.0",
version="0.4.0",
description="Beeminder power tools library",
long_description=README,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit e8a37b1

Please sign in to comment.