# Path: pypd/errors.py
# class BadRequest(Error):
#     def __init__(self, code=400, message='', *args, **kwargs):
#         self.code = code
#         self.message = message
#         self.errors = []
# 
#         Error.__init__(self, *args, **kwargs)
# 
#         try:
#             obj = json.loads(message)['error']
#             self.code = obj.get('code', code)
#             self.message = obj.get('message', message)
#             self.errors = obj.get('errors', [])
#         except:
#             pass
# 
#     def __str__(self):
#         error = '{0} ({1}): {2}'.format(self.__class__.__name__, self.code,
#                                         self.message)
#         if self.errors:
#             addon = self.errors[0] if len(self.errors) == 1 else self.errors
#             error = '{0} - {1}'.format(error, addon)
# 
#         return error


from os.path import dirname, join
from time import sleep
from pprint import pprint
from pypd.errors import BadRequest
import logging
import pypd
    to_merge = pypd.Incident.create(
        data=data_mergable,
        add_headers={'from': from_email, }
    )
except BadRequest:
    to_merge = pypd.Incident.find(incident_key=mergable_key)[-1]

# ack it, snooze it, resolve it... bop it?
pprint(incident)
pprint(incident.json)
incident.acknowledge(from_email)
incident.snooze(from_email, duration=3600)
incident.create_note(from_email, 'This is a note!')
incident.merge(from_email, [to_merge, ])

# before we trigger an event get all currently triggered incidents
triggered_incidents = pypd.Incident.find(statuses=['triggered', ])

# let's see if events and alerts work!
pypd.EventV2.create(data={
    'routing_key': '64e61052453e4ec0a3b42e93ac235375',
    'event_action': 'trigger',
    'payload': {
        'summary': 'this is an error event!',
        'severity': 'error',
        'source': 'pypd bot',
    }
})

# wait for our events to trigger incidents

# Path: pypd/errors.py
# class BadRequest(Error):
#     def __init__(self, code=400, message='', *args, **kwargs):
#         self.code = code
#         self.message = message
#         self.errors = []
# 
#         Error.__init__(self, *args, **kwargs)
# 
#         try:
#             obj = json.loads(message)['error']
#             self.code = obj.get('code', code)
#             self.message = obj.get('message', message)
#             self.errors = obj.get('errors', [])
#         except:
#             pass
# 
#     def __str__(self):
#         error = '{0} ({1}): {2}'.format(self.__class__.__name__, self.code,
#                                         self.message)
#         if self.errors:
#             addon = self.errors[0] if len(self.errors) == 1 else self.errors
#             error = '{0} - {1}'.format(error, addon)
# 
#         return error


# Path: examples/incident_demo.py
from os.path import dirname, join
from time import sleep
from pprint import pprint
from pypd.errors import BadRequest
import logging
import pypd

    to_merge = pypd.Incident.create(
        data=data_mergable,
        add_headers={'from': from_email, }
    )
except BadRequest:
    to_merge = pypd.Incident.find(incident_key=mergable_key)[-1]

# ack it, snooze it, resolve it... bop it?
pprint(incident)
pprint(incident.json)
incident.acknowledge(from_email)
incident.snooze(from_email, duration=3600)
incident.create_note(from_email, 'This is a note!')
incident.merge(from_email, [to_merge, ])

# before we trigger an event get all currently triggered incidents
triggered_incidents = pypd.Incident.find(statuses=['triggered', ])

# let's see if events and alerts work!
pypd.EventV2.create(data={
    'routing_key': '64e61052453e4ec0a3b42e93ac235375',
    'event_action': 'trigger',
    'payload': {
        'summary': 'this is an error event!',
        'severity': 'error',
        'source': 'pypd bot',
    }
})

# wait for our events to trigger incidents

while True: