Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
3 lines (2 sloc) 9.39 KB
{"ts":1354219191586,"silentsave":true,"restoring":false,"patch":[[]],"length":0}
{"contributors":[],"silentsave":false,"ts":1354219193149,"patch":[[{"diffs":[[1,"var phillyapi = phillyapi || {};\r\nphillyapi = {\r\n options: {\r\n\t\tphillyapi: {\r\n\t\t\tbase: \"http://services.phila.gov/PhillyApi/Data/\"\r\n\t\t\t,summary: \"HelperService.svc/GetLocationHistory?$format=json&AddressKey=\"\r\n\t\t\t,permit: \"Service.svc/permits('%id%')?$format=json\"\r\n\t\t\t,license: \"Service.svc/licenses('%id%')?$format=json\"\r\n\t\t\t,_case: \"Service.svc/violationdetails?$filter=case_number%20eq%20'%id%'&$expand=cases&$format=json\"\r\n\t\t\t,zoningboardappeal: \"Service.svc/zoningboardappeals?$filter=appeal_number%20eq%20'%id%'&$format=json\"\r\n\t\t\t,zbahearingdecisions: \"Service.svc/zbahearingdecisions?$filter=appeal_id%20eq%20%id%&$format=json\"\r\n\t\t\t,zbacourtdetails: \"Service.svc/zbacourtdetails?$filter=appeal_id%20eq%20%id%&$format=json\"\r\n\t\t\t,buildingboardappeal: \"Service.svc/buildingboardappeals?$filter=appeal_number%20eq%20'%id%'&$format=json\"\r\n\t\t\t,bbshearingdecisions: \"Service.svc/bbshearingdecisions?$filter=appeal_id%20eq%20%id%&$format=json\"\r\n\t\t\t,bbscourtdetails: \"Service.svc/bbscourtdetails?$filter=appeal_id%20eq%20%id%&$format=json\"\r\n\t\t\t,lireviewboardappeal: \"Service.svc/lireviewboardappeals?$filter=appeal_number%20eq%20'%id%'&$format=json\"\r\n\t\t\t,lirbhearingdecisions: \"Service.svc/lirbhearingdecisions?$filter=appeal_id%20eq%20%id%&$format=json\"\r\n\t\t\t,lirbcourtdetails: \"Service.svc/lirbcourtdetails?$filter=appeal_id%20eq%20%id%&$format=json\"\r\n\t\t\t,timeout: 20000\r\n\t\t}\r\n\t\t,ulrs311: {\r\n\t\t\tbase: \"http://services.phila.gov/ULRS311/Data/\"\r\n\t\t\t,addressKey: \"LIAddressKey/\"\r\n\t\t\t,timeout: 20000\r\n\t\t}\r\n\t}\r\n\r\n\t,getAddressKey: function(input, successCallback, errorCallback) {\r\n\t\tvar url = phillyapi.options.ulrs311.base + phillyapi.options.ulrs311.addressKey + encodeURIComponent(input);\r\n\t\t$.ajax({\r\n\t\t\turl: url\r\n\t\t\t,dataType: \"jsonp\"\r\n\t\t\t,contentType: \"application/json; charset=utf-8\"\r\n\t\t\t,async: false\r\n\t\t\t,cache: true\r\n\t\t\t,crossDomain: true\r\n\t\t\t,timeout: phillyapi.options.ulrs311.timeout\r\n\t\t\t,type: \"GET\"\r\n\t\t\t,xhrFields: { withCredentials: false }\r\n\t\t\t,error: errorCallback\r\n\t\t\t,success: function(data) {\r\n\t\t\t\tif(\"TopicID\" in data) {\r\n\t\t\t\t\tvar addressKey = data.TopicID;\r\n \t\t\t\t// Clean up the address. Default format is something like \" 01234 MARKET ST\" - needs to be \"1234 MARKET ST\" - Anyone have a better regex for it?\r\n\t\t\t\t\tvar address = data.AddressRef ? $.trim(data.AddressRef.replace(/ +(?= )/g,\"\")).replace(/^0+/, \"\") : null;\r\n\t\t\t\t\tsuccessCallback(addressKey, address);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n\r\n\t,getSummary: function(addressKey, successCallback, errorCallback, sorted) {\r\n\t\tvar url = phillyapi.options.phillyapi.base + phillyapi.options.phillyapi.summary + addressKey;\r\n\t\tphillyapi.fetch(url, function(data) {\r\n\t\t\tsuccessCallback(sorted ? phillyapi.sortSummary(data) : data);\r\n\t\t}, errorCallback);\r\n\t}\r\n\t\r\n\t,getPermit: function(id, successCallback, errorCallback) {\r\n\t\tvar url = phillyapi.options.phillyapi.base + phillyapi.options.phillyapi.permit.replace(\"%id%\", id);\r\n\t\tphillyapi.fetch(url, successCallback, errorCallback);\r\n\t}\r\n\t\r\n\t,getLicense: function(id, successCallback, errorCallback) {\r\n\t\tvar url = phillyapi.options.phillyapi.base + phillyapi.options.phillyapi.license.replace(\"%id%\", id);\r\n\t\tphillyapi.fetch(url, successCallback, errorCallback);\r\n\t}\r\n\t\r\n\t,getCase: function(id, successCallback, errorCallback, sorted) {\r\n\t\tvar url = phillyapi.options.phillyapi.base + phillyapi.options.phillyapi._case.replace(\"%id%\", id);\r\n\t\tphillyapi.fetch(url, function(data) {\r\n\t\t\tsuccessCallback(sorted ? phillyapi.sortCase(data) : data);\r\n\t\t}, errorCallback);\r\n\t}\r\n\t\r\n\t/*\r\n\t\tDue to a known issue in the API, we have to do 3 calls here instead of 1. Also, since the Summary gives us the appeal\r\n\t\tnumber rather than appeal id, we have to wait for the first call to finish in order to get the appeal id for the second two\r\n\t*/\r\n\t,getAppeal: function(type, id, successCallback, errorCallback) {\r\n\t\tvar sortedData = {}, urlKeys = [];\r\n\t\tswitch(type) {\r\n\t\t\tcase \"zoningboardappeals\":\r\n\t\t\t\turlKeys = [\"zoningboardappeal\", \"zbahearingdecisions\", \"zbacourtdetails\"];\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"buildingboardappeals\":\r\n\t\t\t\turlKeys = [\"buildingboardappeal\", \"bbshearingdecisions\", \"bbscourtdetails\"];\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"lireviewboardappeals\":\r\n\t\t\t\turlKeys = [\"lireviewboardappeal\", \"lirbhearingdecisions\", \"lirbcourtdetails\"];\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t\t\r\n\t\t// Appeal Details\r\n\t\tvar url1 = phillyapi.options.phillyapi.base + phillyapi.options.phillyapi[urlKeys[0]].replace(\"%id%\", id);\r\n\t\tphillyapi.fetch(url1, function(data) {\r\n\t\t\tsortedData.d = data.d.results[0];\r\n\t\t\tvar requestsPending = 0;\r\n\t\t\t\r\n\t\t\t// Hearing Decisions\r\n\t\t\trequestsPending++;\r\n\t\t\tvar url2 = phillyapi.options.phillyapi.base + phillyapi.options.phillyapi[urlKeys[1]].replace(\"%id%\", data.d.results[0].appeal_id);\r\n\t\t\tphillyapi.fetch(url2, function(data) {\r\n\t\t\t\tsortedData.d.hearingdecisions = data.d.results;\r\n\t\t\t\trequestsPending--;\r\n\t\t\t\tif(requestsPending < 1) successCallback(sortedData);\r\n\t\t\t}, errorCallback);\r\n\t\t\t// Court History\r\n\t\t\trequestsPending++;\r\n\t\t\tvar url3 = phillyapi.options.phillyapi.base + phillyapi.options.phillyapi[urlKeys[2]].replace(\"%id%\", data.d.results[0].appeal_id);\r\n\t\t\tphillyapi.fetch(url3, function(data) {\r\n\t\t\t\tsortedData.d.courtdetails = data.d.results;\r\n\t\t\t\trequestsPending--;\r\n\t\t\t\tif(requestsPending < 1) successCallback(sortedData);\r\n\t\t\t}, errorCallback);\r\n\t\t}, errorCallback);\r\n\t}\r\n\r\n\t,fetch: function(url, successCallback, errorCallback) {\r\n\t\t$.ajax({\r\n\t\t\turl: url\r\n\t\t\t,dataType: \"jsonp\"\r\n\t\t\t,cache: true\r\n\t\t\t,timeout: phillyapi.options.phillyapi.timeout\r\n\t\t\t,jsonp: \"$callback\"\r\n\t\t\t,success: successCallback\r\n\t\t\t,error: errorCallback\r\n\t\t});\r\n\t}\r\n\t\r\n\t// Sort summary data into categories\r\n\t,sortSummary: function(data) {\r\n\t\tvar sortedData = {};\r\n\t\tfor(var i = 0; i < data.length; i++) {\r\n\t\t\tswitch(data[i].category) {\r\n\t\t\t\tcase \"Violation\":\r\n\t\t\t\t\tif(sortedData.cases === undefined) {\r\n\t\t\t\t\t\tsortedData.cases = {};\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif(sortedData.cases[data[i].id] === undefined) {\r\n\t\t\t\t\t\tsortedData.cases[data[i].id] = {\r\n\t\t\t\t\t\t\t\"case_number\": data[i].id\r\n\t\t\t\t\t\t\t,\"violations\": []\r\n\t\t\t\t\t\t\t,\"entity\": data[i].entity\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tsortedData.cases[data[i].id].violations.push(data[i].type);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"Permit\":\r\n\t\t\t\t\tif(sortedData.permits === undefined) {\r\n\t\t\t\t\t\tsortedData.permits = [];\r\n\t\t\t\t\t}\r\n\t\t\t\t\tsortedData.permits.push({\r\n\t\t\t\t\t\t\"permit_number\": data[i].id\r\n\t\t\t\t\t\t,\"permit_type_name\": data[i].type\r\n\t\t\t\t\t\t,\"entity\": data[i].entity\r\n\t\t\t\t\t});\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"Business\":\r\n\t\t\t\t\tif(sortedData.licenses === undefined) {\r\n\t\t\t\t\t\tsortedData.licenses = [];\r\n\t\t\t\t\t}\r\n\t\t\t\t\tsortedData.licenses.push({\r\n\t\t\t\t\t\t\"license_number\": data[i].id\r\n\t\t\t\t\t\t,\"license_type_name\": data[i].type\r\n\t\t\t\t\t\t,\"entity\": data[i].entity\r\n\t\t\t\t\t});\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"Appeal\":\r\n\t\t\t\t\tif(sortedData.appeals === undefined) {\r\n\t\t\t\t\t\tsortedData.appeals = [];\r\n\t\t\t\t\t}\r\n\t\t\t\t\tsortedData.appeals.push({\r\n\t\t\t\t\t\t\"appeal_number\": data[i].id\r\n\t\t\t\t\t\t,\"appeal_type_name\": data[i].type\r\n\t\t\t\t\t\t,\"entity\": data[i].entity\r\n\t\t\t\t\t});\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tif(sortedData.other === undefined) {\r\n\t\t\t\t\t\tsortedData.other = [];\r\n\t\t\t\t\t}\r\n\t\t\t\t\tsortedData.other.push({\r\n\t\t\t\t\t\t\"number\": data[i].id\r\n\t\t\t\t\t\t,\"type_name\": data[i].type\r\n\t\t\t\t\t});\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(sortedData.cases !== undefined) sortedData.cases = phillyapi.objToArray(sortedData.cases);\r\n\t\treturn sortedData;\r\n\t}\r\n\t\r\n\t/*\r\n\t\tThis is a work-around for a known issue in the API. Ideally we'd do a call to the case and expand the violationdetails,\r\n\t\tbut since that gives an error, we do a call to the violation details of the case and expand the case.\r\n\t\tThat gives the case details multiple times, but at least it's only one ajax call. This function shuffles the data\r\n\t\taround to be the case with a violationdetails array.\r\n\t*/\r\n\t,sortCase: function(data) {\r\n\t\tvar sortedData = {};\r\n\t\tsortedData.d = data.d.results[0].cases;\r\n\t\tfor(var i = 0; i < data.d.results.length; i++) {\r\n\t\t\tif(data.d.results[i].cases !== undefined) delete data.d.results[i].cases;\r\n\t\t}\r\n\t\tsortedData.d.violationdetails = data.d.results;\r\n\t\treturn sortedData;\r\n\t}\r\n\t\r\n\t// Stock function\r\n\t,objToArray: function(obj) {\r\n\t\tvar arr = []\r\n\t\tfor(var key in obj) {\r\n\t\t\tarr.push(obj[key]);\r\n\t\t}\r\n\t\treturn arr;\r\n\t}\r\n};"]],"start1":0,"start2":0,"length1":0,"length2":8149}]],"length":8149,"saved":false}
Jump to Line
Something went wrong with that request. Please try again.