Class: Sumac::Message::Exchange::CallResponse

Inherits:
Base show all
Includes:
ID
Defined in:
lib/sumac/message/exchange/call_response.rb

Instance Method Summary collapse

Methods included from ID

#id, #id=

Methods inherited from Base

from_json_structure

Methods inherited from Sumac::Message::Exchange

from_json_structure

Methods inherited from Sumac::Message

from_json, #to_json

Constructor Details

#initialize(connection) ⇒ CallResponse



7
8
9
10
11
# File 'lib/sumac/message/exchange/call_response.rb', line 7

def initialize(connection)
  super
  @return_value = nil
  @exception = nil
end

Instance Method Details

#exceptionObject

Raises:



57
58
59
60
# File 'lib/sumac/message/exchange/call_response.rb', line 57

def exception
  raise MessageError unless setup?
  @exception == nil ? nil : @exception.to_native_object
end

#exception=(new_exception_value) ⇒ Object

Raises:



62
63
64
65
66
# File 'lib/sumac/message/exchange/call_response.rb', line 62

def exception=(new_exception_value)
  raise unless @return_value == nil
  @exception = Object.from_native_object(@connection, new_exception_value)
  raise MessageError unless @exception.class.one_of?(Object::Exception, Object::NativeException)
end

#invert_orginObject

Raises:



68
69
70
71
72
# File 'lib/sumac/message/exchange/call_response.rb', line 68

def invert_orgin
  raise MessageError unless setup?
  @return_value.invert_orgin if @return_value.respond_to?(:invert_orgin)
  nil
end

#parse_json_structure(json_structure) ⇒ Object

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sumac/message/exchange/call_response.rb', line 13

def parse_json_structure(json_structure)
  raise MessageError unless json_structure.is_a?(Hash) &&
    json_structure['message_type'] == 'exchange' &&
    json_structure['exchange_type'] == 'call_response'
  raise MessageError unless json_structure['id'].is_a?(Integer)
  @id = json_structure['id']
  case
  when json_structure['return_value'] && !json_structure['exception']
    @return_value = Object.from_json_structure(@connection, json_structure['return_value'])
  when !json_structure['return_value'] && json_structure['exception']
    @exception = Object.from_json_structure(@connection, json_structure['exception'])
    raise MessageError unless @exception.class.one_of?(Object::Exception, Object::NativeException)
  else
    raise MessageError
  end
  nil
end

#return_valueObject

Raises:



47
48
49
50
# File 'lib/sumac/message/exchange/call_response.rb', line 47

def return_value
  raise MessageError unless setup?
  @return_value == nil ? nil : @return_value.to_native_object
end

#return_value=(new_return_value) ⇒ Object



52
53
54
55
# File 'lib/sumac/message/exchange/call_response.rb', line 52

def return_value=(new_return_value)
  raise unless @exception == nil
  @return_value = Object.from_native_object(@connection, new_return_value)
end

#to_json_structureObject

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sumac/message/exchange/call_response.rb', line 31

def to_json_structure
  raise MessageError unless setup?
  json_structure =
    {
      'message_type' => 'exchange',
      'exchange_type' => 'call_response',
      'id' => @id
    }
  if @return_value
    json_structure['return_value'] = @return_value.to_json_structure
  else
    json_structure['exception'] = @exception.to_json_structure
  end
  json_structure
end