Class: AmfSocket::RpcRequest
- Inherits:
-
Object
- Object
- AmfSocket::RpcRequest
- Defined in:
- lib/amf_socket/rpc_request.rb
Constant Summary collapse
- TIMEOUT =
Seconds.
30
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#failed_callback ⇒ Object
Returns the value of attribute failed_callback.
-
#message_id ⇒ Object
readonly
Returns the value of attribute message_id.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#sent_at ⇒ Object
readonly
Returns the value of attribute sent_at.
-
#state ⇒ Object
readonly
Valid states: :initialized, :sent, :responded, :failed.
-
#succeeded_callback ⇒ Object
Returns the value of attribute succeeded_callback.
-
#timeout_at ⇒ Object
readonly
Returns the value of attribute timeout_at.
Instance Method Summary collapse
- #failed(&block) ⇒ Object
-
#initialize(command, params = {}) ⇒ RpcRequest
constructor
A new instance of RpcRequest.
- #succeeded(&block) ⇒ Object
- #timed_out? ⇒ Boolean
- #timeout ⇒ Object
- #timeout=(seconds) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(command, params = {}) ⇒ RpcRequest
Returns a new instance of RpcRequest.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/amf_socket/rpc_request.rb', line 14 def initialize(command, params = {}) raise AmfSocket::InvalidArg.new('Command must be a String.') unless command.is_a?(String) raise AmfSocket::InvalidArg.new('Params must be a Hash.') unless params.is_a?(Hash) @command = command @params = params @state = :initialized = SecureRandom.hex @timeout = TIMEOUT end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
4 5 6 |
# File 'lib/amf_socket/rpc_request.rb', line 4 def command @command end |
#failed_callback ⇒ Object
Returns the value of attribute failed_callback.
10 11 12 |
# File 'lib/amf_socket/rpc_request.rb', line 10 def failed_callback @failed_callback end |
#message_id ⇒ Object (readonly)
Returns the value of attribute message_id.
3 4 5 |
# File 'lib/amf_socket/rpc_request.rb', line 3 def end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'lib/amf_socket/rpc_request.rb', line 5 def params @params end |
#sent_at ⇒ Object (readonly)
Returns the value of attribute sent_at.
6 7 8 |
# File 'lib/amf_socket/rpc_request.rb', line 6 def sent_at @sent_at end |
#state ⇒ Object (readonly)
Valid states: :initialized, :sent, :responded, :failed.
2 3 4 |
# File 'lib/amf_socket/rpc_request.rb', line 2 def state @state end |
#succeeded_callback ⇒ Object
Returns the value of attribute succeeded_callback.
9 10 11 |
# File 'lib/amf_socket/rpc_request.rb', line 9 def succeeded_callback @succeeded_callback end |
#timeout_at ⇒ Object (readonly)
Returns the value of attribute timeout_at.
7 8 9 |
# File 'lib/amf_socket/rpc_request.rb', line 7 def timeout_at @timeout_at end |
Instance Method Details
#failed(&block) ⇒ Object
31 32 33 34 35 |
# File 'lib/amf_socket/rpc_request.rb', line 31 def failed(&block) require_state(:initialized) @failed_callback = block end |
#succeeded(&block) ⇒ Object
25 26 27 28 29 |
# File 'lib/amf_socket/rpc_request.rb', line 25 def succeeded(&block) require_state(:initialized) @succeeded_callback = block end |
#timed_out? ⇒ Boolean
59 60 61 |
# File 'lib/amf_socket/rpc_request.rb', line 59 def timed_out? return Time.now.utc >= @timeout_at end |
#timeout ⇒ Object
55 56 57 |
# File 'lib/amf_socket/rpc_request.rb', line 55 def timeout return @timeout end |
#timeout=(seconds) ⇒ Object
49 50 51 52 53 |
# File 'lib/amf_socket/rpc_request.rb', line 49 def timeout=(seconds) require_state(:initialized) @timeout = seconds end |
#to_hash ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/amf_socket/rpc_request.rb', line 37 def to_hash object = {} object[:type] = 'rpcRequest' object[:request] = {} object[:request][:messageId] = object[:request][:command] = command object[:request][:params] = params return object end |