require 'QuickBaseClient' require 'cgi' if ARGV.length < 2 puts "\n Usage: ruby downloadCookbook.rb \n" puts "\n This script copies the recipes from the QuickBase API Cookbook to your local drive.\n" exit end qbc = QuickBase::Client.new( ARGV[0], ARGV[1] ) fieldsToDownload = [ "Record ID#", "Title", "Keywords", "Problem", "Solution", "Discussion", "See Also", "File Attachment", "Ingredient 1", "Ingredient 2", "Ingredient 3", "Chef" ] # this is the original QuickBase API Cookbook v3 recipes table fieldValues = qbc.getAllValuesForFields( "bcdcajmrg", fieldsToDownload, nil, nil, "List All" ) numRecs = fieldValues[ "Record ID#" ].length cwd=Dir.getwd fileprefix = "#{cwd}/cookbookfiles/" Dir.mkdir( fileprefix ) if !File.exists?( fileprefix ) Dir.chdir( fileprefix ) File.open( "QuickBaseAPICookbook.html", "w" ) { |outputFile | outputFile.write( "QuickBase API Cookbook v3

QuickBase API Cookbook v3

" ) (0..numRecs.to_i-1).each{ |i| link = "" title = "" keywords = "" problem = "" solution = "" discussion ="" seeAlso = "" file = "" ingredient1 = "" ingredient2 = "" ingredient3 = "" chef = "" recordID = "" fieldValues.each { |fieldName,valueArray| # get the value of fieldName in record i value = valueArray[i] value.gsub!("
","\n") case fieldName when "Record ID#" link = "https://www.quickbase.com/db/bcdcajmrg?a=dr&rid=#{value}" recordID = value.dup when "Title" then title = "#{CGI.escapeHTML(value)}" when "Keywords" then keywords = "

Keywords

#{CGI.escapeHTML(value)}
" when "Problem" then problem = "

Problem:

#{CGI.escapeHTML(value)}
" when "Solution" then solution = "

Solution:

#{CGI.escapeHTML(value)}

" when "Discussion" then discussion = "

Discussion:

#{CGI.escapeHTML(value)}
" when "See Also" then seeAlso = "

See Also:

#{CGI.escapeHTML(value)}
" when "File Attachment" if value.length > 0 fileToWrite = "#{fileprefix}#{value}" #file = "

File Attachment:

#{fileprefix}#{value}
" file = "

File Attachment:

#{value}
" qbc.downLoadFile(qbc.dbid, recordID, "12" ) fileContents = qbc.fileContents.dup if fileContents.length > 0 fileContents.gsub!( "\r\n", "\n" ) File.open( fileToWrite, "w" ){|f|f.write(fileContents) } end end when "Ingredient 1" then ingredient1 = "

Ingredients:

#{CGI.escapeHTML(value)}, " when "Ingredient 2" then ingredient2 = "#{CGI.escapeHTML(value)}, " when "Ingredient 3" then ingredient3 = "#{CGI.escapeHTML(value)}
" when "Chef" then chef = "

Chef:

#{CGI.escapeHTML(value)}
" end } title = "

#{title}" outputFile.write( title ) outputFile.write( keywords ) outputFile.write( problem ) outputFile.write( solution ) outputFile.write( discussion ) outputFile.write( seeAlso ) outputFile.write( file ) outputFile.write( ingredient1) outputFile.write( ingredient2 ) outputFile.write( ingredient3 ) outputFile.write( chef ) outputFile.write( "
" ) } outputFile.write( "" ) }