Sirportly

Toggle Menu

Callbacks

Callbacks allow you to run code at various points of an object's lifecycle. For example, you may wish to execute code whenever a new ticket update is created or each time a user's properties are changed.

In order to add a callback to your module, you should define the following within your module class.

class Hipchat < Module

  add_callback :after, :ticket_update, :create do |config, ticket_update|
    ## All code in this block will be executed after a ticket update is created.
    ##
    ## As the :delayed => true options is present, this method will be executed by
    ## the Sirportly worker rather than in the live thread. All background scheduling
    ## is handled for you. If no :delayed option is present, the request will be run
    ## in the same thread which executed the requested action.
  end

end

Using add_callback

The add_callback method takes three parameters, all three should be passed as Ruby symbols:

  • The first parameter is when you wish the action to take place. This should either be :before or :after.
  • The second parameter is which object you wish to watch. This should be one of the following:
    • customer
    • follow_up
    • ticket
    • ticket_checklist_item
    • ticket_update
    • user
  • The third parameter is the actual action you wish to watch. This should one of: :create, :update or :destroy.

The block will be passed two objects, the config which will be a hash of the configuration data entered by the user with the keys as symbols relating to the parameters you configured in config_options. The second is the object which was associated with the event.