Last active
December 22, 2015 21:19
-
-
Save sweded/6532417 to your computer and use it in GitHub Desktop.
Provides Quickbase auth, create, update, delete, and rescue methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @file /components/qbCrud.cfc | |
* @author Gernot Bartels 2013 | |
* @description Provides Quickbase auth, create, update, delete, and rescue methods | |
**/ | |
component extends="qbAuth" | |
output="false" | |
accessors="true" | |
displayname="Quickbase API methods" | |
hint="createRecord(), updateRecord(), deleteRecord(), rescueRequest()" | |
{ | |
property | |
name="qbRid" | |
type="string" | |
default="" | |
hint="The Quickbase record ID."; | |
property | |
name="qbUpdateID" | |
type="string" | |
default="" | |
hint="The update ID returned by Quickbase."; | |
property | |
name="qbNumFieldsChanged" | |
type="string" | |
default="" | |
hint="The number of fields updated."; | |
public any function init() { | |
this.setUuid(CreateUUID()); | |
return this; | |
} | |
private any function doRecord(url_request, qb_tableID) { | |
http method="POST" result="qbReturn" url=url_request; | |
this.setQbResult(XmlParse(qbReturn.Filecontent)); | |
variables.apiReturn = structNew(); | |
variables.resultChildren = getQbResult().qdbapi.XmlChildren; | |
for ( i=1; i LTE ArrayLen(resultChildren); i=i+1 ) { | |
/* | |
Retrieve the element Name and Text values and assign dynamically */ | |
#elementName# = resultChildren[i].XmlName; | |
#elementText# = resultChildren[i].XmlText; | |
/* | |
Insert keys + values into apiReturn (struct) */ | |
StructInsert(apiReturn, elementName, elementText); | |
} | |
/* | |
Set implicit variables */ | |
if (structKeyExists(apiReturn, "action")) { | |
this.setQbAction(apiReturn.action); | |
} | |
if (structKeyExists(apiReturn, "errcode")) { | |
this.setQbErrCode(apiReturn.errcode); | |
} | |
if (structKeyExists(apiReturn, "errtext")) { | |
this.setQbErrText(apiReturn.errtext); | |
} | |
if (structKeyExists(apiReturn, "errdetail")) { | |
this.setQbErrDetail(apiReturn.errdetail); | |
} | |
if (structKeyExists(apiReturn, "rid")) { | |
this.setQbRid(apiReturn.rid); | |
} | |
if (structKeyExists(apiReturn, "update_id")) { | |
this.setQbUpdateId(apiReturn.update_id); | |
} | |
/* | |
Check return error code */ | |
if (structKeyExists(apiReturn, "errcode")) { | |
switch(getQbErrCode()) { | |
case 0: | |
/* | |
Peachy, no error so exit */ | |
break; | |
case 4: | |
/* | |
We know the ticket is bad so rebuild the session and try to rescue the request */ | |
badTicket = new qbError().badTicket(url_request, qb_tableID); | |
break; | |
default: | |
/* | |
Some other error so log it and notify */ | |
savecontent variable="app_message" { | |
writeOutput( | |
"Calling #getQbAction()# returned Error: | |
#getQbErrCode()#, #getQbErrText()#.<br>" ); | |
} | |
error_data = structNew(); | |
error_data.app_message = app_message; | |
error_data.app_name = "app_name"; | |
error_data.log_name = "log_name"; | |
error_data.apiReturn = apiReturn; | |
error_data.qb_tableID = "111"; | |
error_data.response_id = "222"; | |
qbError = new qbError().logError(error_data); | |
break; | |
} | |
} | |
return this; | |
} | |
/* | |
Create */ | |
public any function createRecord(url_request, qb_tableID) { | |
doRecord(url_request, qb_tableID); | |
return this; | |
} | |
/* | |
Update */ | |
public any function updateRecord(url_request, qb_tableID) { | |
doRecord(url_request, qb_tableID); | |
return this; | |
} | |
/* | |
Delete */ | |
public any function deleteRecord(url_request, qb_tableID) { | |
doRecord(url_request, qb_tableID); | |
return this; | |
} | |
/* | |
Rescue request in case of bad ticket/rebuilt SESSION */ | |
public any function rescueRequest(url_request, qb_tableID) { | |
doRecord(url_request, qb_tableID); | |
return this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment