Method: Trustly::JSONRPCNotificationRequest#initialize

Defined in:
lib/trustly/data/jsonrpcnotification_request.rb

#initialize(notification_body) ⇒ JSONRPCNotificationRequest

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