Class: Signalwire::Blade::Message
- Inherits:
-
Object
- Object
- Signalwire::Blade::Message
show all
- Extended by:
- Forwardable
- Defined in:
- lib/signalwire/blade/message.rb
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_request ⇒ Object
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
38
39
40
|
# File 'lib/signalwire/blade/message.rb', line 38
def error?
@payload.has_key?(:error)
end
|
#error_code ⇒ Object
42
43
44
|
# File 'lib/signalwire/blade/message.rb', line 42
def error_code
@payload.dig(:error, :code)
end
|
#error_message ⇒ Object
46
47
48
|
# File 'lib/signalwire/blade/message.rb', line 46
def error_message
@payload.dig(:error, :message)
end
|
#id ⇒ Object
15
16
17
|
# File 'lib/signalwire/blade/message.rb', line 15
def id
@id ||= SecureRandom.uuid
end
|
#payload ⇒ Object
19
20
21
|
# File 'lib/signalwire/blade/message.rb', line 19
def payload
@payload ||= {}
end
|
#to_s ⇒ Object
34
35
36
|
# File 'lib/signalwire/blade/message.rb', line 34
def to_s
inspect
end
|