class OpenAgent::MessageBuilder
Attributes
guuid[W]
timestamp[W]
Public Class Methods
new(agent, zone)
click to toggle source
# File lib/openagent/message_builder.rb, line 8 def initialize(agent, zone) @agent = agent @zone = zone end
Public Instance Methods
ack(original_source_id, original_msg_id, code=1)
click to toggle source
# File lib/openagent/message_builder.rb, line 13 def ack(original_source_id, original_msg_id, code=1) SIF::Infra::Common::Message.new( :version => @agent.msg_version, :xmlns => @agent.msg_xmlns, :ack => SIF::Infra::Message::Ack.new( :header => create_header, :original_source_id => original_source_id, :original_msg_id => original_msg_id, :status => SIF::Infra::Common::Status.new( :code => code ) ) ) end
condition(cond={})
click to toggle source
# File lib/openagent/message_builder.rb, line 28 def condition(cond={}) SIF::Infra::Common::Condition.new( :element => cond['element'], :value => cond['value'], :operator => cond['operator'] ) end
conditions(conds={})
click to toggle source
# File lib/openagent/message_builder.rb, line 36 def conditions(conds={}) return false if conds.empty? conds.map do |c| SIF::Infra::Common::Conditions.new( :type => c['cond_type'], :condition => condition(c) ) end end
conditions_group(conds={})
click to toggle source
# File lib/openagent/message_builder.rb, line 46 def conditions_group(conds={}) return false if conds.nil? || conds['conditions'].nil? case conds['conditions'].size when 0 return false when 1 SIF::Infra::Common::ConditionGroup.new( :type => 'None', :conditions => conditions(conds['conditions']) ) else SIF::Infra::Common::ConditionGroup.new( :type => conds['group_type'], :conditions => conditions(conds['conditions']) ) end end
event(object_name, action='Change', object_model=nil)
click to toggle source
# File lib/openagent/message_builder.rb, line 84 def event(object_name, action='Change', object_model=nil) SIF::Infra::Common::Message.new( :version => @agent.msg_version, :xmlns => @agent.msg_xmlns, :event => SIF::Infra::Message::Event.new( :header => create_header, :object_data => SIF::Infra::Common::ObjectData.new( :event_object => SIF::Infra::Common::EventObject.new( :object_name => object_name, :action => action, :object => object_model ) ) ) ) end
get_agent_acl()
click to toggle source
# File lib/openagent/message_builder.rb, line 170 def get_agent_acl system_control(SIF::Infra::Message::GetAgentACL.new) end
get_message()
click to toggle source
# File lib/openagent/message_builder.rb, line 162 def get_message system_control(SIF::Infra::Message::GetMessage.new) end
get_zone_status()
click to toggle source
# File lib/openagent/message_builder.rb, line 166 def get_zone_status system_control(SIF::Infra::Message::GetZoneStatus.new) end
ping()
click to toggle source
# File lib/openagent/message_builder.rb, line 150 def ping system_control(SIF::Infra::Message::Ping.new) end
provision()
click to toggle source
# File lib/openagent/message_builder.rb, line 101 def provision object = SIF::Infra::Common::Object SIF::Infra::Common::Message.new( :version => @agent.msg_version, :xmlns => @agent.msg_xmlns, :provision => SIF::Infra::Common::Provision.new( :header => create_header, :subscribe_objects => (@agent.subscribe || []).map { |o| object.new(:object_name => o) }, :provide_objects => (@agent.provide || []).map { |o| object.new(:object_name => o) }, :request_objects => (@agent.request || []).map { |o| object.new(:object_name => o) }, :respond_objects => (@agent.respond || []).map { |o| object.new(:object_name => o) }, :publish_add_objects => (@agent.publish_add || []).map { |o| object.new(:object_name => o) }, :publish_change_objects => (@agent.publish_change || []).map { |o| object.new(:object_name => o) }, :publish_delete_objects => (@agent.publish_delete || []).map { |o| object.new(:object_name => o) }, ) ) end
register()
click to toggle source
# File lib/openagent/message_builder.rb, line 126 def register SIF::Infra::Common::Message.new( :version => @agent.msg_version, :xmlns => @agent.msg_xmlns, :register => SIF::Infra::Message::Register.new( :name => @agent.name, :version => @agent.version, :max_buffer_size => @agent.max_buffer_size, :mode => @agent.mode, :header => create_header ) ) end
request(object_name, condition_arr={})
click to toggle source
conds should = {:type=>“None”, :conditions=>[{:type=>“None”, :element=>“@SchoolYear”, :value=>“2014”, :operator=>“EQ”}]}
# File lib/openagent/message_builder.rb, line 66 def request(object_name, condition_arr={}) SIF::Infra::Common::Message.new( :version => @agent.msg_version, :xmlns => @agent.msg_xmlns, :request => SIF::Infra::Message::Request.new( :version => @agent.version, :max_buffer_size => @agent.max_buffer_size, :header => create_header, :query => SIF::Infra::Common::Query.new( :query_object => SIF::Infra::Common::QueryObject.new( :object_name => object_name ), :condition_group => conditions_group(condition_arr) ) ) ) end
sleep()
click to toggle source
# File lib/openagent/message_builder.rb, line 154 def sleep system_control(SIF::Infra::Message::Sleep.new) end
unregister()
click to toggle source
# File lib/openagent/message_builder.rb, line 140 def unregister SIF::Infra::Common::Message.new( :version => @agent.msg_version, :xmlns => @agent.msg_xmlns, :unregister => SIF::Infra::Message::Unregister.new( :header => create_header ) ) end
wakeup()
click to toggle source
# File lib/openagent/message_builder.rb, line 158 def wakeup system_control(SIF::Infra::Message::Wakeup.new) end
Protected Instance Methods
create_header()
click to toggle source
# File lib/openagent/message_builder.rb, line 184 def create_header SIF::Infra::Common::Header.new( :msg_id => guuid(), :source_id => @agent.source_id, :timestamp => timestamp() ) end
guuid()
click to toggle source
# File lib/openagent/message_builder.rb, line 180 def guuid @guuid || UUID.generate(:compact).upcase end
system_control(message_instance)
click to toggle source
# File lib/openagent/message_builder.rb, line 192 def system_control(message_instance) SIF::Infra::Common::Message.new( :version => @agent.msg_version, :xmlns => @agent.msg_xmlns, :system_control => SIF::Infra::Message::SystemControl.new( :header => create_header, :system_control_data => SIF::Infra::Message::SystemControlData.new( :data => message_instance ) ) ) end
timestamp()
click to toggle source
# File lib/openagent/message_builder.rb, line 176 def timestamp @timestamp || Time.now.strftime('%Y-%m-%dT%H:%M:%S') end