Skip to content

Commit

Permalink
Stop returning only the data, there can also be a meta field
Browse files Browse the repository at this point in the history
  • Loading branch information
David Moreau-Simard committed Jul 27, 2016
1 parent dd469c0 commit f757b61
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions cachetclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ def _delete(self, path, **kwargs):
def _get(self, path, **kwargs):
url = "%s/%s" % (self.endpoint, path)
reponse, data = self._request(url, 'GET', **kwargs)
return json.dumps(data['data'], indent=2)
return json.dumps(data, indent=2)

def _post(self, path, **kwargs):
url = "%s/%s" % (self.endpoint, path)
response, data = self._request(url, 'POST', **kwargs)
return json.dumps(data['data'], indent=2)
return json.dumps(data, indent=2)

def _put(self, path, **kwargs):
url = "%s/%s" % (self.endpoint, path)
Expand Down
31 changes: 16 additions & 15 deletions contrib/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,28 @@
status=1,
description='Test component'))
print(components.get())
components.put(id=new_component['id'], description='Updated component')
print(components.get(id=new_component['id']))
components.delete(id=new_component['id'])
components.put(id=new_component['data']['id'], description='Updated component')
print(components.get(id=new_component['data']['id']))
components.delete(id=new_component['data']['id'])

# /components/groups
groups = cachet.Groups(endpoint=ENDPOINT, api_token=API_TOKEN)
new_group = json.loads(groups.post(name='Test group'))
print(groups.get())
groups.put(id=new_group['id'], name='Updated group')
print(groups.get(id=new_group['id']))
groups.delete(new_group['id'])
groups.put(id=new_group['data']['id'], name='Updated group')
print(groups.get(id=new_group['data']['id']))
groups.delete(new_group['data']['id'])

# /incidents
incidents = cachet.Incidents(endpoint=ENDPOINT, api_token=API_TOKEN)
new_incident = json.loads(incidents.post(name='Test incident',
message='Houston, we have a problem.',
status=1))
print(incidents.get())
incidents.put(id=new_incident['id'],
incidents.put(id=new_incident['data']['id'],
message="There's another problem, Houston.")
print(incidents.get(id=new_incident['id']))
incidents.delete(id=new_incident['id'])
print(incidents.get(id=new_incident['data']['id']))
incidents.delete(id=new_incident['data']['id'])

# /metrics
# /metrics/points
Expand All @@ -64,16 +64,17 @@
description='How many numbers per hour',
default_value=0))
print(metrics.get())
print(metrics.get(id=new_metric['id']))
print(metrics.get(id=new_metric['data']['id']))

points = cachet.Points(endpoint=ENDPOINT, api_token=API_TOKEN)
new_point = json.loads(points.post(id=new_metric['id'], value=5))
print(points.get(metric_id=new_metric['id']))
new_point = json.loads(points.post(id=new_metric['data']['id'], value=5))
print(points.get(metric_id=new_metric['data']['id']))

points.delete(metric_id=new_metric['id'], point_id=new_point['id'])
metrics.delete(id=new_metric['id'])
points.delete(metric_id=new_metric['data']['id'],
point_id=new_point['data']['id'])
metrics.delete(id=new_metric['data']['id'])

# /subscribers
subscribers = cachet.Subscribers(endpoint=ENDPOINT, api_token=API_TOKEN)
new_subscriber = json.loads(subscribers.post(email='[email protected]'))
subscribers.delete(id=new_subscriber['id'])
subscribers.delete(id=new_subscriber['data']['id'])

0 comments on commit f757b61

Please sign in to comment.