Class: QuickBase::EventNotifier
- Inherits:
-
Object
- Object
- QuickBase::EventNotifier
- Defined in:
- lib/QuickBaseEventNotifier.rb
Overview
This class maintains a list of QuickBase table changes to watch for, how to be notified of the changes, how frequently to check for the changes and when to start and stop checking. It can stop checking after a specific number of checks, or stop checking after a specific number of successful checks. It can also check for records changes that only meet certain conditions.
Defined Under Namespace
Classes: EventCheckPolicy, EventNotification, Notification, RecordCondition, TableEvent
Instance Attribute Summary collapse
-
#qbc ⇒ Object
Returns the value of attribute qbc.
Class Method Summary collapse
-
.checkOnce(username, password, dbid) ⇒ Object
Simple method to check one time only, 15 minutes from now, then stop.
-
.waitOnce(username, password, dbid) ⇒ Object
Simple method to wait for one QuickBase change then stop.
-
.watch(username, password, dbid) ⇒ Object
Simple method to get messages when records are added or modified in a table.
-
.watch2007Changes(username, password, dbid) ⇒ Object
Simple method to check for records created after 2006 and modified today.
-
.watchAndRunCode(username, password, dbid) ⇒ Object
Simple method to run code when records are added or modified in a table.
Instance Method Summary collapse
-
#addEventNotification(eventNotification) ⇒ Object
class EventNotification.
-
#initialize(qbc = nil, username = nil, password = nil) ⇒ EventNotifier
constructor
A new instance of EventNotifier.
- #launchURL(url) ⇒ Object
-
#notify(notification, url) ⇒ Object
Event occurred: beep and/or show a message on separate thread.
- #showMessage(messageTitle, message, url, launchBrowser) ⇒ Object
-
#startChecking ⇒ Object
Call with a block to run code when an event occurs, or call without a block to show a message and/or beep.
Constructor Details
#initialize(qbc = nil, username = nil, password = nil) ⇒ EventNotifier
Returns a new instance of EventNotifier.
30 31 32 33 34 35 36 37 38 |
# File 'lib/QuickBaseEventNotifier.rb', line 30 def initialize(qbc=nil, username=nil,password=nil) @username,@password = username,password if qbc @qbc = qbc elsif @username and @password @qbc = QuickBase::Client.new(@username,@password) end @eventNotifications = Array.new end |
Instance Attribute Details
#qbc ⇒ Object
Returns the value of attribute qbc.
27 28 29 |
# File 'lib/QuickBaseEventNotifier.rb', line 27 def qbc @qbc end |
Class Method Details
.checkOnce(username, password, dbid) ⇒ Object
Simple method to check one time only, 15 minutes from now, then stop
553 554 555 556 557 558 |
# File 'lib/QuickBaseEventNotifier.rb', line 553 def EventNotifier.checkOnce(username,password,dbid) en = EventNotifier.new(nil,username,password) notification = EventNotification.new(TableEvent.new(dbid),nil,EventCheckPolicy.new(15,nil,nil,1)) en.addEventNotification(notification) en.startChecking end |
.waitOnce(username, password, dbid) ⇒ Object
Simple method to wait for one QuickBase change then stop
561 562 563 564 565 566 |
# File 'lib/QuickBaseEventNotifier.rb', line 561 def EventNotifier.waitOnce(username,password,dbid) en = EventNotifier.new(nil,username,password) notification = EventNotification.new(TableEvent.new(dbid),nil,EventCheckPolicy.new(nil,nil,nil,nil,1)) en.addEventNotification(notification) en.startChecking end |
.watch(username, password, dbid) ⇒ Object
Simple method to get messages when records are added or modified in a table
535 536 537 538 539 540 |
# File 'lib/QuickBaseEventNotifier.rb', line 535 def EventNotifier.watch(username,password,dbid) en = EventNotifier.new(nil,username,password) notification = EventNotification.new(TableEvent.new(dbid)) en.addEventNotification(notification) en.startChecking end |
.watch2007Changes(username, password, dbid) ⇒ Object
Simple method to check for records created after 2006 and modified today
569 570 571 572 573 574 575 576 |
# File 'lib/QuickBaseEventNotifier.rb', line 569 def EventNotifier.watch2007Changes(username,password,dbid) en = EventNotifier.new(nil,username,password) rc = RecordCondition.new("Date Created", "OAF", "01-01-2007") te = TableEvent.new(dbid,"recordModified",nil,rc) notification = EventNotification.new(te) en.addEventNotification(notification) en.startChecking end |
.watchAndRunCode(username, password, dbid) ⇒ Object
Simple method to run code when records are added or modified in a table
543 544 545 546 547 548 549 550 |
# File 'lib/QuickBaseEventNotifier.rb', line 543 def EventNotifier.watchAndRunCode(username,password,dbid) en = EventNotifier.new(nil,username,password) notification = EventNotification.new(TableEvent.new(dbid)) en.addEventNotification(notification) en.startChecking { |eventNotification| yield eventNotification } end |
Instance Method Details
#addEventNotification(eventNotification) ⇒ Object
class EventNotification
421 422 423 |
# File 'lib/QuickBaseEventNotifier.rb', line 421 def addEventNotification(eventNotification) @eventNotifications << eventNotification if eventNotification.validate(@qbc) end |
#launchURL(url) ⇒ Object
525 526 527 528 529 530 531 532 |
# File 'lib/QuickBaseEventNotifier.rb', line 525 def launchURL(url) url.gsub!("&","^&") url = "start #{url}" if RUBY_PLATFORM.split("-")[1].include?("mswin") if !system(url) = "Error launching browser at #{url}." Tk.({"icon"=>"error","title"=>"QuickBase Event Notifier", "message" => }) end end |
#notify(notification, url) ⇒ Object
Event occurred: beep and/or show a message on separate thread
472 473 474 475 476 477 |
# File 'lib/QuickBaseEventNotifier.rb', line 472 def notify(notification,url) Tk.bell if notification.beep if notification. showMessage(notification.title,notification.,url,notification.launchBrowser) end end |
#showMessage(messageTitle, message, url, launchBrowser) ⇒ Object
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
# File 'lib/QuickBaseEventNotifier.rb', line 479 def showMessage(,,url,launchBrowser) = "#{}\n\nLaunch QuickBase?" if url and launchBrowser root = TkRoot.new{ title } frame = TkFrame.new(root){ pack "side" => "top" borderwidth 8 } = TkLabel.new(frame){ text font "Arial 10 bold" pack "side"=>"top" } if url and launchBrowser = TkFrame.new(frame){ pack "side" => "bottom" width 50 } yesButton = TkButton.new(){ text "Yes" font "Arial 10 bold" pack "side"=>"left", "padx"=>5, "pady"=>5 } yesButton.command { launchURL(url) Tk.exit } noButton = TkButton.new(){ text "No" font "Arial 10 bold" pack "side"=>"right","padx"=>5, "pady"=>5 } noButton.command { Tk.exit } else okButton = TkButton.new(frame){ text "OK" font "Arial 10 bold" pack "side"=>"bottom" } okButton.command { Tk.exit } end Tk.mainloop Tk.restart end |
#startChecking ⇒ Object
Call with a block to run code when an event occurs, or call without a block to show a message and/or beep. The loop stops if all event checks are beyond their stop time.
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/QuickBaseEventNotifier.rb', line 428 def startChecking startTime = Time.now firstLoop = true loop { timeNow = Time.now stopChecking = true @eventNotifications.each { |eventNotification| unless eventNotification.stopChecking? stopChecking = false title,=eventNotification.tableEventNotificationMessage if timeNow > eventNotification.nextCheckTime puts "Checking for changes in QuickBase. (#{title} - #{timeNow})" checkSucceeded = false if eventNotification.eventOccurred? checkSucceeded = true if block_given? yield eventNotification else eventNotification.notification.overrideDefaultTitleAndMessage(title,) notify(eventNotification.notification,eventNotification.url) end end eventNotification.setNextCheckTime(false,checkSucceeded) unless eventNotification.stopChecking? checkTimeMessage = "Next check time for '#{title}' will be #{eventNotification.nextCheckTime}." if eventNotification.numSuccessfulChecks > 0 checkTimeMessage << " (#{eventNotification.numSuccessfulChecks } more successful checks will be performed)." elsif eventNotification.numChecks > 0 checkTimeMessage << " (#{eventNotification.numChecks} more checks will be performed)." end puts checkTimeMessage end elsif firstLoop checkTimeMessage = "Next check time for '#{title}' will be #{eventNotification.nextCheckTime}." puts checkTimeMessage end end } firstLoop = false break if stopChecking } end |