API made a bit more flexible with input data

- input for add_event() and update_event() can now be a JSON object, JSON string, XML
pull/2/merge
Iglocska 2015-07-30 15:53:34 +02:00
parent c315ecaef6
commit 507c5a5446
2 changed files with 17 additions and 6 deletions

View File

@ -4,7 +4,6 @@
import sys
from pymisp import PyMISP
import json
from keys import cert, priv
@ -31,7 +30,7 @@ def init(cert_to_priv=True):
def _to_utf8(request):
to_return = None
if 'json' in request.headers['content-type']:
to_return = json.dumps(request.json())
to_return = request.json()
else:
to_return = request.text.encode('utf-8')
return to_return

View File

@ -81,9 +81,15 @@ class PyMISP(object):
"""
Add a new event
:param event: Event object to add
:param event: Event as JSON object / string or XML to add
"""
session = self.__prepare_session()
if self.out_type == 'json':
if isinstance(event, basestring):
return session.post(self.url, data=event)
else:
return session.post(self.url, data=json.dumps(event))
else:
return session.post(self.url, data=event)
def update_event(self, event_id, event):
@ -91,9 +97,15 @@ class PyMISP(object):
Update an event
:param event_id: Event id to update
:param event: Elements to add
:param event: Event as JSON object / string or XML to add
"""
session = self.__prepare_session()
if self.out_type == 'json':
if isinstance(event, basestring):
return session.post(self.rest.format(event_id), data=event)
else:
return session.post(self.rest.format(event_id), data=json.dumps(event))
else:
return session.post(self.rest.format(event_id), data=event)
def delete_event(self, event_id):