Class: QuickBase::EventNotifier::TableEvent
- Inherits:
-
Object
- Object
- QuickBase::EventNotifier::TableEvent
- Defined in:
- lib/QuickBaseEventNotifier.rb
Overview
A record is added/modified/deleted from a table
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #eventOccurred?(qbc) ⇒ Boolean
-
#initialize(table, eventType = ["recordAdded","recordModified"], application = nil, recordCondition = nil) ⇒ TableEvent
constructor
A new instance of TableEvent.
- #isEventType?(type) ⇒ Boolean
- #tableEventNotificationMessage ⇒ Object
- #validate(qbc) ⇒ Object
- #validateApplicationAndTable(qbc) ⇒ Object
- #validateEventType(eventType) ⇒ Object
- #validateRecordCondition(qbc) ⇒ Object
Constructor Details
#initialize(table, eventType = ["recordAdded","recordModified"], application = nil, recordCondition = nil) ⇒ TableEvent
Returns a new instance of TableEvent.
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/QuickBaseEventNotifier.rb', line 104 def initialize(table, eventType=["recordAdded","recordModified"],application=nil,recordCondition=nil) if eventType.is_a?(String) validateEventType(eventType) elsif eventType.is_a?(Array) eventType.each{|et| validateEventType(et) } end @table,@eventType,@application,@recordCondition=table,eventType,application,recordCondition @lastModifiedTime = 0 @lastRecModTime = 0 @numRecords = 0 @url = "http://www.quickbase.com" end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
102 103 104 |
# File 'lib/QuickBaseEventNotifier.rb', line 102 def url @url end |
Instance Method Details
#eventOccurred?(qbc) ⇒ Boolean
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/QuickBaseEventNotifier.rb', line 196 def eventOccurred?(qbc) query = "" ret = false qbc.getDBInfo(@dbid) if qbc.requestSucceeded if @lastModifiedTime > 0 and qbc.lastModifiedTime.to_i > @lastModifiedTime if isEventType?("recordModified") if qbc.lastRecModTime.to_i > @lastRecModTime query = "{'2'.GT.'#{@lastRecModTime}'}" end end if isEventType?("recordAdded") if qbc.numRecords.to_i > @numRecords if query.length > 0 query << "OR{'1'.GT.'#{@lastModifiedTime}'}" else query = "{'1'.GT.'#{@lastModifiedTime}'}" end end end if isEventType?("recordDeleted") if qbc.numRecords.to_i < @numRecords ret = true end end #puts query if query.length > 0 @records = qbc.getAllValuesForFields(@dbid, "Record ID#", query, nil, nil, "3") puts "Found #{@records.length} records." ret = @records.length > 0 end end @numRecords = qbc.numRecords.to_i @lastModifiedTime = qbc.lastModifiedTime.to_i @lastRecModTime = qbc.lastRecModTime.to_i else raise "Error getting information for table #{@dbid}" end ret end |
#isEventType?(type) ⇒ Boolean
129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/QuickBaseEventNotifier.rb', line 129 def isEventType?(type) ret=false if @eventType.is_a?(String) ret = @eventType == type elsif @eventType.is_a?(Array) @eventType.each{|et| if et == type ret = true break end } end ret end |
#tableEventNotificationMessage ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/QuickBaseEventNotifier.rb', line 237 def tableEventNotificationMessage = "Records have been " if isEventType?("recordAdded") eventTypeMessage = "added" else eventTypeMessage = "" end if isEventType?("recordModified") if eventTypeMessage.length > 0 eventTypeMessage << " or modified" else eventTypeMessage = "modified" end end if isEventType?("recordDeleted") if eventTypeMessage.length > 0 eventTypeMessage << "or deleted" else eventTypeMessage = "deleted" end end << eventTypeMessage << " in the '#{@tableName}' QuickBase table." return @tableName, end |
#validate(qbc) ⇒ Object
189 190 191 192 193 194 |
# File 'lib/QuickBaseEventNotifier.rb', line 189 def validate(qbc) if validateApplicationAndTable(qbc) validateRecordCondition(qbc) end true end |
#validateApplicationAndTable(qbc) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/QuickBaseEventNotifier.rb', line 144 def validateApplicationAndTable(qbc) if @application and @application.length > 0 @table = @application if @table.nil? qbc.findDBByName(@application) if qbc.requestSucceeded qbc.lookupChdbid(@table) if qbc.requestSucceeded @dbid = qbc.dbid.dup qbc._getSchema @tablename = @table.dup end end elsif @table and @table.length > 0 qbc.getSchema(@table) if qbc.requestSucceeded @dbid = qbc.dbid.dup @tableName = qbc.getResponseElement( "table/name" ).text end else raise "table and/or application must be specified" end raise "Error retrieving schema for table #{@table}" if @dbid.nil? @url = "https://www.quickbase.com/db/#{@dbid}" @dbid end |
#validateEventType(eventType) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/QuickBaseEventNotifier.rb', line 117 def validateEventType(eventType) if @validEventTypes.nil? @validEventTypes = Array.new @validEventTypes << "recordAdded" @validEventTypes << "recordModified" @validEventTypes << "recordDeleted" end if ! (eventType.is_a?(String) and @validEventTypes.include?(eventType)) raise "Invalid event type '#{eventType}'." end end |
#validateRecordCondition(qbc) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/QuickBaseEventNotifier.rb', line 170 def validateRecordCondition(qbc) if @recordCondition if @recordCondition.is_a?(RecordCondition) @recordCondition.validate(qbc,@dbid) elsif @recordCondition.is_a?(Array) @recordCondition.each{|rc| if rc.is_a?(RecordCondition) rc.validate(qbc,@dbid) else raise "recordcondition must be a RecordCondition or Array of RecordConditions" end } else raise "recordcondition must be a RecordCondition or Array of RecordConditions" end end true end |