class SebElink::Message

Constants

SUPPORTED_MESSAGES
SUPPORTED_VERSIONS

Attributes

data_hash[R]
gateway_instance[R]
message_code[R]

Public Class Methods

new(gateway_instance, message_code, data_hash) click to toggle source
# File lib/seb_elink/message.rb, line 9
def initialize(gateway_instance, message_code, data_hash)
  @gateway_instance = gateway_instance

  @message_code = message_code

  validate_message_code

  @data_hash = gateway_instance.defaults.
    merge(IB_SERVICE: @message_code).merge(data_hash)

  validate_version
end

Public Instance Methods

digital_signature() click to toggle source
# File lib/seb_elink/message.rb, line 22
def digital_signature
  @digital_signature ||= to_h[:IB_CRC]
end
to_h() click to toggle source
# File lib/seb_elink/message.rb, line 26
def to_h
  @to_h ||= send("message_#{message_code}")
end

Private Instance Methods

message_0002() click to toggle source
# File lib/seb_elink/message.rb, line 32
def message_0002
  footprint_string = gateway_instance.produce_footprint({
    message_code: message_code,
    version: version,
    skip_validation: false,
    data: data_hash
  })

  # 3. Hash-sign the footprint string => obtain "digital signature" of the message
  digital_signature = gateway_instance.sign({
    version: version,
    message_footprint: footprint_string
  })

  # 4. Append IB_CRC key with the "digital signature" and return the hash
  gateway_instance.spec_for(version: version, message_code: message_code).
  keys.each_with_object({}) do |k, hash|
    hash[k] = data_hash[k] if data_hash.has_key?(k)
  end.merge(IB_CRC: digital_signature)
end
version() click to toggle source
# File lib/seb_elink/message.rb, line 53
def version
  return @version if defined?(@version)

  @version = data_hash[:IB_VERSION]
end