Class: QuickBase::Client::FieldValuePairXML
- Inherits:
-
Object
- Object
- QuickBase::Client::FieldValuePairXML
- Defined in:
- lib/broker/client/QuickBaseClient.rb
Overview
Encapsulates field values to be set and file uploads to be made during addRecord() and editRecord() calls.
Instance Attribute Summary collapse
-
#parentClass ⇒ Object
readonly
Returns the value of attribute parentClass.
Instance Method Summary collapse
- #encodeFileContentsForUpload(fileNameOrFileContents) ⇒ Object
-
#initialize(parentClass, name, fid, filename, value) ⇒ FieldValuePairXML
constructor
A new instance of FieldValuePairXML.
- #to_s ⇒ Object
- #verifyFilename(filename) ⇒ Object
Constructor Details
#initialize(parentClass, name, fid, filename, value) ⇒ FieldValuePairXML
Returns a new instance of FieldValuePairXML.
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 |
# File 'lib/broker/client/QuickBaseClient.rb', line 1078 def initialize( parentClass, name, fid, filename, value ) @parentClass = parentClass name = name.downcase if name name = name.gsub( /\W/, "_" ) if name if filename or value @xml = "<field " if name @xml << "name='#{name}'" elsif fid @xml << "fid='#{fid}'" else raise "FieldValuePairXML::initialize: must specify 'name' or 'fid'" end if filename @xml << " filename='#{verifyFilename(filename)}'" end if value if filename value = encodeFileContentsForUpload( value ) else value = @parentClass.encodeXML( value ) end @xml << ">#{value}</field>" elsif filename value = encodeFileContentsForUpload( filename ) @xml << ">#{value}</field>" else @xml << "/>" end else raise "FieldValuePairXML::initialize: must specify 'filename' or 'value'" end end |
Instance Attribute Details
#parentClass ⇒ Object (readonly)
Returns the value of attribute parentClass.
1076 1077 1078 |
# File 'lib/broker/client/QuickBaseClient.rb', line 1076 def parentClass @parentClass end |
Instance Method Details
#encodeFileContentsForUpload(fileNameOrFileContents) ⇒ Object
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 |
# File 'lib/broker/client/QuickBaseClient.rb', line 1124 def encodeFileContentsForUpload( fileNameOrFileContents ) if fileNameOrFileContents if FileTest.readable?( fileNameOrFileContents ) f = File.new( fileNameOrFileContents, "r" ) if f encodedFileContents = "" f.binmode buffer = f.read(60) while buffer encodedFileContents << [buffer].pack('m').tr( "\r\n", '' ) buffer = f.read(60) end f.close return encodedFileContents end elsif fileNameOrFileContents.is_a?( String ) encodedFileContents = "" buffer = fileNameOrFileContents.slice!(0,60) while buffer and buffer.length > 0 buffer = buffer.to_s encodedFileContents << [buffer].pack('m').tr( "\r\n", '' ) buffer = fileNameOrFileContents.slice!(0,60) end return encodedFileContents end end nil end |
#to_s ⇒ Object
1153 1154 1155 |
# File 'lib/broker/client/QuickBaseClient.rb', line 1153 def to_s @xml end |
#verifyFilename(filename) ⇒ Object
1115 1116 1117 1118 1119 1120 1121 1122 |
# File 'lib/broker/client/QuickBaseClient.rb', line 1115 def verifyFilename( filename ) if filename filename.slice!( 0, filename.rindex( '\\' )+1 ) if filename.include?( '\\' ) filename.slice!( 0, filename.rindex( '/' )+1 ) if filename.include?( '/' ) filename = @parentClass.encodeXML( filename ) end filename end |