Class: QuickBase::WebClient
- Inherits:
-
CommandLineClient
- Object
- Client
- CommandLineClient
- QuickBase::WebClient
- Defined in:
- lib/QuickBaseWebClient.rb
Overview
class WebClient: a web server that responds to requests to run command files present on the local machine. This extends QuickBase via URLs on web pages.
e.g. if there is an ‘uploadSpreadsheet.qbc’ command file next to this QuickBaseClient.rb file on your machine, it can be run from a web page by starting ‘WebClient.new’ on your machine and placing ‘127.0.0.1:2358/qbc/uploadSpreadsheet.qbc’ in a link on the web page.
Any request that does not include “/qbc/” will shut down the server.
Instance Attribute Summary collapse
-
#ipAddress ⇒ Object
readonly
Returns the value of attribute ipAddress.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#running ⇒ Object
readonly
Returns the value of attribute running.
-
#runNow ⇒ Object
readonly
Returns the value of attribute runNow.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Attributes inherited from CommandLineClient
#aliases, #availableCommands, #commands, #usage
Attributes inherited from Client
#HTML, #access, #accessid, #accountLimit, #accountUsage, #action, #admin, #adminOnly, #ancestorappid, #app, #appdata, #appdbid, #applicationLimit, #applicationUsage, #apptoken, #authenticationXML, #cacheSchemas, #cachedSchemas, #chdbids, #choice, #clist, #create, #createapptoken, #createdTime, #databases, #dbdesc, #dbid, #dbidForRequestURL, #dbname, #delete, #disprec, #domain, #downLoadFileURL, #email, #encoding, #errcode, #errdetail, #errtext, #escapeBR, #eventSubscribers, #excludeparents, #externalAuth, #fform, #fid, #fids, #field, #fieldTypeLabelMap, #fieldValue, #field_data, #field_data_list, #fields, #fileContents, #fileUploadToken, #firstName, #fmt, #fname, #fnames, #fvlist, #hours, #httpConnection, #id, #ignoreCR, #ignoreError, #ignoreLF, #ignoreTAB, #includeancestors, #jht, #jsa, #keepData, #key_fid, #label, #lastAccessTime, #lastError, #lastModifiedTime, #lastName, #lastPaymentDate, #lastRecModTime, #logger, #login, #mgrID, #mgrName, #mode, #modify, #name, #newappname, #newdbdesc, #newdbid, #newdbname, #newowner, #numMatches, #numRecords, #num_fields, #num_records, #num_recs_added, #num_recs_deleted, #num_recs_input, #num_recs_updated, #numadded, #numremoved, #oldestancestorappid, #options, #org, #page, #pagebody, #pageid, #pagename, #pagetype, #password, #permissions, #printRequestsAndResponses, #properties, #qarancestorappid, #qbhost, #qdbapi, #qid, #qname, #queries, #query, #rdr, #record, #records, #records_csv, #requestHeaders, #requestNextAllowedTime, #requestSucceeded, #requestTime, #requestURL, #requestXML, #responseElement, #responseElementText, #responseElements, #responseXML, #responseXMLdoc, #rid, #rids, #role, #roleid, #rolename, #saveviews, #screenName, #serverDatabases, #serverGroups, #serverStatus, #serverUpdays, #serverUptime, #serverUsers, #serverVersion, #showAppData, #skipfirst, #slist, #standardRequestHeaders, #status, #stopOnError, #table, #tables, #ticket, #type, #udata, #uname, #update_id, #user, #userid, #username, #users, #validFieldProperties, #validFieldTypes, #value, #variables, #varname, #version, #vid, #view, #withembeddedtables, #xsl
Instance Method Summary collapse
-
#initialize(runNow = true, ipAddress = 'localhost', port = 2358) ⇒ WebClient
constructor
A new instance of WebClient.
- #start(ipAddress = 'localhost', port = 2358) ⇒ Object
- #stop ⇒ Object
Methods inherited from CommandLineClient
#cmdString, #evalAvailableCommands, #prompt, #run, #setCommand, #setCommandAlias, #showAvailableCommands, #showUsage
Methods inherited from Client
#_addField, #_addRecord, #_addReplaceDBPage, #_addUserToRole, #_changePermission, #_changeRecordOwner, #_changeUserRole, #_cloneDatabase, #_deleteDatabase, #_deleteField, #_deleteFieldName, #_deleteRecord, #_doQuery, #_doQueryCount, #_doQueryHash, #_doQueryName, #_downLoadFile, #_editRecord, #_fieldAddChoices, #_fieldNameAddChoices, #_fieldNameRemoveChoices, #_fieldRemoveChoices, #_genAddRecordForm, #_genResultsTable, #_getAncestorInfo, #_getAppDTMInfo, #_getBillingStatus, #_getDBInfo, #_getDBPage, #_getDBvar, #_getEntitlementValues, #_getFileAttachmentUsage, #_getNumRecords, #_getRecordAsHTML, #_getRecordInfo, #_getRoleInfo, #_getSchema, #_getUserRole, #_importFromCSV, #_importFromExcel, #_listDBPages, #_printChildElements, #_provisionUser, #_purgeRecords, #_removeUserFromRole, #_renameApp, #_runImport, #_sendInvitation, #_setActiveRecord, #_setAppData, #_setDBvar, #_setFieldProperties, #_setKeyField, #_updateFile, #_uploadFile, #_userRoles, #addField, #addFieldValuePair, #addOrEditRecord, #addRecord, #addReplaceDBPage, #addUserToRole, #alias_methods, #applyDeviationToRecords, #applyPercentToRecords, #authenticate, #average, #chainAPIcallsBlock, #changePermission, #changeRecordOwner, #changeRecords, #changeUserRole, #clearFieldValuePairList, #clientMethods, #cloneDatabase, #copyRecord, #count, #createDatabase, #createTable, #dateToMS, #debugHTTPConnection, #decodeXML, #deleteDatabase, #deleteDuplicateRecords, #deleteField, #deleteRecord, #deleteRecords, #deviation, #doQuery, #doQueryCount, #doSQLInsert, #doSQLQuery, #doSQLUpdate, #downLoadFile, #eachField, #eachRecord, #editRecord, #editRecords, #encodeXML, #encodingStrings, #escapeXML, #fieldAddChoices, #fieldRemoveChoices, #fieldTypeForLabel, #findDBByname, #findDuplicateRecordIDs, #findElementByAttributeValue, #findElementsByAttributeName, #findElementsByAttributeValue, #formatChdbidName, #formatCurrency, #formatDate, #formatDuration, #formatFieldValue, #formatImportCSV, #formatPercent, #formatTimeOfDay, #genAddRecordForm, #genResultsTable, #getAllRecordIDs, #getAllValuesForFields, #getAllValuesForFieldsAsArray, #getAllValuesForFieldsAsJSON, #getAllValuesForFieldsAsPrettyJSON, #getAncestorInfo, #getAppDTMInfo, #getApplicationVariable, #getApplicationVariables, #getAttributeString, #getAuthenticationXMLforRequest, #getBillingStatus, #getColumnListForQuery, #getDBInfo, #getDBPage, #getDBPagesAsArray, #getDBforRequestURL, #getDBvar, #getEntitlementValues, #getErrorInfoFromResponse, #getFieldChoices, #getFieldDataPrintableValue, #getFieldDataValue, #getFieldIDs, #getFieldNames, #getFileAttachmentUsage, #getFileUploadToken, #getFilteredRecords, #getJoinRecords, #getNumRecords, #getNumTables, #getOneTimeTicket, #getQueryRequestXML, #getRecord, #getRecordAsHTML, #getRecordInfo, #getReportNames, #getResponseElement, #getResponseElements, #getResponsePathValue, #getResponsePathValues, #getResponseValue, #getRoleInfo, #getSchema, #getServerStatus, #getSortListForQuery, #getSummaryRecords, #getTableIDs, #getTableName, #getTableNames, #getUnionRecords, #getUserInfo, #getUserRole, #grantedDBs, #importCSVFile, #importFromCSV, #importFromExcel, #importSVFile, #importTSVFile, init, #isAverageField?, #isBuiltInField?, #isHTMLRequest?, #isRecordidField?, #isTotalField?, #isValidFieldProperty?, #isValidFieldType?, #iterateDBPages, #iterateFilteredRecords, #iterateJoinRecords, #iterateRecordInfos, #iterateRecords, #iterateSummaryRecords, #iterateUnionRecords, #listDBPages, #logToFile, #lookupBaseFieldTypeByName, #lookupChdbid, #lookupField, #lookupFieldData, #lookupFieldIDByName, #lookupFieldName, #lookupFieldNameFromID, #lookupFieldPropertyByName, #lookupFieldType, #lookupFieldTypeByName, #lookupFieldsByType, #lookupQuery, #lookupQueryByName, #lookupRecord, #makeSVFile, #max, #method_missing, #min, #obStatus, #onChangedDbid, #parseResponseXML, #percent, #prependAPI?, #printChildElements, #printLastError, #printRequest, #printResponse, #processChildElements, processDatabase, #processRESTFieldNameOrRecordKeyRequest, #processRESTRequest, #processResponse, #provisionUser, #purgeRecords, #removeUserFromRole, #renameApp, #replaceFieldValuePair, #resetErrorInfo, #resetfid, #resetrid, #runImport, #sendInvitation, #sendRequest, #setActiveRecord, #setActiveTable, #setAppData, #setDBvar, #setFieldProperties, #setFieldValue, #setFieldValues, #setHTTPConnection, #setHTTPConnectionAndqbhost, #setKeyField, #setLogger, #setqbhost, #signOut, #splitString, #subscribe, #sum, #toXML, #toggleTraceInfo, #updateFile, #uploadFile, #userRoles, #verifyFieldList, #verifyQueryOperator
Constructor Details
#initialize(runNow = true, ipAddress = 'localhost', port = 2358) ⇒ WebClient
Returns a new instance of WebClient.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/QuickBaseWebClient.rb', line 31 def initialize( runNow = true, ipAddress = 'localhost', port = 2358 ) super() @runNow = runNow @doStop = @running = false if @runNow start( ipAddress, port ) else @ipAddress, @port = ipAddress, port end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class QuickBase::Client
Instance Attribute Details
#ipAddress ⇒ Object (readonly)
Returns the value of attribute ipAddress.
29 30 31 |
# File 'lib/QuickBaseWebClient.rb', line 29 def ipAddress @ipAddress end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
29 30 31 |
# File 'lib/QuickBaseWebClient.rb', line 29 def port @port end |
#running ⇒ Object (readonly)
Returns the value of attribute running.
29 30 31 |
# File 'lib/QuickBaseWebClient.rb', line 29 def running @running end |
#runNow ⇒ Object (readonly)
Returns the value of attribute runNow.
29 30 31 |
# File 'lib/QuickBaseWebClient.rb', line 29 def runNow @runNow end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
29 30 31 |
# File 'lib/QuickBaseWebClient.rb', line 29 def thread @thread end |
Instance Method Details
#start(ipAddress = 'localhost', port = 2358) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/QuickBaseWebClient.rb', line 51 def start( ipAddress = 'localhost', port = 2358 ) stop if @running @ipAddress, @port = ipAddress, port @thread = Thread.new { begin server = TCPServer.new( ipAddress, port ) @running = true puts "------ #{Time.now} ------" puts "------ Web client started on #{ipAddress}:#{port} ------" while ( session = server.accept ) request = session.gets puts "------ #{Time.now} ------" puts "Request: #{request}" if request.include?( " /qbc/" ) commandFile = "" requestParts = request.split( " " ) requestParts.each{ |requestPart| if requestPart.include?( "/qbc/" ) commandFile = requestPart.split( "/" ).last end } if commandFile.length > 1 and FileTest.readable?( commandFile ) puts "------ Attempting to run '#{commandFile}'." run( commandFile ) puts "------ Finished running command file '#{commandFile}'." session.print "HTTP/1.1 200/OK\r\nContent-type: text/html\r\n\r\n" session.print "<html><head><META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\"></META></head><body><h1>" session.print "Finished running command file '#{commandFile}'.<br>Please press the browser's Back button" session.print "</h1></body></html>\r\n" else puts "------ '#{commandFile}' is not a valid command file." session.print "HTTP/1.1 200/OK\r\nContent-type: text/html\r\n\r\n" session.print "<html><head><META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\"></META></head><body><h1>'#{commandFile}' is not a valid command file.</h1></body></html>\r\n" end session.close elsif not request.include?( "GET /favicon.ico " ) session.print "HTTP/1.1 200/OK\r\nContent-type: text/html\r\n\r\n" session.print "<html><head><META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\"></META></head><body><h1>Invalid request.</h1></body></html>\r\n" session.close stop() end end rescue StandardError => e puts "Error: #{e}" end } @thread.join @running end |
#stop ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/QuickBaseWebClient.rb', line 42 def stop() if @running and @thread puts "------ #{Time.now} ------" puts "------ Web client stopped ------" Thread.kill( @thread ) @doStop = @running = @thread = nil end end |