Class: Signalwire::Blade::Message

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/signalwire/blade/message.rb

Direct Known Subclasses

Connect, Execute, Ping, Subscribe, Relay::Event

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Message

Returns a new instance of Message.



10
11
12
13
# File 'lib/signalwire/blade/message.rb', line 10

def initialize(params = {})
  @payload = params
  @id = params[:id]
end

Class Method Details

.from_json(json_hash) ⇒ Object



30
31
32
# File 'lib/signalwire/blade/message.rb', line 30

def self.from_json(json_hash)
  new JSON.parse(json_hash, symbolize_names: true)
end

Instance Method Details

#build_requestObject



23
24
25
26
27
28
# File 'lib/signalwire/blade/message.rb', line 23

def build_request
  payload.merge(
    jsonrpc: '2.0',
    id: id
  )
end

#error?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/signalwire/blade/message.rb', line 38

def error?
  @payload.has_key?(:error)
end

#error_codeObject



42
43
44
# File 'lib/signalwire/blade/message.rb', line 42

def error_code
  @payload.dig(:error, :code)
end

#error_messageObject



46
47
48
# File 'lib/signalwire/blade/message.rb', line 46

def error_message
  @payload.dig(:error, :message)
end

#idObject



15
16
17
# File 'lib/signalwire/blade/message.rb', line 15

def id
  @id ||= SecureRandom.uuid
end

#payloadObject



19
20
21
# File 'lib/signalwire/blade/message.rb', line 19

def payload
  @payload ||= {}
end

#to_sObject



34
35
36
# File 'lib/signalwire/blade/message.rb', line 34

def to_s
  inspect
end