Class: SiriProxy::PluginManager
- Inherits:
-
Cora
- Object
- Cora
- SiriProxy::PluginManager
- Defined in:
- lib/siriproxy/plugin_manager.rb
Instance Attribute Summary collapse
-
#guzzoni_conn ⇒ Object
Returns the value of attribute guzzoni_conn.
-
#iphone_conn ⇒ Object
Returns the value of attribute iphone_conn.
-
#plugins ⇒ Object
Returns the value of attribute plugins.
Instance Method Summary collapse
-
#initialize ⇒ PluginManager
constructor
A new instance of PluginManager.
- #load_plugins ⇒ Object
- #log(text) ⇒ Object
- #no_matches ⇒ Object
- #process(text) ⇒ Object
- #process_filters(object, direction) ⇒ Object
- #respond(text, options = {}) ⇒ Object
- #send_request_complete_to_iphone ⇒ Object
Constructor Details
#initialize ⇒ PluginManager
Returns a new instance of PluginManager.
7 8 9 |
# File 'lib/siriproxy/plugin_manager.rb', line 7 def initialize() load_plugins() end |
Instance Attribute Details
#guzzoni_conn ⇒ Object
Returns the value of attribute guzzoni_conn.
5 6 7 |
# File 'lib/siriproxy/plugin_manager.rb', line 5 def guzzoni_conn @guzzoni_conn end |
#iphone_conn ⇒ Object
Returns the value of attribute iphone_conn.
5 6 7 |
# File 'lib/siriproxy/plugin_manager.rb', line 5 def iphone_conn @iphone_conn end |
#plugins ⇒ Object
Returns the value of attribute plugins.
5 6 7 |
# File 'lib/siriproxy/plugin_manager.rb', line 5 def plugins @plugins end |
Instance Method Details
#load_plugins ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/siriproxy/plugin_manager.rb', line 11 def load_plugins() @plugins = [] if $APP_CONFIG.plugins $APP_CONFIG.plugins.each do |pluginConfig| begin if pluginConfig.is_a? String className = pluginConfig requireName = "siriproxy-#{className.downcase}" else className = pluginConfig['name'] requireName = pluginConfig['require'] || "siriproxy-#{className.downcase}" end require requireName plugin = SiriProxy::Plugin.const_get(className).new(pluginConfig) plugin.plugin_name = className plugin.manager = self @plugins << plugin rescue Exception=>e if pluginConfig['name'] puts "[Error] Failed to load plugin: #{pluginConfig['name']} reason: #{e.}" else puts "[Error] Failed to load a plugin that has no name, check your config.yml" end end end end log "Plugins loaded: #{@plugins.join(', ')}" end |
#log(text) ⇒ Object
84 85 86 |
# File 'lib/siriproxy/plugin_manager.rb', line 84 def log(text) puts "[Info - Plugin Manager] #{text}" if $LOG_LEVEL >= 1 end |
#no_matches ⇒ Object
80 81 82 |
# File 'lib/siriproxy/plugin_manager.rb', line 80 def no_matches return false end |
#process(text) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/siriproxy/plugin_manager.rb', line 58 def process(text) begin result = super(text) self.guzzoni_conn.block_rest_of_session if result return result rescue Exception=>e log "Plugin Crashed: #{e}" respond e.to_s, spoken: "a plugin crashed" return true end end |
#process_filters(object, direction) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/siriproxy/plugin_manager.rb', line 40 def process_filters(object, direction) object_class = object.class #This way, if we change the object class we won't need to modify this code. if object['class'] == 'SetRequestOrigin' properties = object['properties'] set_location(properties['latitude'], properties['longitude'], properties) end plugins.each do |plugin| #log "Processing filters on #{plugin} for '#{object["class"]}'" new_obj = plugin.process_filters(object, direction) object = new_obj if(new_obj == false || new_obj.class == object_class) #prevent accidental poorly formed returns return nil if object == false #if any filter returns "false," then the object should be dropped end return object end |
#respond(text, options = {}) ⇒ Object
76 77 78 |
# File 'lib/siriproxy/plugin_manager.rb', line 76 def respond(text, ={}) self.guzzoni_conn.inject_object_to_output_stream(generate_siri_utterance(self.guzzoni_conn.last_ref_id, text, ([:spoken] or text), [:prompt_for_response] == true)) end |
#send_request_complete_to_iphone ⇒ Object
70 71 72 73 74 |
# File 'lib/siriproxy/plugin_manager.rb', line 70 def send_request_complete_to_iphone log "Sending Request Completed" object = generate_request_completed(self.guzzoni_conn.last_ref_id) self.guzzoni_conn.inject_object_to_output_stream(object) end |