Class: OpenAgent::MessageBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/openagent/message_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent, zone) ⇒ MessageBuilder

Returns a new instance of MessageBuilder.



8
9
10
11
# File 'lib/openagent/message_builder.rb', line 8

def initialize(agent, zone)
  @agent = agent
  @zone = zone
end

Instance Attribute Details

#guuid=(value) ⇒ Object

Sets the attribute guuid

Parameters:

  • value

    the value to set the attribute guuid to.



6
7
8
# File 'lib/openagent/message_builder.rb', line 6

def guuid=(value)
  @guuid = value
end

#timestamp=(value) ⇒ Object

Sets the attribute timestamp

Parameters:

  • value

    the value to set the attribute timestamp to.



6
7
8
# File 'lib/openagent/message_builder.rb', line 6

def timestamp=(value)
  @timestamp = value
end

Instance Method Details

#ack(original_source_id, original_msg_id, code = 1) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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 = {}) ⇒ Object



28
29
30
31
32
33
34
# 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 = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
# 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 = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 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) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# 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_aclObject



170
171
172
# File 'lib/openagent/message_builder.rb', line 170

def get_agent_acl
  system_control(SIF::Infra::Message::GetAgentACL.new)
end

#get_messageObject



162
163
164
# File 'lib/openagent/message_builder.rb', line 162

def get_message
  system_control(SIF::Infra::Message::GetMessage.new)
end

#get_zone_statusObject



166
167
168
# File 'lib/openagent/message_builder.rb', line 166

def get_zone_status
  system_control(SIF::Infra::Message::GetZoneStatus.new)
end

#pingObject



150
151
152
# File 'lib/openagent/message_builder.rb', line 150

def ping
  system_control(SIF::Infra::Message::Ping.new)
end

#provisionObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# 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

#registerObject



126
127
128
129
130
131
132
133
134
135
136
137
138
# 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 = {}) ⇒ Object

conds should = :conditions=>[{:type=>“None”, :element=>“@SchoolYear”, :value=>“2014”, :operator=>“EQ”]}



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# 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

#sleepObject



154
155
156
# File 'lib/openagent/message_builder.rb', line 154

def sleep
  system_control(SIF::Infra::Message::Sleep.new)
end

#unregisterObject



140
141
142
143
144
145
146
147
148
# 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

#wakeupObject



158
159
160
# File 'lib/openagent/message_builder.rb', line 158

def wakeup
  system_control(SIF::Infra::Message::Wakeup.new)
end