Class: ESM::Websocket::Request
- Inherits:
-
Object
- Object
- ESM::Websocket::Request
- Defined in:
- lib/esm/websocket/request.rb,
lib/esm/websocket/request/overseer.rb
Defined Under Namespace
Classes: Overseer
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#command_name ⇒ Object
readonly
Returns the value of attribute command_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#remove_on_ignore ⇒ Object
readonly
Returns the value of attribute remove_on_ignore.
-
#response ⇒ Object
Returns the value of attribute response.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#user_info ⇒ Object
readonly
Returns the value of attribute user_info.
Instance Method Summary collapse
-
#initialize(**args) ⇒ Request
constructor
command: nil, user: nil, channel: nil, parameters: nil, timeout: 30, command_name: nil.
- #on_reply(connection) ⇒ Object
- #on_reply=(callback) ⇒ Object
- #timed_out? ⇒ Boolean
-
#to_h ⇒ Object
The DLL requires it to be this format.
- #to_s ⇒ Object
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
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
6 7 8 |
# File 'lib/esm/websocket/request.rb', line 6 def channel @channel end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
6 7 8 |
# File 'lib/esm/websocket/request.rb', line 6 def command @command end |
#command_name ⇒ Object (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 |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/esm/websocket/request.rb', line 6 def id @id end |
#remove_on_ignore ⇒ Object (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 |
#response ⇒ Object
Returns the value of attribute response.
8 9 10 |
# File 'lib/esm/websocket/request.rb', line 8 def response @response end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
6 7 8 |
# File 'lib/esm/websocket/request.rb', line 6 def user @user end |
#user_info ⇒ Object (readonly)
Returns the value of attribute user_info.
7 8 9 |
# File 'lib/esm/websocket/request.rb', line 7 def user_info @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
49 50 51 |
# File 'lib/esm/websocket/request.rb', line 49 def timed_out? (::Time.zone.now - @created_at) >= @timeout end |
#to_h ⇒ Object
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_s ⇒ Object
45 46 47 |
# File 'lib/esm/websocket/request.rb', line 45 def to_s to_h.to_json end |