Skip to content

Instantly share code, notes, and snippets.

@mikotian
Last active February 6, 2020 15:40
from flask import Flask, json,request
import random
import uuid
import time
from datetime import timedelta
from datetime import datetime
incidentobject = {"busObPublicId":"123","busObRecId":"1233455667","cacheKey":None,"fieldValidationErrors":[],"notificationTriggers":[],"errorCode":None,"errorMessage":None,"hasError":False}
responses={"responses":[incidentobject],"errorCode": None,"errorMessage": None,"hasError": False}
contactobj={"businessObjects":[{"busObId":"40defb14c50e4fabb012f449fa83c66c","busObPublicId":"John Doe","busObRecId":"1382bd87b14149fdb1b7010d8331c022","fields":[{"dirty":False,"displayName":"CustomerID","fieldId":"9446cddb05a4817182c15e4755b6f37eb2ec14ef0f","html":None,"name":"CustomerID","value":"1234"}],"hasPrompts":False,"links":[],"prompts":[],"searchResultsFields":[],"simpleResults":None,"totalRows":1,"errorCode":None,"errorMessage":None,"hasError":False}
incidentobj={"businessObjects":[{"busObId":"080291a3a8d34b4a89950aab9b43a6a4","busObPublicId":"123","busObRecId":"1234","fields":[{"dirty":False,"displayName":"Incident ID","fieldId":"BO:080291a","html":None,"name":"IncidentID","value":"20200113999999"}],"links":[],"errorCode":None,"errorMessage":None,"hasError":False}],"hasPrompts":False,"links":[],"prompts":[],"searchResultsFields":[],"simpleResults":None,"totalRows":1,"errorCode":None,"errorMessage":None,"hasError":False}
notesobj={"businessObjects":[],"hasPrompts":False,"links":[],"prompts":[],"searchResultsFields":[],"simpleResults":None,"totalRows":0,"errorCode":None,"errorMessage":None,"hasError":False}
accessobj={"access_token": "123456","token_type": "bearer","expires_in": 86399,"refresh_token": "ee700338b8254ee5bcb7f7c942587aa1","as:client_id": "5c730783-cb72-4a17-a38c-9d9f822c5db0","username": "abc",".issued": "Tue, 21 Jan 2020 13:10:38 GMT",".expires": "Wed, 22 Jan 2020 13:10:38 GMT"}
listofincidents={}
api = Flask(__name__)
latency=0.5
PREFIX="/mbird/api/V1"
@api.route(PREFIX+'/savebusinessobject', methods=['POST'])
def post_savebusinessobject():
incidentobject["busObPublicId"]=str(random.randrange(20200100000001, 20200199999999, 3))
incidentobject["busObRecId"]=str(uuid.uuid1().hex)
time.sleep(latency)
return json.dumps(incidentobject)
@api.route(PREFIX+'/savebusinessobjectbatch', methods=['POST'])
def post_savebusinessobjectbatch():
responses["responses"][0]["busObPublicId"]=str(random.randrange(20200100000001, 20200199999999, 3))
responses["responses"][0]["busObRecId"]=str(uuid.uuid1().hex)
time.sleep(latency)
return json.dumps(responses)
@api.route(PREFIX+'/linkrelatedbusinessobject/<path:text>', methods=['GET'])
def get_linkRelatedBO(text):
time.sleep(latency)
return json.dumps({})
@api.route('/mbird/token', methods=['POST'])
def get_authToken():
accessobj["access_token"]=str(uuid.uuid4())
accessobj[".issued"]=time.strftime("%a, %d %b %Y %I:%M:%S %p %Z", time.gmtime())
accessobj[".expires"]=time.strftime("%a, %d %b %Y %I:%M:%S %p GMT", (datetime.now()+timedelta(hours=18)).timetuple())
time.sleep(latency)
return accessobj
@api.route(PREFIX+'/getsearchresults', methods=['POST'])
def get_searchResults():
requestjson=request.get_json()
print request
print requestjson["filters"][0]["fieldId"]
print requestjson
time.sleep(latency)
if(requestjson["filters"][0]["fieldId"]=="2cf07f7647b24bbf80251c79337eb50d"):
incidentobj["businessObjects"][0]["busObPublicId"]=str(random.randrange(20200100000001, 20200199999999, 3))
incidentobj["businessObjects"][0]["busObRecId"]=str(uuid.uuid1().hex)
incidentobj["businessObjects"][0]["busObRecId"]=str(uuid.uuid1().hex)
return json.dumps(incidentobj)
elif (requestjson["filters"][0]["fieldId"]=="c0b942234b7442bbb0ec57210153e506"):
return json.dumps(contactobj)
else:
return json.dumps(notesobj)
if __name__ == '__main__':
api.run(host='0.0.0.0',debug=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment