Class: Trustly::JSONRPCNotificationRequest
- Inherits:
-
Data
- Object
- Data
- Trustly::JSONRPCNotificationRequest
show all
- Defined in:
- lib/trustly/data/jsonrpcnotification_request.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Data
#get, #get_from, #json, #pop, #set, #set_in, #vacumm
Constructor Details
Returns a new instance of JSONRPCNotificationRequest.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/trustly/data/jsonrpcnotification_request.rb', line 5
def initialize(notification_body)
super()
self.notification_body = notification_body
unless self.notification_body.is_a?(Hash)
begin
self.payload = JSON.parse(self.notification_body)
rescue JSON::ParserError => e
raise Trustly::Exception::DataError, e.message
end
raise Trustly::Exception::JSONRPCVersionError, 'JSON RPC Version #{(self.get_version()} is not supported' if self.get_version() != '1.1'
else
self.payload = self.notification_body.deep_stringify_keys
end
end
|
Instance Attribute Details
#notification_body ⇒ Object
Returns the value of attribute notification_body.
3
4
5
|
# File 'lib/trustly/data/jsonrpcnotification_request.rb', line 3
def notification_body
@notification_body
end
|
#payload ⇒ Object
Returns the value of attribute payload.
3
4
5
|
# File 'lib/trustly/data/jsonrpcnotification_request.rb', line 3
def payload
@payload
end
|
Instance Method Details
#get_data(name = nil) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/trustly/data/jsonrpcnotification_request.rb', line 42
def get_data(name=nil)
if name.nil?
raise KeyError,"Data not present" if self.payload.try(:[],"params").nil? || self.payload["params"].try(:[],"data").nil?
return self.payload["params"]["data"]
else
raise KeyError,"#{name} is not present in data" if name.nil? || self.payload.try(:[],"params").nil? || self.payload["params"].try(:[],"data").nil? || self.payload["params"]["data"].try(:[],name).nil?
return self.payload["params"]["data"][name]
end
end
|
#get_method ⇒ Object
25
26
27
|
# File 'lib/trustly/data/jsonrpcnotification_request.rb', line 25
def get_method()
return self.get('method')
end
|
#get_params(name) ⇒ Object
37
38
39
40
|
# File 'lib/trustly/data/jsonrpcnotification_request.rb', line 37
def get_params(name)
raise KeyError,"#{name} is not present in params" if name.nil? || self.payload.try(:[],"params").nil? || self.payload["params"].try(:[],name).nil?
return self.payload["params"][name]
end
|
#get_signature ⇒ Object
33
34
35
|
# File 'lib/trustly/data/jsonrpcnotification_request.rb', line 33
def get_signature()
return self.get_params('signature')
end
|
#get_uuid ⇒ Object
29
30
31
|
# File 'lib/trustly/data/jsonrpcnotification_request.rb', line 29
def get_uuid()
return self.get_params('uuid')
end
|
#get_version ⇒ Object
21
22
23
|
# File 'lib/trustly/data/jsonrpcnotification_request.rb', line 21
def get_version()
return self.get('version')
end
|