Class: ESM::Websocket::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/esm/websocket/request.rb,
lib/esm/websocket/request/overseer.rb

Defined Under Namespace

Classes: Overseer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Request

command: nil, user: nil, channel: nil, parameters: nil, timeout: 30, command_name: nil



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/esm/websocket/request.rb', line 11

def initialize(**args)
  @command = args[:command]
  @user = args[:user]

  # String for direct calls, Otherwise its a command
  @command_name = args[:command_name].presence || @command.name

  @user_info =
    if @user.nil?
      ["", ""]
    else
      [@user.mention, @user.id]
    end

  @channel = args[:channel]
  @parameters = args[:parameters]
  @id = SecureRandom.uuid
  @timeout = args[:timeout] || 30
  @created_at = ::Time.zone.now

  # This controls if the request should be removed on the first reply back from Arma.
  @remove_on_ignore = args[:remove_on_ignore] || false
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



6
7
8
# File 'lib/esm/websocket/request.rb', line 6

def channel
  @channel
end

#commandObject (readonly)

Returns the value of attribute command.



6
7
8
# File 'lib/esm/websocket/request.rb', line 6

def command
  @command
end

#command_nameObject (readonly)

Returns the value of attribute command_name.



7
8
9
# File 'lib/esm/websocket/request.rb', line 7

def command_name
  @command_name
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/esm/websocket/request.rb', line 6

def id
  @id
end

#remove_on_ignoreObject (readonly)

Returns the value of attribute remove_on_ignore.



6
7
8
# File 'lib/esm/websocket/request.rb', line 6

def remove_on_ignore
  @remove_on_ignore
end

#responseObject

Returns the value of attribute response.



8
9
10
# File 'lib/esm/websocket/request.rb', line 8

def response
  @response
end

#userObject (readonly)

Returns the value of attribute user.



6
7
8
# File 'lib/esm/websocket/request.rb', line 6

def user
  @user
end

#user_infoObject (readonly)

Returns the value of attribute user_info.



7
8
9
# File 'lib/esm/websocket/request.rb', line 7

def 
  @user_info
end

Instance Method Details

#on_reply(connection) ⇒ Object



57
58
59
# File 'lib/esm/websocket/request.rb', line 57

def on_reply(connection)
  @on_reply_callback.call(connection) if defined?(@on_reply_callback)
end

#on_reply=(callback) ⇒ Object



53
54
55
# File 'lib/esm/websocket/request.rb', line 53

def on_reply=(callback)
  @on_reply_callback = callback
end

#timed_out?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/esm/websocket/request.rb', line 49

def timed_out?
  (::Time.zone.now - @created_at) >= @timeout
end

#to_hObject

The DLL requires it to be this format



36
37
38
39
40
41
42
43
# File 'lib/esm/websocket/request.rb', line 36

def to_h
  {
    "command" => @command_name,
    "commandID" => @id,
    "authorInfo" => @user_info,
    "parameters" => @parameters
  }
end

#to_sObject



45
46
47
# File 'lib/esm/websocket/request.rb', line 45

def to_s
  to_h.to_json
end