Class: HipTail::Manager
- Inherits:
-
Object
- Object
- HipTail::Manager
- Defined in:
- lib/hiptail/manager.rb
Defined Under Namespace
Classes: AuthorityManager
Instance Attribute Summary collapse
-
#authority ⇒ HipTail::Manager::AuthorityManager
readonly
Retrieves authority from oauth_id.
- #authority_provider ⇒ HipTail::AuthorityProvider
Instance Method Summary collapse
-
#handle_event(params) ⇒ void
Handles events (room_message, room_enter, etc.).
-
#handle_install(params) ⇒ void
Handles installing request.
-
#handle_uninstall(oauth_id) ⇒ void
Handles uninstalling request.
-
#initialize(params = {}) ⇒ HipTail::Manager
constructor
A new instance of HipTail::Manager.
-
#on_event(*args) {|event| ... } ⇒ String
Registers hook on events.
-
#on_install(*args) {|authority| ... } ⇒ String
Registers hook on installation.
-
#on_room_enter(*args) {|event| ... } ⇒ String
Registers hook on room_enter event.
-
#on_room_exit(*args) {|event| ... } ⇒ String
Registers hook on room_exit event.
-
#on_room_message(*args) {|event| ... } ⇒ String
Registers hook on room_message event.
-
#on_room_messaging(*args) {|event| ... } ⇒ String
Registers hook on messaging events (room_message and room_notification).
-
#on_room_notification(*args) {|event| ... } ⇒ String
Registers hook on room_notification event.
-
#on_room_topic_change(*args) {|event| ... } ⇒ String
Registers hook on room_topic_change event.
-
#on_room_visiting(*args) {|event| ... } ⇒ String
Registers hook on room visiting event (room_enter and room_exit).
-
#on_uninstall(*args) {|oauth_id| ... } ⇒ String
Registers hook on uninstallation.
-
#register_hook(hook_type, args, block) ⇒ String
Registers a hook.
Constructor Details
#initialize(params = {}) ⇒ HipTail::Manager
A new instance of HipTail::Manager.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hiptail/manager.rb', line 15 def initialize(params = {}) @authority_provider = params[:authority_provider] || MemoryAuthorityProvider.new @authority_manager = AuthorityManager.new(@authority_provider) @hook = {} [ :install, :uninstall, :event, :room_messaging, :room_message, :room_notification, :room_topic_change, :room_visiting, :room_enter, :room_exit, ].each do |hook_type| @hook[hook_type] = {} end end |
Instance Attribute Details
#authority ⇒ HipTail::Manager::AuthorityManager (readonly)
Retrieves authority from oauth_id
46 47 48 |
# File 'lib/hiptail/manager.rb', line 46 def @authority_manager end |
#authority_provider ⇒ HipTail::AuthorityProvider
33 34 35 |
# File 'lib/hiptail/manager.rb', line 33 def @authority_provider end |
Instance Method Details
#handle_event(params) ⇒ void
This method returns an undefined value.
Handles events (room_message, room_enter, etc.).
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/hiptail/manager.rb', line 155 def handle_event(params) event = Event.parse(params) event. = self.[event.oauth_client_id] call_hooks :event, event if event.is_a?(Event::RoomMessaging) call_hooks :room_messaging, event case event when Event::RoomMessage call_hooks :room_message, event when Event::RoomNotification call_hooks :room_notification, event end elsif event.is_a?(Event::RoomTopicChange) call_hooks :room_topic_change, event elsif event.is_a?(Event::RoomVisiting) call_hooks :room_visiting, event case event when Event::RoomEnter call_hooks :room_enter, event when Event::RoomExit call_hooks :room_exit, event end end end |
#handle_install(params) ⇒ void
This method returns an undefined value.
Handles installing request.
133 134 135 136 137 138 139 |
# File 'lib/hiptail/manager.rb', line 133 def handle_install(params) = (params) @authority_provider.register(.oauth_id, ) call_hooks :install, end |
#handle_uninstall(oauth_id) ⇒ void
Uninstall event will be fired after uninstallation on the server. So you cannot use oauth information to do something (e.g. sending notification) on uninstallation phase.
This method returns an undefined value.
Handles uninstalling request.
146 147 148 149 150 |
# File 'lib/hiptail/manager.rb', line 146 def handle_uninstall(oauth_id) call_hooks :uninstall, oauth_id @authority_provider.unregister(oauth_id) end |
#on_event(*args) {|event| ... } ⇒ String
Registers hook on events.
70 71 72 |
# File 'lib/hiptail/manager.rb', line 70 def on_event(*args, &block) register_hook :event, args, block end |
#on_install(*args) {|authority| ... } ⇒ String
Registers hook on installation.
54 55 56 |
# File 'lib/hiptail/manager.rb', line 54 def on_install(*args, &block) register_hook :install, args, block end |
#on_room_enter(*args) {|event| ... } ⇒ String
Registers hook on room_enter event.
118 119 120 |
# File 'lib/hiptail/manager.rb', line 118 def on_room_enter(*args, &block) register_hook :room_enter, args, block end |
#on_room_exit(*args) {|event| ... } ⇒ String
Registers hook on room_exit event.
126 127 128 |
# File 'lib/hiptail/manager.rb', line 126 def on_room_exit(*args, &block) register_hook :room_exit, args, block end |
#on_room_message(*args) {|event| ... } ⇒ String
Registers hook on room_message event.
86 87 88 |
# File 'lib/hiptail/manager.rb', line 86 def (*args, &block) register_hook :room_message, args, block end |
#on_room_messaging(*args) {|event| ... } ⇒ String
Registers hook on messaging events (room_message and room_notification).
78 79 80 |
# File 'lib/hiptail/manager.rb', line 78 def on_room_messaging(*args, &block) register_hook :room_messaging, args, block end |
#on_room_notification(*args) {|event| ... } ⇒ String
Registers hook on room_notification event.
94 95 96 |
# File 'lib/hiptail/manager.rb', line 94 def on_room_notification(*args, &block) register_hook :room_notification, args, block end |
#on_room_topic_change(*args) {|event| ... } ⇒ String
Registers hook on room_topic_change event.
102 103 104 |
# File 'lib/hiptail/manager.rb', line 102 def on_room_topic_change(*args, &block) register_hook :room_topic_change, args, block end |
#on_room_visiting(*args) {|event| ... } ⇒ String
Registers hook on room visiting event (room_enter and room_exit).
110 111 112 |
# File 'lib/hiptail/manager.rb', line 110 def on_room_visiting(*args, &block) register_hook :room_visiting, args, block end |
#on_uninstall(*args) {|oauth_id| ... } ⇒ String
Registers hook on uninstallation.
62 63 64 |
# File 'lib/hiptail/manager.rb', line 62 def on_uninstall(*args, &block) register_hook :uninstall, args, block end |
#register_hook(hook_type, args, block) ⇒ String
Registers a hook.
189 190 191 192 193 |
# File 'lib/hiptail/manager.rb', line 189 def register_hook(hook_type, args, block) priority = args.size > 0 ? args.shift : 100 @hook[hook_type][priority] ||= [] @hook[hook_type][priority] << block end |