module OstKycSdkRuby::Util::ServicesHelper

Public Instance Methods

error_with_data(code, msg, data = {}) click to toggle source

Error with data

Arguments:

code: (String)
msg: (String)
data: (Hash)

Returns:

OstKycSdkRuby::Util::Result
# File lib/ost-kyc-sdk-ruby/util/services_helper.rb, line 62
def error_with_data(code, msg, data = {})

  OstKycSdkRuby::Util::Result.error(
      {
          error: code,
          error_message: msg,
          data: data
      }
  )

end
exception_with_data(e, code, msg, data = {}) click to toggle source

Exception with data and without action

Arguments:

e: (Exception)
code: (String)
msg: (String)
data: (Hash optional)

Returns:

OstKycSdkRuby::Util::Result
# File lib/ost-kyc-sdk-ruby/util/services_helper.rb, line 86
def exception_with_data(e, code, msg, data = {})

  OstKycSdkRuby::Util::Result.exception(
      e, {
      error: code,
      error_message: msg,
      data: data
    }
  )

end
perform_and_handle_exceptions(err_code = 'swt', err_message = 'Something Went Wrong') { || ... } click to toggle source

Wrapper Method which could be used to execute business logic Error handling code wraps execution of business logic

Arguments:

err_code: (String)
err_message: (String)
block: (Proc)

Returns:

OstKycSdkRuby::Util::Result
# File lib/ost-kyc-sdk-ruby/util/services_helper.rb, line 18
def perform_and_handle_exceptions(err_code = 'swt', err_message = 'Something Went Wrong', &block)
  begin
    yield if block_given?
  rescue StandardError => se
    OstKycSdkRuby::Util::Result.exception(se, {error: err_code, error_message: err_message, data: @params} )
  end
end
success() click to toggle source

Success

Returns:

OstKycSdkRuby::Util::Result
# File lib/ost-kyc-sdk-ruby/util/services_helper.rb, line 31
def success
  success_with_data({})
end
success_with_data(data) click to toggle source

Success with data

Arguments:

data: (Hash)

Returns:

OstKycSdkRuby::Util::Result
# File lib/ost-kyc-sdk-ruby/util/services_helper.rb, line 43
def success_with_data(data)

  # Allow only Hash data to pass ahead
  data = {} unless Util::CommonValidator.is_a_hash?(data)

  OstKycSdkRuby::Util::Result.success({data: data})

end