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



27
28
29
30
31
32
33
# File 'lib/openagent/message_builder.rb', line 27

def condition(cond={})
    SIF::Infra::Common::Condition.new(
        :element => cond['element'],
        :value => cond['value'],
        :operator => cond['operator']
    )
end

#conditions(condition_arr = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/openagent/message_builder.rb', line 35

def conditions(condition_arr={})
  return false if condition_arr.count == 0
  condition_arr.map do |c|
#        require 'pry' ; binding.pry
    SIF::Infra::Common::Conditions.new(
        :type => c['cond_type'],
        :condition => condition(c)
    )
  end
end

#conditions_group(condition_arr = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/openagent/message_builder.rb', line 45

def conditions_group(condition_arr={})
  return false if condition_arr.nil? || condition_arr['conditions'].count == 0
  if condition_arr['conditions'].count == 1
    SIF::Infra::Common::ConditionGroup.new(
      :type => 'None',
      :conditions => conditions(condition_arr['conditions'])
      )
  else
    SIF::Infra::Common::ConditionGroup.new(
      :type => condition_arr['group_type'],
      :conditions => conditions(condition_arr['conditions'])
      )
  end
end

#event(object_name, action = 'Change', object_model = nil) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/openagent/message_builder.rb', line 79

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



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

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

#get_messageObject



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

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

#get_zone_statusObject



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

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

#pingObject



145
146
147
# File 'lib/openagent/message_builder.rb', line 145

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

#provisionObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/openagent/message_builder.rb', line 96

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



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/openagent/message_builder.rb', line 121

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

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



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/openagent/message_builder.rb', line 61

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



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

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

#unregisterObject



135
136
137
138
139
140
141
142
143
# File 'lib/openagent/message_builder.rb', line 135

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



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

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